Make Android Great (Again) - Dive into Termux

Background

Termux is an Android APP that can run a Terminal terminal inside Android, that is to say, it makes shell available on Android. But the entire Termux project is not just as simple as a terminal emulator, it includes a complete set of tool chains to allow Android to use shells (bash, zsh, fish, etc.), as well as various Linux program applications (python, perl, gcc, etc.).
Running Termux is equivalent to having an entire apt software warehouse that can run directly on Android. This apt software repository is compiled based on NDK, and it is a binary running mode natively supported by Android, which can be more easily transplanted to run in other Android apps.

Termux basics

Download and installation

  1. Download and install the app, it is recommended to download from f-droid (https://f-droid.org/en/packages/com.termux/), f-droid ensures that the apk is compiled from the corresponding source code
  2. Install it, out-of-the-box

How to search what packages are in the apt repository?

pkg search xx # e.g. pkg search sh lists all *sh* packages

How to install software from apt repository?

pkg install xxx

P.S. The apt command can also be used, but the pkg command is more recommended. Technically detailed explanation: pkg is actually a bash script, and the bottom layer still calls apt, but pkg will handle more boundary conditions, mirror load balancing and other logic.

How to install python in Android with termux?

pkg install python # pretty easy, right

Advanced usage of Termux

How to install pip package in python in android?

pip install xxx 

Note: Due to the "magic change" of $HOME, the old version pip cannot recognize (while the new version can) ~/.pip/pip.conf, so the configuration in pip.conf may not take effect under old version pip.

However, we can still manually specify pypi mirror if we want to:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx # using custom mirror 

Some pip packages can't recognize the modified $HOME either, using proot to cheat and improve compabitily:

proot -0 pip install xxx

How to install python version opencv in Android?

pkg search opencv # we can see two packages: opencv and opencv-python
pkg install opencv opencv-python 

# then we verify if opencv-python has been successfully installed
python -c import cv2; print(cv2.__version__) 
# will output opencv's installed version if success

Should I install python libraries via pip or pkg?

Simply put, if pkg repository provides a corresponding python library (use pkg search python to search for all supported Python libraries), then you should use pkg command first; otherwise, the alternative is pip installation.

Introduction to Termux code repository

The Termux project contains many git repos,can be found in https://github.com/orgs/termux/repositories?type=all.

The following introduces several commonly used important Termux repos.

Later, there will be a special topic to bring you more detailed Termux advanced usage guide.

Let's Make Android great (again), with Termux!

Leave a comment