Android

How to Use Termux to Run Command Line Linux Apps in Android

This article covers a guide on the “Termux” Android app that allows you to run command-line programs and scripts on Android devices.

Termux is an open-source terminal emulator application that works on Android devices. It also works as a sort of mini Linux OS, packed with many tools and utilities you commonly see in desktop Linux distributions. You can use Termux to install and run numerous command-line apps through its own package manager. No root access is required to install and run Termux on Android. You can even use a lightweight desktop environment GUIs without hardware acceleration through Termux (via VNC), but they may be slow and not exactly usable on small screen touch devices. Termux is extremely popular among developers and other users who want to access CLI Linux apps on Android. It is the closest thing you get to a Linux OS on Android, and it is a pleasure to use with its touch-optimized interface suitable for small screen devices. Termux features additional keyboard actions making it easy to input symbols, and also features auto-completion through the <TAB> action key located in the top row of the on-screen keyboard.

Use Cases

Some things you can do with Termux:

  • Run Python scripts
  • Run Bash scripts
  • Play command-line games
  • Access Vi editor
  • Make SSH connections
  • Create Python virtualenv
  • Develop apps as long as you don’t need GUI access
  • Install additional packages with pip, npm, cpan, gem, tlmgr, and other such package managers
  • Basically, anything that an installed package allows you to do through its command-line interface

Installing Termux on Android

You can download and install Termux through Google Play or from F-Droid. Launch Termux through the launcher, and you should be greeted with the following screen:

Enabling Storage Access on Termux

To access files in the Termux terminal or to save files from the Termux terminal, you will first need to setup the Termux storage and provide storage access permissions to Termux when prompted. You can do so by executing the following command:

$ termux-setup-storage

Once you are through the storage setup, you will be able to find Termux files stored in the “shared” folder in the internal storage of your Android device. If the “shared” folder doesn’t exist, you can manually create one. Usually, the full path to this “shared” folder is “/storage/emulated/0/shared”.

Installing and Managing Official Termux Packages

Once you have installed Termux, run the command below to update and upgrade repositories:

$ pkg upgrade

Now you can install your desired packages using the following command:

$ pkg install <package_name>

After installation, you will be able to run the command for the installed package in the Termux terminal (just like you would do on a desktop Linux OS):


You can get a list of installable Termux packages from here. You can also search and look for packages in Termux itself. To do so, run a command in the following format:

$ pkg search <search_term>

You can also list all packages using the following command:

$ pkg list-all

Installing Deb Packages in Termux

You can install certain “.deb” packages from Ubuntu or Debian repositories as long as they are made for your mobile’s architecture (these days, mobiles mostly have aarch64 and aarch32 architectures). Note that some packages may refuse to work on Termux. To install a “.deb” package, run a command in the following format:

$ dpkg -i <deb_package_name>

To remove a manually installed “.deb” package in Termux, run a command in the following format:

$ dpkg --remove <deb_package_name>

To list all manually installed “.deb” packages, you will need to run the following command:

$ dpkg -l

Any “.deb” package from any package source can be installed as long as it meets compatibility requirements. As always, you should be careful when picking up third party packages to prevent the installation of suspicious packages.

Enabling Additional Repositories in Termux

You can also enable extra repositories in Termux to enable the installation of additional packages. To find more repositories, visit this page and click on repositories having names ending with “-packages”. You will find the command for enabling these repositories in their “README” files. The command for enabling extra repositories looks like this:

$ pkg install <repository_name>

Below are some examples that have I have tested and found working on Termux:

$ pkg install x11-repo

$ pkg install game-repo

$ pkg install root-repo

$ pkg install unstable-repo

$ pkg install science-repo

Some third-party community repositories can also be enabled. You will find a list of these repositories available here.

Installing Termux Add-ons

Termux provides some useful add-ons that can be installed on an Android device through the Play Store. Some of these extra add-ons are free, while others are paid. You can find a list of these add-ons available here.

Conclusion

Some apps on the Play Store allow you to install and run full Linux environments on Android. However, a few of them require root access, and they are not exactly easy to use. As far as user-friendliness is concerned, there is nothing else like Termux on the Play Store.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.