This guide covers installing the latest version of lineage OS on a fresh Moto G5s. In my experience, the documentation for going through all the steps required to install lineageOS on a given device are scattered, outdated, and typically require a lot of hard-to-meet conditions (like unlocked bootloader and rooted phone). This guide covers all the steps and issues I came accross when installing lineageOS on my new G5s, including rooting and unlocking the bootloader, and installing a custom recovery image.

Note that as of writing this there currently isn’t an official release of LineageOS for this device. However, the unofficial builds are often updated and, in my experience, very stable which makes me think that it’s not far from being listed on the official lineage OS site. The only issues I’ve had is that camera is a bit janky when opened within whatsapp… but this is an issue I’ve also had in the official lineage release one the Samsung Galaxy S6, so I assume this is more of a whatsapp issue. After going through this guide I’d recomend installing the lineage updater app from the play store. Check the updater app every few days; as soon as an offical stable release comes, it’ll start being listed in this app where you can automatically download and flash it.


First off, lets get everything we need in place. Below are lists of requirements we need to get this working and should only take a few minutes to get ready.


  • ADB command line tools. Installing this developer toolset will let you upload files to your phone and flash ROMs you download. I’m using linux in this guide, so note that on windows you likely have to install a few additional drivers (listed on the download link). Beyond that, all steps should be the same.
  • TWRP image. Codename of our device: montata. Version of TWRP to get: 3.2.3-0. TWRP will replace your phones default recovery program. This will allow you to install new software (and operating systems) without any external tools. With TWRP, you can simply download an image, enter recovery mode, then flash a different OS on your device. Just like Lineage, there is currently no official release for the G5s yet. I’ve tested the image linked here and it performed just fine for the steps in this guide.

  • Latest unofficial release of LineageOS. Do make sure to check the official lineage site to see if an official release has been published since writing this. If the links don’t work, just try googling “LineageOS montana”, where montana is the device code for the G5s.
    Go for trustworthy links from the xda-developers as this is where all the builds are posted when they are released and seems quite reliable in my experience.

  • gapps. Lineage OS doesnt come with any google apps like the playstore, which is quite essential. Do remedy this, we’ll have to download and install gapps ourselves from the link. To get the correct version, we need to know what version of android we’re planning to use in addition to what kind of chipset the phone has. We’re installing lineageOS version 14.1, which is based on android version 7.1.2 (Nougat). Using this info, [download] the version of gapps corresponding to ARM and Android: 7.1. I’m downloading the stock version of Gapps, but you can choose which ever suits your needs.

Note: I tried this later on using the micro variant, but then I had no keyboard as gboard was not installed and for some reason the Lineage default keyboard would not activate. To be on the safe side, I reccomend taking the stock variant of gapps.

  • SuperUser. This is for rooting lineage OS after you’ve installed it. You should select the version for 14.1 and arm (not to be confused with arm64!). This may not be necessary for you, but since we’ll be crawling around in TWRP anyways, now would be a conveniant time to root your phone.


On your phone, you’ll have to do a few steps to allow us to flash the ROM later.

  1. Enter developer mode. In your settings, navagate to where your Build Number is displayed. This is usually in the (about phone) section of the settings. Tap on Build Number seven times, then you will see a message indicating developer mode has been activated (unless you have done this before, then don’t worry about this step).

  2. Now in your settings, there will be an additional Developer Options sub menu. Go here, and select Unlock OEM, which allows us to replace the recovery tool, and Enable USB debugging. USB debugging will allow us to control the phone via the ADB toolset you installed.

Unlock bootloader

Now we’ll start. First, we need to unlock the bootloader which will give us permission to flash a new recovery tool. To do this, we need to be in fastboot mode. Before we proceed, we’ll verify that your USB connections are working then go into fastboot.

Connect to your phone via ADB

  1. With your phone on, check that USB debugging is activated in phone. When you plug in the USB to your computer you should see notifications like in the following images. USB Debug notification

  2. Now lets check if ADB can communicate with the phone. Open a terminal (or the cmd app on windows) and change your directory to where your adb binary in installed. On Ubuntu, I had to use this command:
    cd /home/james/Android/Sdk/platform-tools/

    These commands will look slightly different on windows.

  3. Next, run ADB and see if it can see your phone with the following command:
    ./adb devices

    Problem signs you want watch out for here is if no devices are listed, or if there are udev error messages (only on linux). Otherwise… you should one or more devices listed here and you can proceed as normal.

  4. Finally, now that we have verified our USB connections are working, reboot into fastboot via ADB using the following command:
    ./adb reboot-bootloader

    Your phone will now restart into fastboot mode. If you run into the error in the image below, check the screen of your phone as there is likely a prompt asking you to verify the USB permissions. USB Debug notification USB Debug notification When you are in fastboot mode, you’ll see something like the image below. Notice the line oem_locked. In the next steps, we’ll change this to unlocked. USB Debug notification

Get OEM unlock key from device

