The great thing about the Nexus devices like the Nexus 4 and Nexus 10 is that they're easily upgradable, they're free of any bloatware provided by vendors and carriers, and they're made to be tinkered with. Google knows that nerds would want to get customize devices like that, so they don't try to get in the way of such actions -- the bootloader on Nexus devices is easily unlockable, which opens up a world of possibilities with the effort of a single command. Depending on your own needs from your Nexus device, there are a few ways of rooting, unrooting, and unlocking the device.

Carrier Unlocking

Before we begin, let's get one thing out of the way: carrier unlocking. By default, any Nexus device with cellular capabilities comes unlocked (at least if you buy it from Google -- I can't 100% guarantee the same if you bought it from a carrier). Without doing anything to the device at all, you should be able to have it work with any carrier -- GSM device with GSM-carrier, CDMA with CDMA-carrier, but not mixed and matched. Simply put, there are no ifs, ands, or buts when it comes to this. And I only bring this up because there's a difference between bootloader unlocking and carrier unlocking. While carrier unlocking allows you to access to any compatible carrier rather than just the one you bought the device from, bootloader unlocking is the first step to being able to modify the software that is on the device that provides you all of its functionality. The two are completely independent.

Warning About Unlocking Bootloader and Rooting

While unlocking the bootloader is necessary to make any software changes on your device, following through with unlocking it will completely wipe your device. One way or another, you'll have to set up your device again. In order to make it easier, it's best to back up your device with an app like Titanium Backup first before proceeding. Also, while rooting allows you to gain more access to system features, it can potentially prevent you from receiving system updates from Google (this is a guaranteed truth if you're flashing a different ROM), and Google Wallet will complain about you using an insecure device (although it won't stop you either). Finally, some people also claim that battery performance is affected -- usually negatively, unless you take battery-saving measures afterwards.

Toolkit Route

For rooting, unrooting, and unlocking the bootloader of your Nexus device, there are two main routes -- the toolkit route and the manual route. The toolkit gives you an application to work with that essentially does all of the dirty work; the manual route gives you all the dirty work to do yourself, but don't think that it's necessarily hard.

unlock_root_nexus_wugtoolkit

Wug's Toolkit (no longer available) is the preferred tool to do everything you need on your Nexus device. As a Windows-only program, Mac OS X and Linux users will have to defer to the manual route unless they can find their own toolkit alternatives, but it's recommended to do the manual route on those operating systems. Wug's Toolkit practically takes care of everything for you. All you have to do is choose which device you want to work with, and, after a quick message about how to enable USB debugging on your device, you're presented with a window containing numerous buttons. You'll probably want to do the automatic initial setup so that your computer uses the right drivers to communicate with your Nexus device. Once that's complete, you're free to unlock, root, and unroot the device with a simple click of a button. Under advanced utilities, you can also perform a number of other tasks including sideloading zip files for flashing, restoring stock recovery and kernel, force reboots, and manually install APKs. Really, it's all you could ever want to do with such a utility.

Manual Route

Taking the manual route is certainly more challenging than pushing a single button, but if you're already doing something as serious as rooting/unlocking to a Nexus device, then you may want to actually understand a little more about what's really going on when you click that button. Plus, you can use whatever computer you have access to when you have the skills to do it manually.

Before beginning, you'll want to install the Android SDK tools onto your computer so you can use tools such as fastboot and adb. Otherwise, you won't be able to communicate with your Nexus device.

nexus4_lte_fastboot

Unlocking the Nexus device is really simply. Boot it up into fastboot mode -- on the Nexus 4, this is done by holding the Power + Volume Down buttons at the same time. Once you see a screen like above, open up a command line terminal and (assuming you're using Linux; adjust slightly as appropriate for other operating systems) type

        sudo fastboot devices
    

. If anything appears from this command, the computer recognizes the Nexus device. Then, type

        sudo fastboot oem
    

unlock, and accept the warning shown on the Nexus device by navigating with the Volume Buttons and accepting with the Power button. Congratulations, your Nexus device is now unlocked!

Rooting manually is a little tricky, because rooting the stock version of Android (the one that Google provided that originally came with the device) used to be pretty tricky. At least with a Nexus device, you just need to download a flashable CF-Auto-Root file and flash that onto the device, giving you root access. However, you're still most likely going to need to use a custom recovery, and while you're at it you may as well install a custom ROM onto your device (which won't require an additional flash of CF-Auto-Root).

Unrooting your device is nearly impossible to do without flashing stock back onto your device. You'll need to download the latest factory image from Google's Android Developer Images site, and move the two included .img files from the .zip into a separate folder, and then open the secondary .zip and move those .img files into the same separate folder as well.

nexus4_lte_restore_stock

Then type the following commands into your computer while it is connected to the Nexus device:

  1.         sudo fastboot devices
        
    (to make sure that the computer sees your Nexus 4)
  2.         sudo fastboot flash bootloader bootloader_xxxx.img
        
    (Replace bootloader_xxxx.img with the actual file name)
  3.         sudo fastboot reboot-bootloader
        
  4.         sudo fastboot flash radio radio_xxxx.img
        
    (Replace radio_xxxx.img with the actual file name. For Android 4.3, the version should end in a .84)
  5.         sudo fastboot reboot-bootloader
        
  6.         sudo fastboot flash system system.img
        
  7.         sudo fastboot flash userdata userdata.img
        
  8.         sudo fastboot flash boot boot.img
        
  9.         sudo fastboot flash recovery recovery.img
        
  10.         sudo fastboot format cache
        
    (to remove any old traces of the old system)
  11. OPTIONAL:
            sudo fastboot oem lock
        
    (this re-locks the bootloader to prevent future tinkering with the device, i.e. forces you to "unlock" the bootloader again and wipe the device before tinkering)
  12.         sudo fasboot reboot
        

Conclusion

You should now be back to a completely stock configuration for your Nexus device! Playing around with a Nexus device is a lot of fun, and it provides a great learning experience about how to tinker with Android. Above all, it can provide a lot of extra functionality (such as LTE functionality on the Nexus 4) that isn't built into Android itself -- you just have to go find it yourself.

Have you tinkered with your Nexus device? Any tips you can give to beginners? Let us know in the comments!

Image Credit: drukelly