How To

Install and Use tmux on Linux

tmux is a terminal multiplexer that lets you run multiple terminal sessions inside a single window. It keeps sessions alive even after you disconnect, which makes it essential for managing long-running processes on remote servers. The project is open source and actively maintained on GitHub.

Original content from computingforgeeks.com - post 1267

This guide covers how to install and use tmux on Linux – including session management, window and pane operations, copy mode, and configuration. All commands were tested on Ubuntu 24.04 with tmux, but the workflow applies to any Linux distribution.

Install and use tmux on Linux

Prerequisites

  • A Linux system (Ubuntu/Debian, Fedora/RHEL, Arch) or macOS
  • sudo or root access to install packages
  • A terminal emulator with UTF-8 support

Step 1: Install tmux on Linux

tmux is available in the default package repositories on all major distributions. Pick the command that matches your system.

On Ubuntu and Debian:

sudo apt update
sudo apt install -y tmux

On Fedora:

sudo dnf install -y tmux

On RHEL, Rocky Linux, and AlmaLinux (EPEL required on older releases):

sudo dnf install -y tmux

On Arch Linux:

sudo pacman -S tmux

On macOS using Homebrew:

brew install tmux

After installation, confirm tmux is available by checking the version:

tmux -V

The output shows the installed version number:

tmux 3.6a

Step 2: Start tmux and Understand Basic Concepts

tmux organizes work into three layers: sessions, windows, and panes. A session is a collection of windows that persists until you explicitly destroy it. Each session has one or more windows, which act like tabs. Each window can be split into multiple panes – independent terminal areas within the same window.

Start a new tmux session by running:

tmux

You are now inside a tmux session. Notice the green status bar at the bottom – it shows the session name, window list, and hostname. All tmux commands use a prefix key, which is Ctrl+b by default. You press Ctrl+b first, release it, then press the action key.

To detach from the session and return to your regular shell, press Ctrl+b then d. The session continues running in the background.

Step 3: tmux Session Management

Named sessions make it easy to organize different projects. Create a new detached session with a name:

tmux new-session -d -s myproject

This creates a session called myproject in the background. The -d flag starts it detached so you stay in your current shell.

Create a couple more sessions for different tasks:

tmux new-session -d -s monitoring
tmux new-session -d -s database

List all active sessions to see what is running:

tmux list-sessions

The output shows each session name, number of windows, and creation time:

database: 1 windows (created Sun Mar 22 00:35:51 2026)
monitoring: 1 windows (created Sun Mar 22 00:35:51 2026)
myproject: 1 windows (created Sun Mar 22 00:35:51 2026)

Attach to a specific session by name:

tmux attach -t myproject

While attached, switch to another session with Ctrl+b then s. This brings up an interactive session list where you can navigate with arrow keys and press Enter to select.

Rename the current session with Ctrl+b then $. Type the new name and press Enter.

Kill a session you no longer need from outside tmux:

tmux kill-session -t database

Kill all sessions except the one you are attached to:

tmux kill-server

Use kill-server with caution – it terminates every tmux session and all processes inside them.

Step 4: Window Management in tmux

Windows work like tabs within a session. Attach to a session first, then create windows for different tasks.

Attach to the myproject session and create named windows:

tmux attach -t myproject

Inside the session, create new windows with Ctrl+b then c. Rename a window with Ctrl+b then , – type the name and press Enter. Create three windows named editor, logs, and monitor.

You can also create named windows from the command line:

tmux new-window -t myproject -n editor
tmux new-window -t myproject -n logs
tmux new-window -t myproject -n monitor

List windows in the session to confirm they exist:

tmux list-windows -t myproject

The output shows each window with its index, name, dimensions, and layout:

0: bash* (1 panes) [205x50] [layout b5bf,205x50,0,0,0] @0 (active)
1: editor (1 panes) [205x50] [layout b5c0,205x50,0,0,3] @3
2: logs (1 panes) [205x50] [layout b5c1,205x50,0,0,4] @4
3: monitor (1 panes) [205x50] [layout b5c2,205x50,0,0,5] @5

Switch between windows with these shortcuts:

  • Ctrl+b then n – next window
  • Ctrl+b then p – previous window
  • Ctrl+b then 0-9 – jump to window by number
  • Ctrl+b then w – interactive window list

Close a window by typing exit in the shell or pressing Ctrl+d. You can also kill a specific window from outside:

tmux kill-window -t myproject:3

Step 5: Pane Management – Split, Navigate, and Resize

Panes split a single window into multiple terminal areas. This is one of the most useful tmux features – run a command in one pane while watching logs in another.

Split the current window horizontally (top and bottom):

Press Ctrl+b then "

Split the current pane vertically (left and right):

Press Ctrl+b then %

