Thanks to the work of renowned developer Chainfire, the Nexus 5 has already been rooted using the latest version of CF-Root. The step by step instruction of how to do this follows:
Ensure you backup your device before you continue
Your first step is to unlock the device. You can do this by connecting your device to a computer with the Android SDK, enter fastboot mode, and type "fastbook oem unlock" into a terminal window.
- Download CF Autoroot and extract it to your computer
- Boot your device in bootloader/fastboot mode.
- Turn off device and Press Volume Up + Volume Down + Power buttons together
- To install on Windows
- Run root-windows.bat
- To install on Mac
- chmod +x root-mac.sh
- Run root-mac.sh
- To install on Linux
- chmod +x root-linux.sh
- Run root-linux.sh
Follow the onscreen instructions on your computer and device to complete the rooting
If you face any issues rooting your Nexus 5, head over the source link to discuss your issue.
source - XDA Developers