LinuxTutorials

How To Install Tmux Terminal Multiplexer on Linux

Install Tmux Terminal Multiplexer on Linux

In this tutorial, we will show you how to install Tmux terminal multiplexer on Linux. In the world of Linux system administration and development, efficiency and multitasking capabilities are essential for productive workflows. Tmux, short for Terminal Multiplexer, stands as one of the most powerful tools available for managing multiple terminal sessions. This comprehensive guide walks you through everything you need to know about installing and getting started with Tmux on various Linux distributions.

What is Tmux and Why Use It?

Tmux is an open-source terminal multiplexer that allows you to create multiple terminal sessions within a single window. The name “Tmux” itself is derived from “terminal multiplexer,” highlighting its primary function. Unlike standard terminal emulators, Tmux provides a layer of abstraction that separates your terminal sessions from the physical terminal window.

At its core, Tmux operates with three fundamental components:

  • Sessions: Independent terminal instances that can contain multiple windows
  • Windows: Full-screen virtual displays within a session
  • Panes: Subdivisions of windows that allow you to view multiple terminal instances simultaneously

The advantages of using Tmux extend far beyond simple window management. When working on remote servers via SSH, Tmux preserves your terminal sessions even if your connection drops unexpectedly. This persistence feature alone saves countless hours of work that might otherwise be lost during network interruptions.

For developers, Tmux facilitates efficient multitasking by enabling simultaneous views of code editors, build processes, and application outputs. System administrators benefit from monitoring multiple servers concurrently while executing commands across synchronized panes. Data scientists can run long computations in the background while continuing other work in separate panes.

Unlike similar tools such as Screen, Tmux offers more intuitive keybindings, better customization options, and a more active development community. Its lightweight nature means it consumes minimal system resources while delivering substantial productivity benefits.

Prerequisites for Installing Tmux

Before proceeding with Tmux installation, ensure your Linux system meets the necessary requirements. While Tmux is relatively lightweight, understanding these prerequisites will help avoid installation issues.

System Requirements:

  • Any modern Linux distribution (kernel 2.6 or newer)
  • Basic terminal access
  • Sufficient privileges (sudo or root access) for system-wide installation
  • Approximately 2-5 MB of disk space for the package and dependencies
  • RAM requirements are minimal (works well even on systems with limited memory)

Dependencies:

Tmux relies on two primary libraries:

  • libevent: A library for asynchronous event notification
  • ncurses: A library for text-based user interfaces

Most package managers will automatically handle these dependencies, but when compiling from source, you’ll need to install them manually.

To check if Tmux is already installed on your system, simply run:

tmux -V

If installed, this command will display the current version. Otherwise, you’ll see a “command not found” error, indicating installation is needed.

Installing Tmux on Debian-Based Distributions

Debian-based distributions, including Ubuntu, Linux Mint, and Pop!_OS, provide straightforward Tmux installation through the APT package manager.

Ubuntu/Debian Installation

Start by updating your package repositories to ensure you’re installing the latest available version:

sudo apt update

Then install Tmux with a simple command:

sudo apt install tmux

This command automatically resolves and installs all required dependencies along with Tmux. The installation typically completes within seconds, depending on your internet speed.

To verify successful installation, check the installed version:

tmux -V

You should see output similar to:

tmux 3.2a

The version number may vary depending on your distribution and its repositories.

If you need a specific version of Tmux not available in standard repositories, consider using Personal Package Archives (PPAs) on Ubuntu:

sudo add-apt-repository ppa:your-chosen-ppa
sudo apt update
sudo apt install tmux

Common installation issues on Debian-based systems typically involve package repository problems or dependency conflicts. If you encounter errors about “unmet dependencies,” try:

sudo apt --fix-broken install

Installing Tmux on RPM-Based Distributions

RPM-based distributions like RHEL, CentOS, and Fedora handle Tmux installation differently, using either the YUM or DNF package managers.

RHEL/CentOS Installation

On RHEL or CentOS systems, Tmux is available in the standard repositories, but you might need the EPEL (Extra Packages for Enterprise Linux) repository for the latest versions:

# Install EPEL repository if needed
sudo yum install epel-release

# Install Tmux
sudo yum install tmux

After installation completes, verify with:

tmux -V

If you encounter issues with missing dependencies, ensure the EPEL repository is properly configured:

sudo yum repolist

The output should include the EPEL repository among the enabled repositories.

Fedora Installation

Fedora uses the DNF package manager, which simplifies the installation process:

sudo dnf install tmux

DNF handles dependencies automatically and typically provides more recent versions of Tmux compared to RHEL/CentOS repositories.

Verify your installation:

tmux -V

For older Fedora versions still using YUM, the command structure remains the same, simply substituting yum for dnf.

Installing Tmux on Other Linux Distributions

Beyond Debian and RPM-based systems, Tmux is readily available on virtually all Linux distributions through their respective package managers.

Arch Linux

