It is said that the CF-Auto-Root method is the safest method for rooting it. For more information you may head to this thread.
Disclaimer:AndroidJunkie will not be responsible for you damaging your device by following this guide. Please make sure to follow all the steps carefully and make sure you meet the requirements.
Requirements:1. USB Debugging
Be sure to enable USB debugging on your GS4 first. You can do that by going to Settings -> Applications - From there head to Development and tick the box for debugging.
2. USB Driver
Install the USB driver on your PC so that it will be recognizable when we get to the Odin part.
Your phone should be factory unlocked and not locked by any carrier.
Make sure your phone's battery is well charged.
Make a backup of your apps and data just incase something goes wrong.
1. Download the zip file to your computer - CF-Auto-Root-ja3g-ja3gxx-gti9500.zip
2. Download Odin - Odin 3.07
3. Extract the Odin zip file aswell as the CF-Auto-Root zip file.
4. Turn off your Galaxy S4 and boot into Download mode. To do that, press and hold the Home, Volume Down and Power button until the screen turns on and you see a construction-like image.
5. Run the Odin program on your computer and connect your GS4 while it is in Download mode. Within a few seconds Odin should recognize the device. It should appear in the COM Port box as yellow. (If you happen to have problems with establishing the connection, try another USB port).
6. In Odin, click the PDA button and locate the CF-Auto-Root .tar.md5 file that you got when you extracted the zip file and choose it.
7. Next, make sure that Auto Reboot and F. Reset Time options are enabled, make sure that Re-Partition option is not enabled.
8. Once you have selected the file and have configured the right settings as told above, you may press the Start button.
9. The phone should automatically reboot into Recovery mode, where it will install the root package.
10. Head to the app drawer and see if you have SuperSU.