How to Install and Use tmux on Ubuntu
Tmux, or terminal multiplexer, is a unified workspace that enables users to organize and monitor several sessions within a single window. Apart from multitasking, it offers a number of features, such as detaching from a session and keeping it running in the background, and then reattaching when needed, seamless integration with different terminal applications, and persistence even if the connection is lost. Overall, it improves speed, productivity, and flexibility in terminal-based environments.
In this guide, we will demonstrate step-by-step instructions to install, configure, and use Tmux on Ubuntu.
How to Install Tmux on Ubuntu
To set up Tmux on Ubuntu, you must execute a few simple steps. First, update and upgrade your system repositories to avoid any conflicts during installation:
sudo apt update && sudo apt upgrade -y
Ubuntu provides tmux in its default repository. Therefore, we can install it directly using Ubuntu’s default package manager, apt:
sudo apt install tmux -y
Once Tmux is successfully installed on your system. Confirm its availability on your system by checking its version:
tmux -v
Now that Tmux is installed on your Ubuntu system, you can use it to manage several sessions and processes from a single terminal Window.
Tmux Commands Usage in Ubuntu
Tmux uses Windows, Sessions, and Panes to manage tasks more efficiently. Using Tmux commands, you can create, access, and control various terminals from a single session.
Tmux Sessions
A Tmux session is a single collection of one or more windows, and each window can have one or more panes. With a Tmux session, you can manage all activities of your project within a unified workspace instead of using a new terminal for each one.
| Command | Description |
|---|---|
| tmux | Starts a new session. |
| tmux new -s [sessionName] | Creates a new session and assigns it the specified name. |
| tmux attach | Connects to the most recently utilized session. |
| tmux a -t [sessionName] or
tmux attach -t [sessionName] |
Joins a particular tmux session by specifying its name. |
| tmux detach | Disconnect a session but keep running it in the background. |
| tmux ls or
tmux list-sessions |
Displays all currently running tmux sessions. |
| tmux rename-session -t [oldName] [newName] | Changes the name of an existing session. |
| tmux switch -t [sessionName] | Moves you to the selected session by name. |
| tmux kill-session -t [sessionName] | Terminates the session with the specified name. |
| tmux kill-session -a | Terminates all sessions except the current one. |
| tmux kill-session -at [sessionName] | Closes all sessions, excluding the one you specify. |
| tmux kill-server | Terminates the Tmux server along with all windows, sessions, and panes. |
Launching a New Tmux Session
To begin a new tmux session, simply enter the command:
tumx
This will open a fresh tmux session:
If you’d like to give your session a custom/specific name, you can start it using:
tmux new -s genieTest
Now the status bar shows the session name at the bottom left of your screen:
Once you are connected to a Tmux session, you can run different Tmux commands to achieve specific tasks.
Manage Tmux Sessions
You can use the tmux ls command to list all tmux sessions:
tmux ls
The output shows that there are two active tmux sessions named “genieTest” and “Test”. The “genieTest” is detached while the “Test” is attached
One of the notable features of tmux is detach and reattach to sessions. When you detach a tmux session, it returns you to the regular terminal; however, the tmux session keeps running in the background. To do this, you can use the tmux detach command or keyboard shortcut Ctrl+B then D:
tmux detach
After detaching from a session, you can reattach to it using the tmux attach command:
tmux attach
This command will reconnect to the latest active tmux session:
Similarly, if you want to terminate a specific session, you can run the following command:
tmux kill-session -t genieTest
You can verify the session termination using the tmux ls command:
Tmux Windows
Tmux enables us to create multiple Windows in a single session to perform different tasks or activities in a single workspace. Tumux Windows allows coders to write, compile, and test code in a single session. This way, they can switch between different windows without disrupting any task.
| Command/Shortcut Key | Description |
|---|---|
| tmux select-window -t [windowName] | Selects the specified window by its name or index. |
| tmux rename-window [newName] or
Ctrl+B then , |
Renames the current tmux window. |
| Ctrl+B followed by C | Opens a new window within the tmux session. |
| Ctrl+B then W | Press Ctrl+B and then W to list all tmux windows. |
| Ctrl+B followed by N | Moves to the next window in the session. |
| Ctrl+B followed by P | Moves back to the previous window. |
| Ctrl+B then & | Terminates the current window. Type y to confirm window termination. |
| Ctrl+B then D | Disconnect from the current session, leaving it running in the background. |
| Ctrl+B then L | Moves to the last open window. |
| Ctrl+B then 0….9 | Press Ctrl+b followed by a specific number from 0-9 to switch to that numbered window. |
Tmux Window Management
You can rename your current Tmux window to a specific name using the following command:
tmux rename-window testWindow
To list all windows, use the keyboard key combination Ctrl+B followed by W:
You can switch to the previous, next, or last open windows by pressing Ctrl+B followed by P, N, or L, respectively.
Tmux Panes
Panes let us divide windows into different sections, either horizontally or vertically. You can perform multiple functionalities on a single screen. For example, you can monitor the processes on one screen while running scripts on the other one. This way, you can monitor multiple tasks without toggling between different windows.
| Command/Shortcut Keys | Description |
|---|---|
| Ctrl+B then % | Divides the active pane into two vertical sessions. |
| Ctrl+B then “ | Splits the pane horizontally. |
| Ctrl+B followed by X | Exit the current Pane. It prompts for confirmation; press y to kill the current pane. |
| Ctrl+B then O | Moves to a different pane. |
| Ctrl+B followed by Z | Zooms the pane to full screen. |
| Ctrl+B then ; | Toggles between the two most recently used panes. |
| Ctrl+B followed by { | Shift the current pane one position to the left. |
| Ctrl+B then } | Moves the current pane one position to the right. |
| Ctrl+B then SPACE | Switches between different pane layouts. |
| Ctrl+B then ! | Converts the current pane to a window. |
| exit or
Ctrl+D |
Quits the selected pane. |
| Ctrl+B then Q | Shows the number of each pane. |
| Ctrl+B+[arrow keys] | Press Ctrl+B+arrow keys to adjust the height or width of the pane. Use Ctrl+B+Up or down arrow to increase or decrease the pane height, and Ctrl+B+left or right arrow keys to increase or decrease the pane width. |
| Ctrl+B then : | Resizes the pane. |
Manage Tmux Panes
To split the current pane vertically, press Ctrl+B followed by the % symbol:
Similarly, you can split it horizontally by pressing Ctrl+b and then “:
If you get confused in the pane numbers, simply press Ctrl+b followed by q to view the number of each pane:
Similarly, you can use different key combinations as discussed in the above table to manage your Tmux panes.
How to Configure tmux.conf on Ubuntu
Configuring the Tmux config file, tmux.config helps you to modify key bindings and window management. You can configure this configuration file for a specific user or all users.
To apply tmux settings across the entire system, open and modify the configuration file located at:
sudo nano /etc/tmux.conf
If you are looking to customize tmux settings only for your current user, then edit the config file in the user’s home directory:
sudo nano ~/.tmux.conf
You can include the below-listed commands in this file to configure Tmux for a particular purpose:
| Command | Description |
|---|---|
| set-option -g prefix C-X
unbind C-B bind C-X send-prefix |
Updates the tmux command prefix from Ctrl+B to Ctrl+X. |
| set -g status-bg colorName
set -g status-fg colorName |
Sets the background color and foreground color of the status bar to the specified colors. |
| setw -g visual-activity on
setw -g monitor-activity on |
Turn on visual alerts for any activity within the tmux windows. |
| set -g base-index 1 | By default, tmux assigns numbers to windows from 0 onwards. You can customize it to start Windows numbering from 1 instead of 0. |
| set -g pane-base-index 1 | Start the pane numbering from 1 rather than 0. |
| unbind %
bind h split-window –h |
Unbinds the horizontal split from % and modifies it to Ctrl+B+H. |
| unbind ‘”‘
bind v split-window –v |
Removes the default key binding for vertical splits and assigns Ctrl+B followed by V to split the current pane vertically. |
Customize Activation Key
In Tumx, pressing the Ctrl+B key combination activates the functions. However, we can overwrite this default behaviour in the Tmux config file. For example, the following command changes the default key function from Ctrl+B to Ctrl+X:
set-option -g prefix C-x
unbind C-b
bind C-x send-prefix
After saving this code in the config file, restart the active Tmux session to apply changes. Now, you need to press Ctrl+X to activate the function and then press any key to achieve a specific purpose. For example, to split the pane horizontally, you must press Ctrl+X followed by “, instead of Ctrl+C then “.
Edit Status Bar
By default, the background and foreground colors of the Tmux status bar are green and black, respectively. We can modify them as per our preferences by specifying the following lines of code in the tmux.conf file:
set -g status-bg red
set -g status-fg yellow
Save the Config file, and restart the active session to apply changes:
Similarly, you can customize the pane numbering, window numbering, enable visual notifications, and remap keys to split the pane.
Conclusion
To install tmux on Ubuntu, first, update and upgrade your system, then run the “sudo apt install tmux -y” command. After this, you can confirm the installation by executing the “Tmux -V” command. Once Tmux is successfully installed, you can type “tmux” in the Terminal to launch a new session, where you can create multiple Windows and panes to manage your tasks in a unified workspace. Moreover, you can configure the Tmux config file to customize the tmux settings for the current user or all users. In this guide, we demonstrated each step to install, configure, and use Tmux commands on Ubuntu.