Arch Linux and derivatives like Manjaro provide the latest Tmux versions through the pacman package manager:

sudo pacman -S tmux

Arch’s rolling release model ensures you’re always getting the most recent stable version of Tmux without needing additional repositories.

OpenSUSE

On OpenSUSE systems, use the zypper package manager:

sudo zypper install tmux

After installation, verify with the standard version check:

tmux -V

Alpine Linux

Alpine Linux, known for its minimalist approach, offers Tmux through the APK package manager:

sudo apk add tmux

Alpine’s lightweight nature makes it particularly well-suited for Tmux, as both prioritize efficiency and minimal resource usage.

Installing Tmux from Source

While package managers provide convenience, compiling Tmux from source gives you access to the very latest features, bug fixes, and customization options.

When to compile from source:

  • When you need the latest Tmux version not yet available in repositories
  • When you want to apply custom patches or modifications
  • When your distribution doesn’t provide a Tmux package
  • When you need to install without root privileges (to your home directory)

Source Installation Steps:

  1. Install build dependencies:For Debian/Ubuntu:
    sudo apt install build-essential autoconf automake pkg-config libevent-dev libncurses-dev

    For RHEL/CentOS:

    sudo yum install gcc make autoconf automake pkg-config libevent-devel ncurses-devel
  2. Download the latest Tmux source:
    wget https://github.com/tmux/tmux/releases/download/3.3a/tmux-3.3a.tar.gz
  3. Extract the archive:
    tar -zxf tmux-3.3a.tar.gz
    cd tmux-3.3a
  4. Configure, compile, and install:
    ./configure
    make
    sudo make install

    For installation to your home directory without sudo:

    ./configure --prefix=$HOME/.local
    make
    make install
  5. Verify installation:
    tmux -V

Compiling from source provides the most control but requires more technical knowledge and time. The primary advantages include access to the latest features and the ability to customize the build process to your specific needs.

First Steps with Tmux

After successfully installing Tmux, it’s time to start exploring its capabilities. Starting Tmux is straightforward—simply type tmux in your terminal:

tmux

Upon launching Tmux for the first time, you’ll notice subtle changes to your terminal window. A green status bar appears at the bottom of the screen, displaying essential information:

  • Session name (default is numbered, starting from 0)
  • Window list with numbers and names
  • System information (hostname, time, date)

Understanding the prefix key concept is crucial for Tmux navigation. By default, Tmux uses the key combination Ctrl+b as its prefix. This prefix signals to Tmux that the next keystroke is a command rather than input for your shell.

To exit Tmux entirely, you can:

  1. Type exit within the shell
  2. Use the prefix followed by & (Ctrl+b, &) and confirm with ‘y’

If you want to detach from a session while leaving it running in the background, use:

Ctrl+b, d

To later reattach to this session:

tmux attach

Essential Tmux Commands

Mastering a few key commands will dramatically improve your Tmux experience. Here’s a breakdown of the most important ones, all preceded by the prefix (Ctrl+b by default):

Session Management

  • $ – Rename the current session
  • d – Detach from the current session
  • s – Select from available sessions
  • :new -s session-name – Create a new named session
  • :kill-session -t session-name – Destroy named session

Window Management

  • c – Create a new window
  • , – Rename the current window
  • n – Move to the next window
  • p – Move to the previous window
  • w – List all windows
  • & – Kill the current window

Pane Management

  • % – Split the current pane vertically
  • " – Split the current pane horizontally
  • o – Cycle through panes
  • q – Show pane numbers (type the number to select)
  • x – Kill the current pane
  • z – Toggle pane zoom (maximize/restore pane)
  • Arrow keys – Navigate between panes

Command Mode

Enter command mode with Ctrl+b, : to access additional commands not directly bound to keys. For example:

:set -g mouse on

This enables mouse support for the current session.

Learning these commands may seem daunting initially, but they become second nature with regular use. Consider creating a cheat sheet until the most common commands become muscle memory.

Working with Tmux Sessions

Tmux sessions are the highest level of organization within the Tmux hierarchy. Understanding how to effectively manage sessions allows you to organize your terminal work into logical groupings.

Creating a named session provides better organization than the default numbered sessions:

tmux new -s development

This creates and attaches to a session named “development,” perfect for organizing work by project or function.

To list all running sessions from outside Tmux:

tmux ls

The output displays session names, creation times, and the number of windows in each session.

Attaching to a specific session by name:

tmux attach -t development

The true power of sessions becomes apparent when working remotely. If your SSH connection drops while using Tmux, your session continues running on the server. Simply reconnect to SSH and reattach to your Tmux session to continue exactly where you left off—all processes, outputs, and window arrangements remain intact.

For collaborative work, Tmux sessions can be shared between multiple users. This requires both users to have access to the same system:

# First user creates the session
tmux new -s shared_session

# Second user attaches to the same session
tmux attach -t shared_session

Both users can now see and interact with the same terminal session simultaneously, making it ideal for pair programming or troubleshooting.

