How to Install and Configure tmux

October 3, 2024

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.

Learning how to install and configure tmux.

Prerequisites

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 DistributionCommand to Install tmux
Ubuntu/Debiansudo apt install tmux -y
RHEL/Rocky Linuxsudo yum install epel-release -y && sudo yum install tmux
Fedorasudo dnf install tmux
Arch Linuxsudo pacman -S tmux
OpenSUSEsudo zypper install tmux
Alpine Linuxsudo 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.

An example of a tmux session window.

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.

An overview of tmux sessions, windows, and panes.

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.

Multiple tmux windows within a session.

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.

Multiple panes within a tmux window.

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
Modifying the status bar color in tmux.

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.

Was this article helpful?
YesNo
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
Linux Commands Cheat Sheet: With Examples
November 2, 2023

A list of all the important Linux commands in one place. Find the command you need, whenever you need it or download our Linux Commands Cheat Sheet and save it for future reference.
Read more
How To Install and Use Linux Screen, With Commands
April 7, 2022

Linux Screen provides users an option to open several separate terminal instances within a single terminal window manager. This tutorial will show you how to install and use Screen on a Linux system.
Read more
How to Install and Configure Squid Proxy on Ubuntu
May 29, 2024

Squid is a Linux-based proxy application that can be used for filtering traffic, security, DNS lookups, and speeding up a web server by caching resources. This guide explains how to set up and install Squid Proxy on Linux.
Read more
Top 10 DevOps Trends in 2024
October 3, 2024

This article explores the top ten DevOps trends in 2024, giving insights into how you can enhance efficiency, security, and innovation within your organization.
Read more