Use a Linux terminal on your Android phone |

Use a Linux terminal on your Android phone

Use a text editor, SSH into a computer, or even maintain your Kubernetes cluster right from the palm of your hand with Termux.

Tux and Android stuffed animals on shelf
Image credits : 
Quinn Dombrowski via Flickr. CC BY-SA 2.0

Subscribe now

Get the highlights in your inbox every week.

When it comes to ultra-mobile computing, I prefer the PocketCHIP or a Raspberry Pi with a screen rather than a mobile phone or tablet. These solutions offer a pure Linux environment that's as open source as the hardware allows and make no assumptions about how I expect to work.

Sometimes, though, the only thing I have on me is a mobile phone. While there are some really great Android apps out there, many feel like overkill for simple tasks, especially knowing how much can be done in a simple terminal on my Linux desktop. I'm not the only person who feels this way, and that's why the Termux project was born.

Termux is a terminal emulator and Linux environment app for Android. It also doesn't require you to root your device.



(Seth Kenlon, CC BY-SA 4.0)

Termux installs a minimal base system automatically, and additional packages are available using a package manager, just as you do with Fedora, Debian, or the like.

Install Termux

Installing Termux is as easy as installing any app on your Android device. You can use either the default Google Play store or the open source app repository F-Droid.

You can also download the source code and compile it yourself.

Linux-like Android

Once you have Termux installed on your mobile phone, you essentially have a minimal Linux system running as an application on your (Linux-based) Android device. You can use most of the usual terminal applications you are familiar with, or you can become familiar with them now that you have them on your phone. Most importantly, the Termux interface provides software Ctrl, Alt, Esc, and arrow keys, so essential keystroke shortcuts are easy to type—even on a virtual keyboard. On long trips, I prefer to carry a Bluetooth keyboard with me, so I can use Termux as easily as a terminal on my desktop or laptop.

By default, Termux runs Bash:

$ echo $0

Most of the commands you're used to will work as expected, whether they're built-in Bash commands or the usual array of common Linux commands and utils. There are also several other shells available, including Zsh and tcsh.

Installing commands

If you're used to Linux, or even Homebrew on a Mac or Chocolatey on Windows, then you already know how to install more commands for Termux. Its backend package manager is Apt from Debian Linux, but Termux uses the pkg command as a simplified frontend interface. The result approximates the consistent simplicity of Fedora's DNF experience, and I'd love to see pkg as an abstraction layer on more platforms (imagine using the same package management commands on Debian, RHEL, and Slackware).

The first package I installed was a simple text editor:

$ pkg search jed
jed/stable 4.6-4 aarch64
Lightweight text editor
$ pkg install jed

Running Jed was exactly the same as running it on my RHEL desktop. Both run in the terminal and use the same keyboard shortcuts. That's exactly the mobile experience I want: the same as my desktop.

Remote control

A text editor is one thing, but Termux reveals its true potential the first time you SSH into a computer. Through this simple terminal, you can log onto any computer on any network you have access to. You have a portable console you can use either as a host or as a terminal into any amount of computing power available to you.

This doesn't end with SSH, though. There's a Termux package for kubectl, so by using the use-context option in kubectl, you can maintain your Kubernetes cluster from anywhere.

Contributing to Termux

One of my favorite things about Termux is that it removes a significant barrier to contributing to a mobile project. All current open source mobile platforms are Android or Android-based, requiring a special toolchain and a fair amount of Java knowledge.

Termux, by nature, shields a potential new contributor from much of that because you can write packages for Termux without knowing anything about Android. You can create a package definition for Termux as long as you know how to write a shell script because you're writing a package for the Termux subsystem.

Put a terminal in your pocket

Termux is a great way to learn the Linux terminal, and it's easy to install. Put Termux on your phone or tablet, check out some of our terminal basics (such as our articles about mastering the ls and cat commands) and our Bash cheat sheet, and transform the way you use your mobile.

Cheat Sheet cover image

Download our new kubectl cheat sheet to learn helpful commands for the Kubernetes command-line utility.
A person looking at a phone

Take as many shots as you want; gphoto2 makes transferring photos from your device to your Linux computer quick and easy.
Hands holding a mobile phone with open on the screen

Get some writing work done on your mobile device with these four apps.

About the author

Seth Kenlon
Seth Kenlon - Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time. He is one of the maintainers of the Slackware-based multimedia production project Slackermedia.