Install a CLI linux distro in your android phone with Termux!

Termux allows us to install and run several CLI programs like vim, github-cli, git in our phones.

Cranberry
7 min readNov 5, 2023

In this guide I’ll teach you how to install a distro on your android phone (android 6, 5 have a different way of installing).

First of all you’ll need to enable “unknown sources” at your phone settings, security tab (in newer phones you actually just download the APK file, click on it and give the prompted permission). That will allow you to install .apk files that are basically app installers. The reason we need to install an apk file is because the play store version of termux is so outdated it simply does not work so we’ll need to download it from github.

For android 7 up:

https://github.com/termux/termux-app scroll down to the bottom of the page and click releases to go to the releases page where you can download the .apk file. There you’ll find several download options like termux…armv7, armv8 etc, if you know the architecture of your phone download the proper one, if you don’t just downloaded the one with universal on its name (probably the biggest in size). Once downloaded you’ll click on the downloaded .apk file(you may be asked to give permission to install from your browser), if the installation fails, try with another download option.

For Android 5, 6:

Go to this page: https://github.com/termux/termux-app/actions/workflows/debug_build.yml?query=branch%3Amaster+event%3Apush then click on the first option with a green checkmark, scroll down and you’ll see some download options, in order to be able to download, you’ll need to be signed in a GitHub account or else the options will be whited out, download the right apk for your cpu architecture and Android version 5/6 or download the one that says universal.

Termux app:

When you first open the app you’ll probably see something like “installing bootstrap packages”, wait until it’s done, then you’ll be greeted with this screen:

That’s a Linux terminal, it doesn’t have all commands available in GNU Linux but it still have a lot of functionalities specially if you’re using android 7+. Termux uses “PKG" packaged manager, the first command we want to type is

pkg update

After updating the repos you’ll see something like this:

Type “y” to begin the installation of necessary packages, whenever prompted y/n type y, it’s necessary for termux to function properly. The next command is:

termux-setup-storage

That will grant you access to the phone’s internal storage, a new folder called storage will appear, you can type ls to check it, inside it there are some shortcuts to some folders like download, the folder named “shared” is the actual internal storage, be careful to not run naughty commands like rm on something you don’t want to delete.

To install new packages to termux you use:

pkg install package_name

You can type:

pkg help

To get a list of pkg usages.

Note: the available packages and version vary depending on the cpu architecture, notice how it says “arm” next to the version.

neofetch is a program that displays the system's info on the terminal to install it type pkg install neofetch

Note that neofetch detects termux as Android, termux alone may be enough for you, you can install git, cli programs like github-cli (android 7+), nodeJS, python, clang, editors like vim, emacs and other utilities, try it out.

How to install Linux distros on termux using proot-distro

You can install an actual distro and make it run under termux. The android OS actually uses the linux kernel, although “crippled” since you can’t actually do most of the things you can on a Linux desktop. Proot uses some partitions and some of the functionalities of the linux kernel present in android.

Method 1: proot-distro (android 7+)

here’s how to install it.

pkg install proot-distro

It will install the package “proot-distro” and some of its dependencies like the proot pkg.

After the installation if you type proot-distro you’ll see all the available arguments to use with proot-distro.

Use proot-distro list to see all available OSes.

To install type:

proot-distro install distro_alias

Let’s install Ubuntu. Type “proot-distro install ubuntu” when it finishes log in typing:

proot-distro login ubuntu

Once logged in Ubuntu you’ll notice the prompt changed from “~ $” to “root@localhost:~#”, that means we’re now logged in Ubuntu, type

apt update

This will set some things up like termux pkg update. Usually proot systems come in a really basic installation so you may have compatibility issues or need to set a lot of things by yourself. Linux alpine is really small in size so if storage is a concern alpine may be more suitable for you although alpine package manager “apk" is not as rich as Ubuntu’s “apt” it still may give you some functionalities that you don’t have in regular termux like access to the file system like use, bin, home (all inside termux inside a proot environment :0 ).

You can even set up an actual user authentication! It’s possible to set up a graphical environment but it’s slow and buggy so I’m not going to teach how to do it in this article.

Method 2: Using apps like anlinux, android (android 6+)

Using these apps makes it simpler to set up a graphical environment.

For Android 6 I recommend using a Linux and installing debian or Linux alpine, sadly proot-distro is not available in android below 7 and a lot of the OS options don’t work properly so I’m going to focus on linux installation on Android 6 using anlinux (https://play.google.com/store/apps/details?id=exa.lnx.a).

when you first open the app you’ll see some information, just go to the bottom and mark “i understand", now select dashboard on the left top corner, you’ll go to this page:

click the choose button and select the desired OS, in my case I’ll choose alpine (debian worked the best on my android 6 device). Then some commands will appear:

click the copy command and launch termux and then paste the commands you copied from anlinux, it will begin the installation. Type ls you’ll see some files ending with .sh, run the script that starts with “start-…” in my case start-alpine.sh, to run a script just type “./script_name.sh”.

for debian and ubuntu type “apt update" for alpine type “apk update". after that we also need to set up alpine so it uses the latest version of the packages to do that first install a code editor like vim.

apk add vim

after install vim type

vim /etc/apk/repositories

to change the repo to use the “edge" repo, your file will look like this:

just change the 2 “v3.16" to “edge" and your good. To enter insert mode in vim press i then move the cursor with the arrow keys and make the changes, then press ESC to exit insert mode, then type :wq and press enter to save and exit. it now should look like this:

now type:

apk update && apk upgrade

to upgrade the system to the newest version. I recommend installing zsh, alpine uses busybox by default just install it with apk add zsh, and to launch type zsh. If you want acess to your internal storage first log out of the proot environment then edit the start script, remove the “#” from the line “ #command+=" -b /sdcard” ”.

note that there’s a double quote next to sdcard, don’t change anything else besides the “#”

To uninstall an os installed with proot-distro simply type:

proot-distro remove system_alias

if you used anlinux:

just open anlinux, go to the uninstall tab, choose the system to uninstall copy the command an paste in termux (not logged inside the system!)

--

--

Cranberry

Howdy, I'm currently studying software engineering at the 42 school, i've created this account to train my teaching skills and hopefully make something special.