Run Linux on Your Phone with Termux: Turn Any Android Device into a Pocket Server
This guide shows how to install Termux from the official GitHub releases, update its package sources, add essential development tools, access Android storage, run Python scripts, connect to remote servers via SSH, and extend functionality with tmux, proot‑distro and other utilities, turning a phone into a fully functional Linux environment.
As a long‑time operations engineer, I always keep a tool on my phone that can connect to servers. Termux provides a complete Linux environment on Android without requiring root, flashing, or a virtual machine.
What is Termux?
Termux is an Android terminal emulator that includes a package manager ( pkg) compatible with Ubuntu's apt, a compiler suite, and runtimes for Python, Node.js, Ruby, etc. It works out‑of‑the‑box after installing the APK.
Installing Termux
Do not download from Google Play; the version there is unmaintained. Use the official GitHub releases page ( https://github.com/termux/termux-app/releases) and install the latest termux-app_v0.118.x_arm64.apk. After installation, the app shows a plain terminal welcome screen.
Updating Package Sources
Run pkg update && pkg upgrade to refresh the package index and upgrade installed packages. For slower connections, replace the default source with Tsinghua University's mirror by editing $PREFIX/etc/apt/sources.list:
sed -i '[email protected]@mirrors.tuna.tsinghua.edu.cn/termux@' $PREFIX/etc/apt/sources.listInstalling Essential Tools
A typical one‑liner to install a full toolset is:
pkg install git python wget curl vim openssh tmux htop nmap treeThe article explains each tool’s purpose (e.g., git for version control, htop for process monitoring, nmap for network scanning).
Accessing Android Files
Run termux-setup-storage to create ~/storage links to the device’s Pictures, Downloads, Music, etc. Example:
cd ~/storage/downloads
tar -xzf myproject.tar.gz
ls myproject/This lets you manipulate phone files directly from the terminal.
Running Python Code
After installing the Python package, you can edit scripts with vim and execute them:
vim hello.py
python hello.pyThe script prints hostname, platform, and Python version, confirming the Linux environment. Additional packages can be installed via pip (e.g., pip install requests flask numpy).
SSH Remote Access
Connect to remote servers with: ssh [email protected] -p 22 It is recommended to set up key‑based authentication:
ssh-keygen -t ed25519
ssh-copy-id [email protected]Advanced Usage
tmux : keep long‑running tasks alive when the app is closed.
tmux new -s mysession
python long_running_script.py
# Detach with Ctrl+B then D
tmux attach -t mysessiontsu : obtain root inside Termux on rooted devices ( pkg install tsu && tsu).
nmap : portable network scanner ( nmap -sP 192.168.1.0/24).
proot-distro : install a full Linux distribution such as Ubuntu (
pkg install proot-distro
proot-distro install ubuntu
proot-distro login ubuntu).
Additional Tips
Enable “unrestricted” battery optimization or run termux-wake-lock to prevent background kills.
If storage permission fails, grant it manually in Android settings.
Switch mirrors to USTC if Tsinghua is slow.
sed -i '[email protected]@mirrors.ustc.edu.cn/termux@' $PREFIX/etc/apt/sources.listClear Termux cache (not data) to recover from crashes.
Conclusion
Termux turns any Android phone into a portable Linux workstation. It supports command‑line practice, SSH management, Python scripting, web services, Docker (with root), and even penetration‑testing tools, making fragmented time ideal for improving Linux skills.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Agent Super App
AI agent applications, installation, large-model testing, computer fundamentals, IT operations and maintenance exchange, network technology exchange, Linux learning
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
