[Nexus 4 Android Development] HQRaja:
I originally posted this method at AddictiveTips. The method I posted there is targeted at everyone including the absolute beginners and I have also included instructions there for setting up the required tools, and for reverting back to the original recovery and boot image in case anything goes wrong. All external credits should be given to that guide (it does link back to this thread). Here is the link: How To Root Nexus 4 and Install ClockworkMod Recovery on it.

To my knowledge, this is the first confirmed working rooting method for Nexus 4 posted here at XDA. Though my knowledge is limited, so please correct me if I am wrong.

UPDATE: There is an official ClockworkMod recovery for Nexus 4 now available directly by Koush, so this should all be easy as pie now and you can now safely install CWM too. I am updating the CWM method with the updated instructions.

This method requires an unlocked bootloader. You can find instructions for unlocking it at XDA, or at the AddictiveTips guide linked above (the link to the bootloader unlock guide is in the requirements section there).

UPDATE 2: If your device does NOT get wiped after unlocking the bootloader, fret not. While this isn't expected behavior, several users have experienced the same on the Nexus 4. This could be due to some error at Google's end, but unlocking still works perfectly fine.

That said, let's get on with rooting and flashing CWM.

ClockworkMod Recovery Method:

Download the latest official ClockworkMod recovery from CWM website and rename it to recovery.img

Enable Android Debugging from Settings > Developer Options. (If you can't find developer options, go to 'About' and tap 'Build number' seven times.)

Connect the device to your computer via USB, and install the required drivers.

Download the recovery flashable SuperSU package with Busybox and transfer it to your phone's internal SD card.

Reboot into fastboot/bootloader:

adb reboot bootloader

You can also power off the phone and then use power + volume-down key combination to get into bootloader.

Unlock the bootloader if you haven't done so already. WARNING: This command will wipe all data on your device.

fastboot oem unlock

Enter this command in a command prompt to flash the ClockworkMod recovery (making sure you are in the directory where you downloaded the recovery file):

fastboot flash recovery recovery.img

OR

If you simply want to root without flashing a custom recovery and want to stick to your stock recovery, simply boot this recovery once using this command:

fastboot boot recovery.img

If you flashed the recovery in the previous step, you can now boot into recovery by pressing volume-up or volume-down twice to select the recovery option, and then the power button to enter it. If you simply booted into the recovery file without flashing it in the previous step, you should already be in recovery now.

Once in recovery, take a backup to be on the safe side.

Flash the downloaded SuperSU and busybox package zip file from recovery.

Clear cache and dalvik cache just in case (not required but won't hurt).

Reboot the device.

ADB and Insecure Boot Image Method:

Grab the insecure boot image from this thread.

Also download these root files. This package includes the latest SuperSU 0.98, latest su binary that comes with it, and working busybox (not sure if latest).

Extract the contents of the downloaded zip file to your computer.

Enable Android Debugging from Settings > Developer Options. (If you can't find developer options, go to 'About' and tap 'Build number' seven times.)

Connect the device to your computer via USB, and install the required drivers.

Reboot into fastboot/bootloader:

adb reboot bootloader

You can also power off the phone and then use power + volume-down key combination to get into bootloader.

Unlock the bootloader if you haven't done so already. WARNING: This command will wipe all data on your device.

fastboot oem unlock

Get back into bootloader mode and boot into the downloaded insecure boot image:

fastboot boot boot.img

Don't worry, this will not replace your existing boot image and will only boot from the insecure one once.

If it does NOT work for you and you get stuck in a boot loop, simply reboot your phone into bootloader and use the above command again. Some users had issues with booting from it the first time, but a second attempt worked.

Once booted into Android successfully using the insecure boot image, simply enter these commands one by one in command prompt (making sure you are in the directory where you downloaded the files):

adb shell mount -o remount,rw /system
adb push su /system/bin/
adb push Superuser.apk /system/app/
adb push busybox /system/xbin/
adb shell
chmod 06755 /system/bin/su
chmod 0644 /system/app/Superuser.apk
chmod 04755 /system/xbin/busybox
cd /system/xbin
busybox --install /system/xbin/
exit
exit

Reboot your device.

You will now have root access. Tested and confirmed working by Stryder5 and many others.

Credits:

Stryder5 for testing, confirming, tipping me about working CWM, providing the required drivers, and helping others on the thread. :highfive:

Harry GT-S5830 for the insecure boot image.

fkrone for his recovery revert disabler script and his unofficial working CWM before an official one became available.

Kstarz for posting this same recovery method with his own working CWM in this thread before an official one was out.

evaradar for informing about the release of official ClockworkMod recovery.

Koush for developing ClockworkMod recovery.

Chainfire for developing SuperSU.

Everyone else on this thread for testing, providing feedback and hitting the 'THANKS' button. =)

I have tried my best to give everyone the due credit but if I have missed out on anyone, please do remind me.