[Nexus 4 Q&A, Help & Troubleshooting] 69b84b9559feb74133c6bbc97:
I just rooted my Nexus 4 using Ubuntu 12.04.

The instructions I found weren't quite what I'd liked them to be, none of them were for Linux and I had to do quite a bit of trial and error.

I know that a few years ago I wouldn't have been able to do it with those instructions.

So I thought I'd write down what I did so others can do it easier and faster than me.

To be able to easily understand this guide you need to know the basics about using a terminal, but other than that I'm trying to not to require the reader to know anything.

If you use another Linux distro everything should work pretty much exactly the same, but for the additional packages I had to install, but their name should be easy to guess because they are usually similar across distributions and how you install them should be explained in the documentation of your distro.

Connect your Nexus 4 to your computer using an USB cable.

First I downloaded the ADT Bundle from there developer.android.com/sdk/index.html and unpacked it into a new folder. Doesn't matter where, I'll use ~/androidSDK in those instructions. The tools which you need to root your phone are ~/androidSDK/adt-bundle-linux-x86-20130514/sdk/platform-tools/adb and ~/androidSDK/adt-bundle-linux-x86-20130514/sdk/platform-tools/fastboot

"x86" means I downloaded the 32bit version and "20130514" is the date of when the version I'm using was published, that will most likely be different for other people.

Now most likely adb and fastboot won't run yet (if you run them it will tell you something like "~/androidSDK/adt-bundle-linux-x86-20130514/sdk/platform-tools/adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory"). To fix this you need to install the packages "lib32ncurses5" and "lib32stdc++6". You can run the following command to do that:

sudo apt-get install lib32ncurses5 lib32stdc++6

(got that from there: stackoverflow.com/questions/10005907/eclipse-android-plugin-libncurses-so-5)

For adb to work you also need to activate USB debugging: Go to Settings->About phone and tap "Build Number" until it says you are developer. Then a new entry will appear in "Settings", called "{ } Developer options". Check the box next to "USB debugging", confirm with ok.

Now you need to backup everything on your Nexus 4 because it will be wiped while rooting. You can do this by running:

cd ~/androidSDK/adt-bundle-linux-x86-20130514/sdk/platform-tools

(in the future I'll assume you stayed inside that directory)

./adb backup -apk -shared -all -system

Before this command can finish you need to confirm on your Nexus 4 that it's okay to do that backup (just do what it says on it's screen).

This will put a file named backup.ab in the current directory. You can change the name and location of that file using the -f paramter, if you want.

Run

./adb reboot bootloader

to boot into the bootloader. After a moment the Nexus 4 should display something like this:

(image stolen from reviews.cnet.co.uk/mobile-phones/how-to-root-your-google-nexus-4-50010361/)

Now the actual unlocking happens: Enter

sudo ./fastboot oem unlock

Maybe try without sudo first (just leave it out), but it only worked with sudo for me; without sudo it displayed "waiting for device" forever and I needed to abort with Ctrl+C.

Download SuperSU from there http://download.chainfire.eu/supersu (at the moment "CWM-SuperSU-v0.98.zip").

Put that file on your Nexus 4 any way you want, one possible way is to do:

./adb push ~/CWM-SuperSU-v0.98.zip /sdcard/

That assumes you downloaded SuperSU to your home directory. For that to work you need to activate USB debugging again (it was deactivated during unlocking).

Download the Nexus 4 "Touch Recovery" from www.clockworkmod.com/rommanager.

I guess you shouldn't need the touch version, but it's more comfortable for sure. When I downloaded it the file was named "recovery-clockwork-touch-6.0.4.7-mako.img" and that's what I'm going to use when I give you commands to run.

This "Touch Recovery" needs to be installed to the Nexus 4. To do this first boot into the bootloader again:

./adb reboot bootloader

And then flash the file using the fastboot utility:

sudo ./fastboot flash recovery recovery-clockwork-touch-6.0.3.1-mako.img

(if it needed sudo the last time it will need it again, if not, not)

Now go to the recovery mode (use volume buttons to navigate and power to confirm).

Tap "install zip from sdcard"

Tap "choose zip from sdcard"

Tap "0/"

Find the SuperSU .zip file you put on the phone earlier (tip: scrolling works as usual by swiping or if you want with the volume buttons) and tap on it.

Confirm that you really want to install it.

Boot into Android again and restore the backup you made earlier (if you made one).

./adb restore backup.ab

You need to confirm that command on the Nexus 4.

As you are now finished you can of course disconnect your Nexus 4 from your computer.

You should be finished now. Unless I remembered something wrongly when writing this because I mostly wrote this from memory, after rooting my Nexus 4. If something doesn't work as I claim then please tell me and I'll fix it (possibly eventually).

I myself followed those instructions http://xdaforums.com/showthread.php?t=2018179 as far as possible and then googled what didn't work or just tried around for a bit.

Edit: As of now (18.8.14), those instructions should still work.