How to Install and Use tmux in Termux (Mobile-Friendly Guide)
Android's background app killer is the enemy of anyone trying to run a long compile, a local server, or an SSH session from their phone. Switch apps for ten seconds and the process can be gone. tmux — a terminal multiplexer — is the standard fix: it keeps your terminal sessions alive on a background server process, lets you split one screen into multiple panes, and lets you reattach exactly where you left off. This guide covers installing it in Termux, the keybindings and config that actually work on a touchscreen, and the Android-specific persistence setup most tutorials skip entirely.
One thing worth knowing before you start: tmux keeps a session alive as long as its underlying process survives — but on Android, that process can still be killed by battery optimization or the background-process limits described in this guide to Termux crashes. Detaching from tmux isn't automatically bulletproof; the persistence section below covers the extra step (a wake lock) that actually makes it reliable.
What Is tmux and Why Use It on Android?
tmux lets you run multiple terminal programs in one window, split the screen into panes, and detach a running session so it keeps going in the background — then reattach later from the same or a different terminal. Inside tmux, work is organized in three layers:
- Sessions — the outer container; a session can hold multiple windows and keeps running independently of whether you're currently looking at it.
- Windows — full-screen views inside a session, similar to browser tabs.
- Panes — a window split into sections, so you can watch a log in one pane while typing commands in another.
Nearly every tmux command starts with a prefix key — by default Ctrl+b. You press and release the prefix, then press the command key.
Install tmux in Termux
Update your package indices first — skipping this is the single most common cause of a broken install. If you haven't installed Termux itself yet, start with this Termux installation guide; if you have, but haven't updated recently, see updating and upgrading packages in Termux for the full routine.
pkg update && pkg upgrade -y
pkg install tmux -y
Verify it installed correctly:
tmux -V
A version string (e.g. tmux 3.4) confirms it worked.
Your First tmux Session
Start a named session — naming it now saves confusion later when you have several running:
tmux new -s dev
You'll see a status bar appear at the bottom of the screen — you're now inside tmux. Try splitting the window horizontally (prefix, then "), move to the new pane (prefix, then an arrow key), and run something in it, like a local dev server. When you want to step away, detach rather than close the app:
Ctrl+b, then d
Your shell returns to normal Termux, and the session — including anything running in it — keeps going in the background (subject to the wake-lock caveat above). To list what's running and jump back in:
tmux ls
tmux attach -t dev
Must-Know Keybindings
| Action | Keys |
|---|---|
| New session | tmux new -s name |
| List sessions | tmux ls |
| Attach to session | tmux attach -t name |
| Detach | Prefix, then d |
| Split vertically (side by side) | Prefix, then % |
| Split horizontally (stacked) | Prefix, then " |
| Move between panes | Prefix, then arrow key |
| New window | Prefix, then c |
| Close pane | Prefix, then x |
| Rename session | Prefix, then $ |
Android Keyboards and the Prefix Key
Ctrl+b is awkward to reach on a lot of on-screen and third-party Android keyboards, and some launcher/gesture combinations intercept it entirely. If it feels unusable, remap the prefix to something easier to reach, like Ctrl+a. Open the config file — see using nano and vim in Termux if you're new to either editor:
nano ~/.tmux.conf
Add:
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
Reload it without restarting tmux:
tmux source-file ~/.tmux.conf
A Minimal, Mobile-Friendly ~/.tmux.conf
Skip plugin managers and heavy themes on a phone — they slow startup for little benefit on a small screen. This covers the essentials: mouse support, a longer scrollback, and 1-indexed windows (easier to reach on a keyboard):
# ~/.tmux.conf — minimal, mobile-friendly
# Mouse support: tap to switch panes, drag borders to resize, scroll to view history
set -g mouse on
# Longer scrollback buffer
set -g history-limit 10000
# Start windows/panes at 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1
# Faster escape response (helps with some Android keyboards)
set -sg escape-time 0
# Simple status bar
set -g status-style bg=black,fg=green
set -g status-left "#S "
set -g status-right "%H:%M"
Save, then reload with tmux source-file ~/.tmux.conf. If you also want to customize font size or color scheme at the Termux app level rather than inside tmux, see changing Termux font and color.
Copy-Mode and Scrollback on Touch
With mouse on set above, you can scroll tmux's history just by swiping/scrolling in the terminal, and tap to switch panes — no keyboard shortcuts required for the basics. For selecting and copying text, enter copy mode with the prefix and [, move with the arrow keys, and press q to exit. On touch devices this is fiddlier than on desktop; for quick copy-paste, long-pressing inside the Termux terminal itself (using Termux's own selection, not tmux's) is often faster than tmux's keyboard-driven copy mode.
Keep Sessions Alive on Android (the Part Most Guides Skip)
A detached tmux session is not automatically safe from Android's battery management. Two things make it durable:
1. Hold a Wake Lock While Something Important Is Running
termux-wake-lock
This asks Android not to sleep the CPU while Termux is active, which matters for anything long-running — a build, a sync, an SSH tunnel. Release it when you're done with:
termux-wake-lock-release
2. Auto-Start on Boot with Termux:Boot
Install the separate Termux:Boot add-on app (F-Droid or GitHub, matching your Termux install source), open it once so Android grants it boot permission, then create a script:
mkdir -p ~/.termux/boot
nano ~/.termux/boot/start-tmux
Contents:
#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
tmux new-session -d -s main
Make it executable:
chmod +x ~/.termux/boot/start-tmux
Now a main tmux session starts automatically after a reboot, with a wake lock held from the start. If you're running something like a persistent SSH server this way, pair it with this guide to SSH in Termux.
3. For Managed Daemons: termux-services
If you're running something that should behave like a proper background service (sshd, a database, a bot) rather than living inside your interactive tmux session, termux-services is a better fit than stuffing everything into tmux:
pkg install termux-services
sv-enable sshd # auto-starts sshd whenever Termux opens
Use tmux for the things you're actively working in, and termux-services for daemons you just want running unattended.
Small-Screen Layout Habits
Desktop tmux setups often use four or more panes at once. On a phone, stick to one or two — a second pane for a log tail or server output alongside your main working pane is usually the practical limit before text becomes unreadable. Prefer vertical stacking (prefix, ") over side-by-side splits on portrait screens; side-by-side splits only make sense in landscape or with an external display.
Naming Sessions and a Quick Attach-or-Create Alias
Always name sessions (tmux new -s project-name) once you have more than one running — tmux ls with three unnamed numbered sessions is not useful. A small alias saves a step every time you come back to a project. Add this to your shell config (~/.bashrc or ~/.zshrc — see installing and configuring Zsh if you'd rather use Zsh):
alias tm='tmux new-session -A -s main'
The -A flag attaches to the session if it already exists, or creates it if it doesn't — one command instead of checking tmux ls first.
Basic Session Security
A phone is more likely to be picked up unlocked or briefly borrowed than a desktop. If a tmux session might contain anything sensitive, you can lock it manually:
tmux lock-session
This requires your Android device's own unlock method to get back into the shell (via vlock or your system's lock command, if configured), but it does not replace properly securing secrets — avoid storing API keys or passwords in plaintext files in your home directory regardless.
Common Errors and Fixes
| Error / Symptom | Likely Cause | Fix |
|---|---|---|
error connecting to /data/data/com.termux/files/usr/var/tmux-1000/default (No such file or directory) |
tmux server crashed or storage state changed abruptly | tmux kill-server then tmux to start fresh |
| Prefix key doesn't register / gets intercepted | Android keyboard or gesture conflict with Ctrl+b | Remap prefix to Ctrl+a (see above) |
| Colors or box-drawing characters render garbled | TERM variable not set correctly |
Add export TERM=xterm-256color to your shell config before launching tmux |
| "Duplicate session" when creating a new one | A session with that name already exists | tmux attach -t name instead, or pick a different name |
If tmux itself seems fine but Termux is crashing or restarting around it, that's a separate issue — see the full Termux black screen and crash troubleshooting guide.
Next Step: tmux with a GUI (Brief)
If you eventually want a full desktop environment (for running GUI apps like a code editor or browser) alongside your terminal work, tmux runs inside a Termux:X11 or proot-distro session the same way it does in plain Termux — start tmux as usual once your DISPLAY variable is set. This is a more advanced setup than this guide covers; if you're using companion apps like Termux:API for this, Termux vs Termux:API: what's the difference is a good primer first.
FAQs
Does tmux survive closing the Termux app?
Yes, as long as the underlying process isn't killed by Android's battery management first. Detaching (Ctrl+b, then d) keeps the session running; holding a wake lock or using Termux:Boot as shown above makes that reliable rather than occasional.
Do I need root to install tmux?
No. It installs through Termux's standard package manager with no root required.
How do I fully close a tmux session instead of just detaching?
Type exit in every pane of that session. Once the last pane exits, the session ends automatically.
Conclusion
tmux solves Android's background-killing problem for terminal work — but only completely once you pair it with a wake lock or Termux:Boot, since a detached session is still a process Android can kill. Install it, remap the prefix if Ctrl+b doesn't work for your keyboard, keep your config lean, and set up persistence before you rely on it for anything important.

Join the conversation