Rooted my Nexus 5 android following this instruction.
1. Backup the phone (Rooting will erase all setting and personal files on the phone & SD card)
2. Enable USB debugging:
Go to phone’s Setting -> About Phone, then keep tapping on “Build Number” until it shows “You are now a developer”
3. Unlock the bootloader & Flash Nexus 5 with the factory image
Factory images can be found here.
Extract the downloaded file hammerhead-mob30y-factory-7f05cd7f.tgz
Open a terminal on my MAC and ran the following commands,
fastboot oem unlock
fastboot erase boot
fastboot erase recovery
fastboot erase system
fastboot erase userdata
fastboot erase cache
fastboot flash bootloader bootloader-hammerhead-hhz20h.img
fastboot reboot-bootloader
fastboot flash radio radio-hammerhead-m8974a-2.0.50.2.29.img
fastboot reboot-bootloader
fastboot flash boot boot.img
fastboot flash recovery recovery.img
fastboot flash system system.img
fastboot flash userdata userdata.img
fastboot flash cache cache.img
fastboot reboot-bootloader
4. Get Android-studio from here
twrp from here. This is a better recovery tool.
SuperSu from here
5. Install custom recovery
Go to directory which contains the Andriod-studio files (on Mac)
#which fastboot
/Users/myuser/android-sdk/android-sdk-macosx/platform-tools/fastboot
#cd /Users/myuser/android-sdk/android-sdk-macosx/platform-tools/fastboot
#fastboot flash recovery twrp-3.0.2-0-hammerhead.img
#fastboot reboot-bootloader
Power-off the phone and enter the Fastboot mode again, switch to Recovery mode and proceed, then the custom recovery will be shown.
6. Root the phone
On Mac terminal:
#adb push UPDATE-SuperSU-v2.76-20160630161323.zip /sdcard/
Boot the phone into Fastboot mode then switch to recovery mode as before.
Click on install, then choose SuperSu zip file and click “Install image”.
Reboot.
7. The phone couldn’t get connection from carrier(Sprint) after the changes above, ran the following code on the dial pad, then the problem got fixed.
*#*#72786#*#*