Managing Windows and Panes

Windows in Tmux function similarly to tabs in a modern browser, while panes subdivide these windows into multiple viewports. This hierarchical organization provides flexible terminal layouts.

Working with Windows

Create a new window with:

Ctrl+b, c

Windows are identified by numbers and optional names in the status bar. Rename the current window:

Ctrl+b, ,

Switch between windows using:

Ctrl+b, window_number

or

Ctrl+b, n (next)
Ctrl+b, p (previous)

Pane Management

Split the current window vertically:

Ctrl+b, %

Split horizontally:

Ctrl+b, "

Navigate between panes using:

Ctrl+b, arrow_key

Resize the current pane:

Ctrl+b, Ctrl+arrow_key

Practical pane layouts dramatically improve productivity. For instance, a development setup might include:

  • One pane for code editing
  • Another running the application server
  • A third for database access
  • A fourth displaying logs in real-time

For operations requiring identical commands across multiple servers, Tmux offers synchronized panes:

Ctrl+b, :
setw synchronize-panes on

With synchronization enabled, any command typed in one pane is automatically sent to all panes in the current window—perfect for bulk server administration.

Basic Tmux Configuration

While Tmux works well with default settings, customization can significantly enhance your experience. Tmux uses a configuration file located at ~/.tmux.conf for persistent customization.

If this file doesn’t exist, create it:

touch ~/.tmux.conf

A common customization is changing the prefix key from the default Ctrl+b to something more accessible like Ctrl+a:

# Set prefix to Ctrl+a
unbind C-b
set -g prefix C-a
bind C-a send-prefix

Enable mouse support for easier navigation:

set -g mouse on

Increase scrollback buffer size from the default 2000 lines:

set-option -g history-limit 5000

For a more visually appealing status bar:

# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green](#S) '
set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=white]%H:%M#[default]'

After making changes to the configuration file, load them into the current session with:

Ctrl+b, :
source-file ~/.tmux.conf

Alternatively, restart Tmux to apply changes to all new sessions.

Troubleshooting Common Installation Issues

Despite its relatively straightforward installation, you might encounter issues when setting up Tmux. Here are solutions to common problems:

Package Manager Errors

If you see “package not found” errors:

  • Ensure your package repositories are up-to-date
  • Check your distribution’s package name for Tmux (sometimes it’s “tmux”, sometimes “tmux-terminal”)
  • On older distributions, you might need additional repositories

For dependency issues:

# Debian/Ubuntu
sudo apt --fix-broken install

# RHEL/CentOS
sudo yum clean all
sudo yum update

Permission Problems

“Permission denied” errors during installation usually indicate insufficient privileges:

  • Use sudo for system-wide installation
  • For source installations without root access, use the --prefix=$HOME/.local option with configure

Terminal Compatibility Issues

If Tmux displays incorrectly or key bindings don’t work:

  • Ensure your TERM environment variable is properly set
  • Add to your .bashrc or .zshrc:
    export TERM=xterm-256color

Resource Limitations

On minimal systems, you might encounter resource constraints:

  • Free up memory by closing unnecessary applications
  • For extremely limited systems, consider lighter alternatives like screen or dvtm

For troubleshooting terminal size issues after attaching to a session:

Ctrl+b, :
refresh-client -S

Practical Usage Examples

Tmux truly shines when applied to real-world scenarios. Here are some practical setups that demonstrate its versatility:

Development Environment

Create a complete development environment with a single command:

tmux new-session -s dev -n editor \; \
  send-keys 'vim' C-m \; \
  split-window -v -p 20 \; \
  send-keys 'npm run dev' C-m \; \
  new-window -n server \; \
  send-keys 'ssh user@production' C-m \; \
  new-window -n database \; \
  send-keys 'mysql -u root' C-m \; \
  select-window -t 1 \;

This script creates:

  • A main window with Vim and a build process
  • A window for server management via SSH
  • A window for database operations
  • And automatically returns to the first window

Server Monitoring Setup

Monitor multiple system aspects simultaneously:

tmux new-session -s monitoring -n resources \; \
  send-keys 'htop' C-m \; \
  split-window -h \; \
  send-keys 'watch df -h' C-m \; \
  split-window -v \; \
  send-keys 'watch -n 1 "netstat -tuln | grep LISTEN"' C-m \; \
  new-window -n logs \; \
  send-keys 'sudo tail -f /var/log/syslog' C-m \; \
  split-window -h \; \
  send-keys 'sudo tail -f /var/log/auth.log' C-m \;

This creates a comprehensive monitoring dashboard showing system resources, disk usage, network ports, and live log files.

Long-Running Processes

For data processing or lengthy compilations, Tmux ensures continuity:

tmux new -s long-process
# Inside the session
nohup python3 big_data_processing.py &
# Detach with Ctrl+b, d

Later, check on the process:

tmux attach -t long-process

Even after network disconnections or days later, your process remains accessible and under your control.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button