To unlock the bootloader, we’ll have to get a unique key form our phone, then use this to register on the Motorola website to recieve the mathcing unlock key we’ll use to unlock the bootloader.

  1. First, check that you have permissions for communicating with the device.
    Just because USB debugging works when your phone is on, this does not mean fastboot will also work the same. Run ./fastboot devices and check to see if the device is listed. When I tried this, I got the following error: USB Debug notification If you have the error, the simple solution is to just run both adb and fastboot commands as sudo (this is only on linux). From now on, you’ll see me prepending sudo to these commands in the rest of the guide. If you don’t suffer from this issue, I would recomend not using sudo unless you have to.

  2. Now enter the command:
    sudo ./fastboot oem get_unlock_data

    You should get a key like the image below. USB Debug notification

  3. Take your unlock data and follow the instructions here to get the key you need to unlock your device. Note that you’ll have to register a developer account with motorola to get to this page as they will email you the key you need. It only took a few seconds for me to get the resulting key via email.

Unlock bootloader with new OEM key

Finally, unlock your bootloader with the following command (you’re phone should still be in fastboot mode) and of course replace [OEM_UNLOCK_KEY] with your actual key value recieved via email:

sudo ./fastboot oem unlock [OEM_UNLOCK_KEY]

You’ll note that the output tells you to rerun the command.
Go ahead and enter the command a second time to get the following result. USB Debug notification USB Debug notification You will also notice the message flashing_unlocked on your fastboot screen, like below. USB Debug notification

Flash TWRP using Fastboot

Okay, our bootloader is unlocked… that means we can now install our custom recovery ROM: TWRP.

  1. Lets flash the TWRP image to our phone.
    Enter the following command with the appropriate location of where you download TWRP to (out terminal is still in the same directory where adb was located in the previous steps):
    sudo ./fastboot flash recovery ~/Downloads/twrp-montana-

    You’ll see an output like below if it flashed sucesfully. USB Debug notification

  2. Now, on your phone while still in fastboot mode, select RECOVRY MODE with the volume keys and press power to select it. When I entered TWRP the first time, it asked me for a finger pattern to unlock. I tried the phone pattern, but this didnt work… but then I pressed cancel and I was able to continue as normal within TWRP. Make sure to stay in TWRP for the next section when we install lineageOS. If you leave and reboot, your phone will likely replace TWRP with the origional bootloader (I know by trial and error). I’m not sure why this happens, but I assume its related to actions in the stock ROMs boot process. If you mess this up, just re-flash TWRP and continue from this point.

Install lineage OS

To recapp:

  • We installed ADB on a laptop so we can interface with our phone.
  • We used ADB to unlock the bootloader of our device.
  • We then flashed the TWRP custom recovery.

Now we’re finally at the important step of installing lineageOS. Flashing images is very quick as you’ve noticed, so we’ll also flash gapps and SuperSU while we’re doing this.

Install lineageOS, gapps, and root phone

  1. First, lets wipe our system in recovery mode. In TWRP, go to wipe > Advanced Wipe and select:
  • Dalvik
  • system
  • data

Then swipe to clear it. This lets us do a clean flash, (as opposed to a dirty flash)

I ran into some quite annoying bugs after installing LineageOS when I tried skipping this step previously.

  1. While we’re still in recovery mode (i.e. TWRP), lets use adb to load the files to the phone. Unlike earlier, I no longer have to use sudo here. The recovery enviroment (TWRP) and the fastboot environment have different permissions, so its not surprising that one works slightly different than the other, at least on linux machines. To load the files, use the commands:
    $ ./adb push ~/Downloads/open_gapps-arm64-7.1-stock-20180901.zip /
    $ ./adb push ~/Downloads/lineage-14.1-20180820-UNOFFICIAL-montana.zip /
    $ ./adb push ~/Downloads/addonsu-14.1-arm-signed.zip / 

    The command works like adb push [location_of_file_to_push] [destination_on_device]. The / at the end of our commands just tells adb to drop those files at the root of the phones file system, so we dont have to waste time searching around for it in TWRP.

If you are getting errors like insufficient permissions from this device when pushing files through adb, try running sudo ./adb kill-server to reset adb then retry the above commands with sudo prepended to them. This allowed me to get around the permissions errors that many seem to have.

  1. In TWRP, select install and select the lineage OS file we just dropped on your phone (the image shows installing gapps, but it will look the same for lineageOS).

    USB Debug notification USB Debug notification
  2. Now do the same with the Gapps package SuperSU. During the last install (SuperSU), select Wipe cache/dalvik from the install options. I’m not sure this is necessary, but this seems to solve issues sometimes.

  3. Now select reboot from TWRP. Before rebooting, it may prompt you to install the TWRP app, swipe to confirm this. Not sure why I need this… but I have a feeling having the TWRP app will be useful down the road.

Now when your phone restarts, you should log into lineageOS for the first time. Proceed as you would on any other new phone to set up you accounts. Since we installed gapps, you should have the google play store included in your lineage OS install.

The steps listed here are exactly what I had to do to get lineageOS installed. Note that different versions of TWRP, SuperSU, and possibly updates of your stock android system may cause some additional issues, so please take into consideration the date this guide was written when following along.

Updated on: 2018-10-17