I want to install CyanogenMod on my Galaxy S4. Do I need to install a custom recovery first in order to do it?
In order to install most any ROM, you need to install custom recovery first. I assume by asking this question, you may also be wondering why. Flashing a new ROM or recovery happens before Android is running. Basically, when you're rooting your device you're getting root permission, which is full access to your Android OS. Truly administrative privilages, and only you can limit/extend your own rules. This is much like Linux, Ubuntu and any other Linux-based operating system, though when we talk about Android it's a different story. [Sort of, but in a similar respect. Android is Linux.]
Why you need custom recovery: The main advantage of creating a custom recovery is to provide a way to reset an Android device when it may be impossible to boot into it. In addition, it is an environment separate from Android that allows diagnostic updates, and the ability to perform factory resets.
You can use Odin to root your device, it's easiest in my opinion.