Termux: Linux applications on Android
Termux is an Android app that provides a Linux environment and terminal emulator for such devices. Most command-line software can be used quite easily with Termux, and GUI software can be run by installing a few extra apps. It is an excellent option for Android users who want to run Linux software occasionally on a device more portable than a laptop but do not want to use a dedicated Linux phone due to the cost or limitations of such devices.
The Android operating system runs on the Linux kernel, but it cannot run most desktop Linux software on its own because its user space is almost entirely different. One of the most important differences is the absence of the GNU C library (glibc); Android uses Google's custom Bionic C library implementation, released under the three-clause BSD license, instead. Android's filesystem layout is also different from that of a typical Linux system, necessitating adaptations to run standard Linux software.
Because of these differences, software generally must be compiled specifically for Termux. The app's developers maintain repositories containing rebuilds of widely-used command-line Linux software, as well as many GUI programs.
Command-line software
The simplest use case for Termux is running standard command-line Linux software. Most programs work fine with only the base Termux app installed. One common use is SSH. By installing either OpenSSH or Dropbear, it is possible to use Termux to remotely access another machine. This works in exactly the same way as using SSH from a desktop or laptop. Another program that I often run is the Python REPL. Programming on a phone is not ideal but is not too difficult for simple scripts; the Python console also works well as a calculator. Command-line text editors also work; I use Vim regularly in Termux (screen shot on the right), and it works as well as it does on a laptop or the PinePhone.
Of course, typical phone keyboards are not suitable for command-line use due to their lack of keys such as Ctrl, Alt, Tab, and the arrow keys. Termux does use the phone's standard keyboard, but it provides these keys in a row above the main keyboard. The hyphen and forward slash are also included because it usually takes several taps to access them in a phone keyboard, but they are used quite often in typing command-line options and file paths. Termux disables the phone keyboard's auto-correct and predictive text, because these features would interfere with typing commands.
Installation
Termux can be installed from F-Droid or downloaded as an APK from GitHub. Releases are infrequent, but this is because the app itself does relatively little and needs few updates. The project itself is actively developed. Using the F-Droid version is recommended due to its automatic-update functionality. There is a listing for Termux on the Google Play Store, but the version is several years out of date and should not be used.
Termux works on most of the Android devices in active use. It runs on Android 5.0 through 12.0, supports 32- and 64-bit Arm, i686, and x86_64 devices, and requires only 300MB of disk space for a minimal installation.
Once Termux is installed, most users will want to install more software, of course. The default distribution is quite minimal with only some basic command-line utilities (grep, Bash, tar, curl, etc.) and the nano text editor. The package manager, pkg, is a wrapper around Debian's apt. The packages come from a custom repository run by the Termux developers. pkg supports most basic apt commands, but allows abbreviations as long as they are unambiguous; for example, "pkg in vim" is equivalent to "apt install vim".
Termux has three repositories: main, X11, and root. The main repository contains command-line software and common libraries, the X11 repository contains GUI software and X11-specific libraries, and the root repository contains software and libraries that are only useful on rooted devices. Due to Termux policy, hacking and penetration-testing software is not included in any of the repositories.
It is possible to build or develop other software for Termux in many different languages. The libc problem can be handled by rebuilding packages using the Android Native Development Kit (NDK), which is largely released under FOSS-license terms, though the full license picture is not entirely clear. The NDK automatically uses Bionic for its C library; the majority of Linux software can be compiled using other C library implementations, including Bionic. The filesystem layout is accounted for by patching the package sources to refer to files in the locations that Termux uses rather than the standard locations used on desktop distributions.
Termux:API
Although the main Termux app is quite powerful, it does have several limitations. It mostly creates an isolated environment with little ability to interact with the main Android operating system. However, Termux can integrate with several add-ons, which are separate apps that connect to Termux and provide extra functionality. One of these apps is Termux:API, which allows scripts running in Termux to integrate with Android itself, by providing command-line programs for Android API calls. In addition to installing the Termux:API app, it is necessary to install the package termux-api in Termux (pkg in termux-api).
Termux:API provides several commands related to communication. Content can be shared from within Termux; either a file or text from standard input can be shared, and once the Android share dialog opens, it works the same as sharing from any other app. Termux can be used to receive and send SMS messages. Sending requires that the Android SEND_SMS permission be granted to Termux:API; I did this using Android Debug Bridge (ADB). It is also possible to make outgoing calls, but not detect or answer incoming calls, using Termux:API.
Termux can take photos using the device's camera, though there is no way to record videos. Audio recordings can be both made and played; the audio player does accept videos but only plays the audio.
Termux:API provides a variety of commands for changing device settings, such as screen brightness, volume, and wallpaper image. It also allows access to the device's shared storage; after running termux-setup-storage, a directory called storage will be created in the Termux home directory with symlinks to the shared-storage root and several often-used subdirectories. This provides an easy way to share files between Termux and other apps.
Termux:X11
Termux:X11 allows for the use of X11 software in Termux (as can be seen in the screen shot on the right). It is still in early development and has little documentation; those seeking a more stable experience may prefer one of the other methods to run GUI software. For me, however, Termux:X11 works quite well, although it does still have several bugs.
Termux:X11 has no stable release yet; the only prebuilt APKs available are the GitHub Actions build artifacts. The app is under active development, and new APKs are built with each commit. Unlike the other add-ons, Termux:X11 does not need to be installed from the same source as the main Termux app; the APKs from GitHub work fine with the main app from F-Droid. After installing the app, some software also needs to be installed in Termux:
$ pkg in x11-repo $ pkg in termux-x11-nightly xfce4
The installation must be done in two commands because the first command enables the repository and the second one installs the software. The xfce4 package includes only a minimal desktop; other packages, such as xfce4-terminal or firefox, can be appended to the command.
The command that I use to launch the desktop is:
$ am start --user 0 com.termux.x11/com.termux.x11.MainActivity; \ rm -f .ICEauthority; \ sleep 3; \ termux-x11 :1 -xstartup "xfce4-session"I put that all in a script, however. The am command automatically launches the Termux:X11 app and brings it to the front. On my phone, if the .ICEauthority file is not deleted, the desktop disappears shortly after loading and an "ICE I/O Error" shows in Termux. (The same error also happens if you switch out of Termux:X11 app and return; once it happens, it is necessary to return to Termux and re-run the command.)
The phone keyboard can be opened and closed using the device's back button. Termux:X11, like Termux itself, disables predictive text and shows a bar with extra keys. It seems that this bar covers the bottom section of the display rather than shrinking the display, but there is an option in preferences (accessed using a button shown when Termux:X11 is opened without a client) to make the volume-down button toggle the extra key bar. The mouse cursor is controlled by using the phone screen as if it were a laptop touchpad.
Of course, running non-mobile-optimized software on a smartphone does not provide the best experience; many of the same problems that exist with desktop software on the PinePhone also exist with Termux:X11. Additionally, because smartphones have a higher pixel density than typical desktops, most items on the screen, including text, are extremely small. Termux:X11 has a scaling option in its preferences, which helps with this problem. The image is slightly blurred when scaling is enabled, and there is, of course, less screen space available when objects are twice as large, but it will probably still be better for most users to enable scaling; the text is almost unreadable at the default size. The scale option in Xfce display settings does not work; instead of scaling up the display, it shrinks the usable area to only a fourth of the screen and makes objects even smaller.
Termux's selection of GUI software is much less extensive than its selection of command-line software; for example, LibreOffice is not available, but AbiWord is, and Chromium is not available, though Firefox is. Despite the limited selection, the applications that I have tested all work well.
Conclusion
Termux provides many of the benefits of Linux smartphones, such as the PinePhone, without some of the drawbacks. It is not a perfect solution, and X11 support can be particularly problematic, but for those who primarily use Android apps and only use Linux software occasionally, it is likely a better option than a dedicated Linux phone. But those who use mobile-Linux software extensively would probably find a Linux phone to be a better choice than an Android phone with Termux. Many Linux phone users also have another phone due to the limitations of current Linux phones, such as a lack of apps for mobile Linux and the performance/stability of the PinePhone; for these users, having Termux installed on the other phone can be helpful when the Linux phone is not available for some reason.
Index entries for this article | |
---|---|
GuestArticles | Sloniker, Sam |
Posted Jul 6, 2023 10:19 UTC (Thu)
by johanwiden (subscriber, #137175)
[Link] (2 responses)
Posted Jul 6, 2023 17:00 UTC (Thu)
by KJ7RRV (guest, #153595)
[Link]
Posted Jul 19, 2023 12:57 UTC (Wed)
by lypanov (guest, #8858)
[Link]
Posted Jul 6, 2023 15:06 UTC (Thu)
by wsy (subscriber, #121706)
[Link] (1 responses)
Posted Jul 6, 2023 17:00 UTC (Thu)
by KJ7RRV (guest, #153595)
[Link]
Posted Jul 6, 2023 17:17 UTC (Thu)
by jak90 (subscriber, #123821)
[Link] (1 responses)
https://github.com/termux/termux-packages/wiki/Termux-and...
Posted Jul 6, 2023 18:49 UTC (Thu)
by mjg59 (subscriber, #23239)
[Link]
Posted Jul 6, 2023 17:58 UTC (Thu)
by meyert (subscriber, #32097)
[Link]
Posted Jul 7, 2023 2:39 UTC (Fri)
by salimma (subscriber, #34460)
[Link] (2 responses)
Posted Jul 7, 2023 4:45 UTC (Fri)
by KJ7RRV (guest, #153595)
[Link] (1 responses)
Posted Jul 19, 2023 12:55 UTC (Wed)
by lypanov (guest, #8858)
[Link]
Posted Jul 11, 2023 18:26 UTC (Tue)
by alkbyby (subscriber, #61687)
[Link] (3 responses)
Posted Jul 11, 2023 19:17 UTC (Tue)
by excors (subscriber, #95769)
[Link] (2 responses)
Also it was BSD-licensed, which was important since "we want to keep GPL out of user-space". (https://sites.google.com/site/io/anatomy--physiology-of-a...)
A lot of the code was adapted from OpenBSD/FreeBSD/NetBSD, though some was written from scratch. They couldn't use musl because this was >3 years before musl existed. And once they had shipped Bionic, it would probably be very difficult to switch to a different libc without breaking compatibility with apps.
Posted Jul 11, 2023 20:08 UTC (Tue)
by Wol (subscriber, #4433)
[Link]
But remember. Glibc is *by design* a STANDARD C library. Which means it's full of cruft supporting things like the DEC Alpha, the Playstation 1, etc etc. And it's missing a lot of things that you want in a linux library, or an android library.
Systemd, for example, which targets linux exclusively, needs a lot of linux code which the naive observer would expect to be in the standard library. Maybe it will get there eventually, but it's a slow process. And that process was a lot slower a few years back.
Linux today is pretty much the only game in the Unix town. It would make a lot of sense to ditch (or fork) glibc and dump all the stuff that's not relevant to linux. Don't be surprised that people like Google thought that, actually, it was in their interest to do so.
In linux-land, though, I doubt anyone wants to do it. In Google-land, they probably had to throw a couple of engineers at it to deal with all the custom hardware interfaces - it wasn't that big a stretch to go the whole hog and just fork/create your own C library.
Cheers,
Posted Jul 11, 2023 20:59 UTC (Tue)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Around 2005. During the darkest days of glibc, when it had the main maintainer with a very... abrupt... personality. I believe, the only other existing libc at that point was uClibc.
Posted Jul 20, 2023 12:39 UTC (Thu)
by jengelh (subscriber, #33263)
[Link] (2 responses)
Which is why you just install "Hacker's Keyboard". This has benefits beyond termux; Ctrl-A,C,V; ^A/^X; ^A,Del come to mind to quickly clear all text from some field.
There are a bunch of key combos that don't work in HK, like Ctrl-_ or Ctrl-Bksp. Then again, use of ^_ is few, but it does make an appearance in Alpine (so, also, pico/nano editor?).
Posted Jul 28, 2023 0:33 UTC (Fri)
by Kamilion (subscriber, #42576)
[Link] (1 responses)
Posted Aug 11, 2023 17:05 UTC (Fri)
by leephillips (subscriber, #100450)
[Link]
I installed a Debian container on top of Termux, and now I have a Julia REPL on my phone.
Termux: Linux applications on Android
One can for instance create an Ubuntu container, and in that install and run software that is not available in Termux, such as for example Steel Bank Common Lisp.
The great thing about pseudoroot containers, is that they do not have super user access to Android, so they are more secure.
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Wol
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android
Termux: Linux applications on Android