After splitting the window into three panes, list them to see the layout:

tmux list-panes

The output shows each pane with its index, dimensions, position, and active status:

0: [205x25] [history 0/50000 bytes; 0 0/0] %0
1: [102x24] [history 0/50000 bytes; 0 0/0] %1
2: [102x24] [history 0/50000 bytes; 0 0/0] %2 (active)

Navigate between panes using these shortcuts:

  • Ctrl+b then arrow keys – move to adjacent pane
  • Ctrl+b then o – cycle through panes
  • Ctrl+b then q – show pane numbers, then press the number to jump

Resize panes by holding Ctrl+b then pressing an arrow key repeatedly. For larger steps, use the command mode:

tmux resize-pane -D 10
tmux resize-pane -U 5
tmux resize-pane -L 10
tmux resize-pane -R 10

These commands resize the active pane down, up, left, and right by the specified number of cells.

Zoom a pane to full screen with Ctrl+b then z. Press the same combination again to restore it. This is useful when you need more space temporarily without closing other panes.

Close a pane with exit or Ctrl+d. To rearrange pane layouts, press Ctrl+b then Space to cycle through preset layouts (even-horizontal, even-vertical, main-horizontal, main-vertical, tiled).

Step 6: Copy Mode and Scrollback

By default, scrolling in tmux does not work like a regular terminal. You need to enter copy mode to scroll through output and copy text.

Enter copy mode with Ctrl+b then [. You are now in a vi-style navigation mode where you can:

  • Scroll up and down with arrow keys or Page Up/Page Down
  • Search forward with / and backward with ?
  • Start selection with Space, move to select text, then press Enter to copy
  • Paste the copied text with Ctrl+b then ]

Press q to exit copy mode without copying.

The default scrollback buffer holds 2000 lines. Increase it by adding this to your tmux configuration:

set -g history-limit 50000

If you prefer emacs-style key bindings in copy mode instead of vi, set:

set -g mode-keys emacs

Step 7: Customize tmux with .tmux.conf

tmux reads its configuration from ~/.tmux.conf at startup. Create this file to set your preferred options, key bindings, and appearance.

Create or edit the configuration file:

vi ~/.tmux.conf

Add the following practical configuration:

# Change prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Split panes with | and - (more intuitive than " and %)
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# Switch panes with Alt+arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Enable mouse support (resize panes, switch windows, scroll)
set -g mouse on

# Start window numbering from 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1

# Increase scrollback buffer
set -g history-limit 50000

# Reduce escape time (faster key response)
set -sg escape-time 10

# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display "Config reloaded"

# Status bar styling
set -g status-style 'bg=colour235 fg=colour136'
set -g status-left '#[fg=colour46][#S] '
set -g status-right '#[fg=colour166]%Y-%m-%d %H:%M'

# Active window highlight
setw -g window-status-current-style 'fg=colour166 bold'

After saving the file, reload the configuration without restarting tmux:

tmux source-file ~/.tmux.conf

The changes take effect immediately. If you used the config above, the prefix key is now Ctrl+a instead of Ctrl+b.

tmux Keyboard Shortcuts Reference

This table lists the default tmux key bindings. All shortcuts require pressing the prefix key (Ctrl+b) first, then the action key.

ShortcutAction
Ctrl+b dDetach from session
Ctrl+b sList and switch sessions
Ctrl+b $Rename current session
Ctrl+b cCreate new window
Ctrl+b ,Rename current window
Ctrl+b nNext window
Ctrl+b pPrevious window
Ctrl+b 0-9Switch to window by number
Ctrl+b wInteractive window list
Ctrl+b &Kill current window
Ctrl+b "Split pane horizontally
Ctrl+b %Split pane vertically
Ctrl+b arrowNavigate between panes
Ctrl+b oCycle through panes
Ctrl+b qShow pane numbers
Ctrl+b zToggle pane zoom (fullscreen)
Ctrl+b SpaceCycle pane layouts
Ctrl+b xKill current pane
Ctrl+b [Enter copy mode
Ctrl+b ]Paste from buffer
Ctrl+b :Enter command mode
Ctrl+b ?List all key bindings

Conclusion

tmux gives you persistent terminal sessions, multi-window workflows, and pane splitting – all from a single SSH connection. Once the key bindings become muscle memory, you will wonder how you worked without it. For long-running production tasks, always start work inside a tmux session so a network drop does not kill your process.

Related Articles

Terminal How To Enable Command Autosuggestions on Zsh Featured Manage VirtualBox VMs From Command Line using VboxManage Terminal Best SSH, Telnet and Serial Client Applications for Windows Systems Cheat Sheets Enable Bash Completion in Zsh on Linux

Leave a Comment

Press ESC to close