Introduction
tmux is a Linux utility that allows users to manage multiple sessions and processes from a single terminal window. You can run several processes simultaneously, switch between them, and detach or reattach to remote sessions without interrupting them.
Find out how to install tmux on Linux and customize its interface with practical configuration examples.
Prerequisites
- A Linux-based system.
- A user account with sudo or root privileges.
- Access to a terminal window/command line.
How to Install tmux
To install tmux
, use your system's default package manager. Access the command line and enter the installation command for your Linux distribution:
Linux Distribution | Command to Install tmux |
---|---|
Ubuntu/Debian | sudo apt install tmux -y |
RHEL/Rocky Linux | sudo yum install epel-release -y && sudo yum install tmux |
Fedora | sudo dnf install tmux |
Arch Linux | sudo pacman -S tmux |
OpenSUSE | sudo zypper install tmux |
Alpine Linux | sudo apk add tmux |
Note: The examples in the tutorial are presented using Ubuntu 24.04.
After the tmux
installation is complete, start a new named session using the following command:
tmux new -s [session_name]
Replace session_name
with the desired name for your session.
The screen changes and displays a status bar at the bottom. The session name (test
) and window number (0:bash*
) are shown on the left side of the status bar.
On the lower-right, tmux
displays the hostname (phoenixnap
) and the time and date.
You can now start issuing commands in tmux
. Use this handy cheat sheet to learn essential tmux commands like how to create sessions, switch between windows, and split panes.
Working In tmux
tmux
uses sessions, windows, and panes to help users split tasks and manage them in an organized workspace.
tmux Sessions
A tmux
session is a unified workspace that contains all activities and commands for a specific project. For example, a development project involves coding, debugging, and testing. You can organize these tasks within a single session instead of opening a new terminal window for each one.
tmux Windows
tmux
windows are used to create separate workspaces for tasks within a session. Rather than opening a new session for each activity, developers can edit code in one window, compile it in another, and run unit tests in a third.
Since processes in windows run separately, you can switch between them without disrupting ongoing tasks.
tmux Panes
Panes are used to split a window into multiple sections. Panes can be arranged horizontally or vertically, depending on how you want to divide the screen. For example, you can run a script in one pane while monitoring logs in another, allowing you to track both tasks without switching windows.
How to Configure tmux
In the tmux
configuration file, tmux.conf, you can add custom commands to remap function keys, adjust the visual appearance of sessions, windows, and panes, and configure their features and behaviors.
Use a text editor, like Nano, to create or edit the file in the system directory:
sudo nano /etc/tmux.conf
System-wide settings affect all users. If you want to limit custom settings to a specific user, create or edit the tmux.conf file in that user's home directory:
sudo nano ~/.tmux.conf
Change Activation Key
By default, tmux
uses CTRL+b
to activate functions. To change the default key binding to, for example, CTRL+a
, add the following in the tmux.conf file:
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
Save the changes and exit the editor. You must close and restart any active sessions for the changes to take effect.
Remap Keys to Split Panes
You can remap function keys to manage panes more efficiently. For example, remap the horizontal split from CTRL+b+%
to CTRL+b+h
, and the vertical split from CTRL+b+"
to CTRL+b+v
:
unbind '%'
bind h split-window –h
unbind '"'
bind v split-window -v
You can remap any function key in this way. Remember to use single quotes around a key to ensure the system interprets it correctly.
Customize Status Bar Appearance
You can customize the appearance of the status bar by changing its color. To change the status bar's background to blue and its foreground to black, add the following lines to your configuration file:
set -g status-bg blue
set -g status-fg black
To define a color more precisely, you can use numerical color codes (0–255) instead of color names.
Enable Visual Notifications
Add the following commands to enable visual notifications when tmux
registers new output or activity in a window:
setw -g monitor-activity on
setw -g visual-activity on
tmux
will highlight the window's status in real-time. This means you can easily monitor changes without needing to switch between windows.
Change Window Numbering
By default, tmux
starts numbering windows at 0. Add the following line to the configuration file to start window numbering at 1:
set -g base-index 1
When you open a new window in a session, the numbering starts at 1 instead of 0, which is a more natural counting convention for many.
Change Pane Numbering
Pane numbering in tmux starts at 0. Add the following line in the tmux.conf file to start pane numbering at 1:
set -g pane-base-index 1
This change is recommended if you have already modified window numbering to 1, as it helps maintain a consistent numbering scheme.
Conclusion
In this tutorial, you learned how to install tmux
and customize it to fit your workflow.
You'll find that tmux
excels in multitasking scenarios, such as managing multiple remote machines over SSH.