GeekDas
••22 min read•
GeekdasGeekdas

TMUX on Terminal: Install, Setup & Practical Guide Complete Beginner to Pro Guide

TMUX on Terminal: Install, Setup & Practical Guide Complete Beginner to Pro Guide

TMUX lets you split one terminal window into many shells, detach from them, and pick them up again later, even after an SSH connection drops. If you work in a terminal every day for development, server management or DevOps, it is one of the highest-return tools you can learn in an afternoon.

This guide takes you from zero to confident use. You will install TMUX on every major platform, learn sessions, windows and panes, build a practical ~/.tmux.conf, add plugins that restore your work after a reboot, and walk through real workflows such as long-running jobs over SSH and a one-command development layout. It ends with a cheat sheet, troubleshooting steps, common mistakes and a FAQ.

TL;DR: Get Started in 60 Seconds

If you only have a minute, these five commands cover the core idea of TMUX:

tmux new -s work      # start a named session called "work"
# press Ctrl+b then %  to split the screen into two panes
# press Ctrl+b then d  to detach (everything keeps running)
tmux ls               # list running sessions
tmux attach -t work   # come back exactly where you left off

The rest of this guide explains each step, why it works, and how to make TMUX fit the way you work.

What Is TMUX?

TMUX (short for Terminal Multiplexer) is a command-line program that runs several terminal sessions inside a single window and keeps them alive in the background. It is open source, written in C, and available on Linux, macOS, BSD and Windows (through WSL).

The key idea is its client-server design. When you run tmux, it starts a background server that owns your shells, and your terminal window becomes a client attached to that server. Close the window or lose the SSH connection and only the client disappears. The server, and every program running inside it, keeps going.

The Three Layers: Sessions, Windows and Panes

TMUX organizes everything into three nested layers. Understanding them makes every command easier to remember.

Server
└── Session   (a workspace, e.g. "backend")
    ├── Window 1  (like a browser tab, e.g. "editor")
    │   ├── Pane A  (a shell)
    │   └── Pane B  (another shell)
    └── Window 2  (e.g. "logs")
        └── Pane A

Layer

What it is

Typical use

Session

A complete workspace that you can detach from and reattach to

One per project or server

Window

A full-screen tab inside a session

Separate tasks such as editor, server, logs

Pane

A split section of a window running its own shell

Watching logs next to a running command

Who uses it: developers, sysadmins, DevOps and backend engineers, data scientists running long training jobs, and anyone who works on remote Linux servers over SSH.

Why Use TMUX?

TMUX solves a handful of everyday terminal problems that tabs and a plain SSH session cannot. Here are the situations where it pays off most.

  • Your SSH connection drops. Without TMUX, the running command dies with the connection. With TMUX, it keeps running and you reattach when you are back.

  • You run long jobs. Database migrations, backups, builds, model training and large file transfers can run for hours. Start them in TMUX, detach, and check later.

  • You juggle several services. Run an app server, a database shell and a log tail side by side in one screen instead of juggling windows.

  • You work on many projects. Keep one named session per project and switch between them in a second.

  • You pair program or teach. Two people can attach to the same session and watch the same terminal live.

  • You want a repeatable environment. A short script can rebuild your exact layout every morning.

It is also very light on resources. A typical session uses only a few megabytes of memory, which is why it is safe to leave running on small servers.

How to Install TMUX

TMUX is in the default package repositories of almost every Linux distribution and macOS, so installation is a single command. Pick your platform below.

Ubuntu and Debian (including WSL)

sudo apt update
sudo apt install tmux

CentOS, RHEL, Rocky Linux and AlmaLinux

sudo dnf install tmux      # RHEL/CentOS 8 and newer
sudo yum install tmux      # older releases

Fedora

sudo dnf install tmux

Arch Linux

sudo pacman -S tmux

Alpine Linux

sudo apk add tmux

macOS (Homebrew)

brew install tmux

Windows

TMUX does not run natively in Windows PowerShell or Command Prompt. Install Windows Subsystem for Linux (WSL), open an Ubuntu shell, and use the Ubuntu commands above.

Build from Source (Latest Version)

Distribution packages are sometimes a few releases behind. If you need a newer version, build it yourself. You need libevent, ncurses, a C compiler, make and autoconf installed first.

git clone https://github.com/tmux/tmux.git
cd tmux
sh autogen.sh
./configure
make
sudo make install

Verify the Installation

tmux -V

If TMUX is installed correctly you will see a version number such as tmux 3.4. Some options used later in this guide need version 3.2 or newer, and the guide marks them when that applies.

Your First TMUX Session

Type tmux and press Enter to start. You land in a new session with one window and one pane, and a green status bar appears at the bottom showing the session name, window list and clock.

The Prefix Key

Nearly every TMUX shortcut starts with the prefix key, which is Ctrl + b by default. Press and release the prefix, then press the next key. For example, Ctrl + b then c creates a new window. It is a two-step sequence, not a chord where you everything together.

To see every key binding at any time, press Ctrl + b then ?. Press q to close the list.

A 2-Minute Walkthrough

  1. Run tmux new -s practice to start a named session.

  2. Press Ctrl + b then % to split the window into left and right panes.

  3. Press Ctrl + b then the right or left arrow key to move between panes.

  4. Press Ctrl + b then c to open a second window. The status bar now lists windows 0 and 1.

  5. Press Ctrl + b then d to detach. You are back in your normal shell.

  6. Run tmux attach -t practice. Your panes and windows are exactly as you left them.

That loop of start, split, detach and reattach is 80% of daily TMUX use.

Managing Sessions

Sessions are what make TMUX persistent, so learn these commands first. Always give sessions names so you can tell them apart.

Task

Command or keys

Create a named session

tmux new -s myproject

Create a session in the background

tmux new -d -s myproject

List sessions

tmux ls

Attach to a session

tmux attach -t myproject (or tmux a -t myproject)

Attach to the most recent session

tmux attach

Detach from the current session

Ctrl + b then d

Switch between sessions

Ctrl + b then s (interactive list), ( previous, ) next

Rename the current session

Ctrl + b then $

Kill one session

tmux kill-session -t myproject

Kill every session and the server

tmux kill-server

A handy shortcut is tmux new -A -s main. It attaches to the session named main if it exists and creates it if not, so you can use one command every time.

When you detach, your session keeps running in the background. Programs inside it continue to execute, and output keeps scrolling into the session history until you return.

Working with Windows and Panes

Windows act like tabs and panes split a single window, and together they let you build any layout you need.

Windows

Task

Keys

Create a new window

Ctrl + b then c

Next window

Ctrl + b then n

Previous window

Ctrl + b then p

Jump to window by number

Ctrl + b then 0 to 9

Choose from a list of windows

Ctrl + b then w

Rename the current window

Ctrl + b then ,

Close the current window

Ctrl + b then & (asks to confirm)

Panes

TMUX names its splits from the direction of the dividing line, which confuses many beginners. The % key puts a vertical line down the middle, giving you left and right panes. The " key puts a horizontal line across, giving you top and bottom panes.

Task

Keys

Split into left and right panes

Ctrl + b then %

Split into top and bottom panes

Ctrl + b then "

Move to another pane

Ctrl + b then an arrow key

Cycle to the next pane

Ctrl + b then o

Show pane numbers, then jump

Ctrl + b then q then the number

Resize a pane

Press Ctrl + b, then hold Ctrl + arrow key (or use :resize-pane)

Zoom a pane to full screen and back

Ctrl + b then z

Swap panes

Ctrl + b then { or }

Cycle through preset layouts

Ctrl + b then Space

Turn a pane into its own window

Ctrl + b then !

Close the current pane

Ctrl + b then x, or type exit

The zoom shortcut, Ctrl + b then z, is worth memorizing. It temporarily maximizes the active pane so you can read a long log, then restores the layout when you press it again.

If resizing with the arrow keys is awkward on your keyboard or terminal, the custom bindings in the configuration section below give you a simpler way.

Scrolling, Searching and Copying Text (Copy Mode)

You cannot scroll a TMUX pane with your normal terminal scrollbar, because TMUX keeps its own scrollback buffer. To scroll, enter copy mode with Ctrl + b then [. Move with the arrow keys, Page Up and Page Down, and press q to leave.

If you enable the mouse (see the next section), you can also scroll with the mouse wheel, which switches into copy mode automatically.

Vi-Style Keys in Copy Mode

Add set -g mode-keys vi to your config to use vi keys inside copy mode.

Action

Key (vi mode)

Start selection

Space

Copy selection and exit

Enter

Search forward

/

Search backward

?

Next or previous match

n or N

Jump to top or bottom

g or G

Quit copy mode

q

After copying, press Ctrl + b then ] to paste the text into any pane. This uses TMUX's own buffer. To send text to your system clipboard, see the clipboard settings in the configuration section.

Tip: If you enabled the mouse and want to select text with your terminal's own selection, hold Shift (or Option on some macOS terminals) while dragging.

How to Customize TMUX with .tmux.conf

TMUX reads its settings from ~/.tmux.conf when the server starts, and a few well-chosen lines make it far more comfortable. Create the file (or open it if it exists) and start with the configuration below.

A Practical Starter Configuration

# ---------- General ----------
set -g mouse on                      # click panes, resize, scroll with the wheel
set -g history-limit 50000           # keep more scrollback
set -sg escape-time 10               # remove the delay after pressing Esc (helps Vim)
set -g base-index 1                  # number windows from 1, not 0
setw -g pane-base-index 1            # number panes from 1 as well
set -g renumber-windows on           # close the gap when a window is closed
set -g mode-keys vi                  # vi keys in copy mode
set -g set-clipboard on              # let tmux talk to the system clipboard (terminal permitting)

# ---------- Colors ----------
set -g default-terminal 'tmux-256color'
set -as terminal-features ',xterm-256color:RGB'   # true color (tmux 3.2+)

# ---------- Easier splits (new panes open in the current folder) ----------
bind | split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'
unbind %
unbind '"'
bind c new-window -c '#{pane_current_path}'

# ---------- Vim-style pane navigation ----------
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# ---------- Resize panes with Shift + Prefix ----------
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# ---------- Reload config with Prefix + r ----------
bind r source-file ~/.tmux.conf \; display-message 'Config reloaded!'

# ---------- Status bar ----------
set -g status-interval 5
set -g status-style 'bg=colour235,fg=colour250'
set -g status-left '#[bold] #S '
set -g status-right '%H:%M  %d-%b-%Y '
set -g window-status-current-style 'bold,fg=colour39'

What the Key Lines Do

  • mouse on lets you click to select panes and windows, drag borders to resize, and scroll with the wheel. It is the single best setting for beginners.

  • history-limit controls how many lines of output each pane remembers. The default of 2000 is small for build logs.

  • escape-time is the delay TMUX waits after Esc to see whether it begins a longer sequence. The default of 500 ms makes Vim feel sluggish.

  • base-index 1 makes window numbers match the key positions on your keyboard, so Ctrl + b then 1 jumps to the first window.

  • bind | and bind - give you memorable split keys. The -c '#{pane_current_path}' part opens the new pane in the directory you are already in.

  • bind -r makes a binding repeatable, so you can press H several times after one prefix.

Apply Your Changes

Reload the file inside TMUX with Ctrl + b then r (the binding above), or run this from any shell:

tmux source-file ~/.tmux.conf

Some settings only take effect when the server starts. If a change does not appear, save your work and run tmux kill-server, then start TMUX again.

Optional: Change the Prefix to Ctrl + a

Many people find Ctrl + a easier to reach than Ctrl + b. Add this block if you prefer it:

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Note that Ctrl + a normally jumps to the start of the line in a shell, so bind C-a send-prefix lets you still do that by pressing Ctrl + a twice.

Optional: Copy to the System Clipboard

Add the line that matches your system so that pressing y in copy mode copies to your clipboard:

# macOS
bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'pbcopy'

# Linux with X11
bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'

# Linux with Wayland
bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'wl-copy'

TMUX Plugins with TPM (Tmux Plugin Manager)

Plugins add features such as saving your layout across reboots, and TPM installs them for you. This matters because TMUX sessions live in memory: a server reboot ends every session unless you save them.

Step 1: Install TPM

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Step 2: Add Plugins to ~/.tmux.conf

Put this at the very bottom of your config file:

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

set -g @continuum-restore 'on'     # restore the last saved environment on start

run '~/.tmux/plugins/tpm/tpm'      # keep this as the last line

Step 3: Install the Plugins

Reload the config, then press Ctrl + b then Shift + i (capital I). TPM downloads each plugin and shows a confirmation when it finishes.

Plugins Worth Knowing

Plugin

What it does

tmux-sensible

A set of sane defaults that most people agree on

tmux-resurrect

Saves and restores sessions, windows, panes and working directories. Save with Ctrl + b then Ctrl + s, restore with Ctrl + b then Ctrl + r

tmux-continuum

Saves your environment automatically every 15 minutes and can restore it when TMUX starts

tmux-yank

Copies selected text to the system clipboard

Restoring recreates your windows, panes and the directories they were in, and it can relaunch a short list of common programs. It does not bring back the exact state of a running process, so a half-finished job still needs to be restarted.

Practical TMUX Examples

These four workflows show how TMUX is used in real work. Each one is something you can copy and run today.

Example 1: Run a Long Job over SSH Safely

This is the classic reason to use TMUX. A dropped connection no longer kills your task.

ssh user@server
tmux new -s backup
rsync -avh /data/ /mnt/backup/       # or a build, migration or training run
# press Ctrl + b then d to detach, then log out if you like

# later, from any machine:
ssh user@server
tmux attach -t backup

The job kept running the whole time, and you see all the output that appeared while you were away.

Example 2: A One-Command Development Layout

Save this script as dev.sh, make it executable with chmod +x dev.sh, and run it. It rebuilds the same workspace every time, or reattaches if it already exists.

#!/usr/bin/env bash
SESSION="dev"
PROJECT="$HOME/projects/myapp"

# Reattach if the session already exists
tmux has-session -t "$SESSION" 2>/dev/null && exec tmux attach -t "$SESSION"

# Window 1: editor
tmux new-session -d -s "$SESSION" -n editor -c "$PROJECT"
tmux send-keys -t "$SESSION:editor" 'nvim .' C-m

# Window 2: app server and a shell side by side
tmux new-window -t "$SESSION" -n server -c "$PROJECT"
tmux send-keys -t "$SESSION:server" 'npm run dev' C-m
tmux split-window -h -t "$SESSION:server" -c "$PROJECT"

# Window 3: logs and system monitor
tmux new-window -t "$SESSION" -n logs -c "$PROJECT"
tmux send-keys -t "$SESSION:logs" 'tail -f app.log' C-m
tmux split-window -v -t "$SESSION:logs"
tmux send-keys -t "$SESSION:logs" 'htop' C-m

tmux select-window -t "$SESSION:editor"
exec tmux attach -t "$SESSION"

Change the project path and commands to suit your stack. The same idea works for a Python virtual environment, a Docker Compose stack or a Rails app.

Example 3: A Quick Server Monitoring Dashboard

Open one window and split it into several panes, then start a different monitor in each:

  • htop for CPU and memory

  • watch -n 5 df -h for disk space

  • journalctl -f for live system logs

  • tail -f /var/log/nginx/error.log for web server errors

Press Ctrl + b then z to zoom into whichever pane needs a closer look, and press it again to return to the dashboard.

Example 4: Pair Programming and Teaching

Two people logged into the same machine as the same user can share one terminal. Person A runs tmux new -s pair. Person B connects over SSH and runs tmux attach -t pair. Both see and control the same screen in real time.

To let someone watch without typing, attach in read-only mode with tmux attach -t pair -r.

Only share sessions with people you trust. A shared TMUX session gives the other person full control of your shell, including anything your user account can do.

TMUX Cheat Sheet

Bookmark this table. Every key below is pressed after the prefix (Ctrl + b by default) unless the Command column shows a shell command.

Keys Pressed After the Prefix

Area

Keys

What it does

Session

d

Detach from the session

Session

s

Choose a session from a list

Session

$

Rename the session

Window

c

Create a window

Window

n / p

Next / previous window

Window

0-9

Jump to a window by number

Window

,

Rename the window

Window

&

Close the window

Pane

%

Split into left and right panes

Pane

"

Split into top and bottom panes

Pane

Arrow keys

Move between panes

Pane

z

Zoom or unzoom the pane

Pane

x

Close the pane

Pane

Space

Cycle through layouts

Mode

[

Enter copy mode (scroll and select)

Mode

]

Paste the copied text

Mode

:

Open the TMUX command prompt

Help

?

List all key bindings

Help

t

Show a clock in the pane

Shell Commands

Command

What it does

tmux new -s name

Start a named session

tmux new -A -s name

Attach to the session, or create it if missing

tmux ls

List sessions

tmux attach -t name

Attach to a session

tmux attach -t name -r

Attach in read-only mode

tmux rename-session -t old new

Rename a session

tmux kill-session -t name

Kill one session

tmux kill-server

Kill the server and all sessions

tmux send-keys -t name 'cmd' C-m

Type a command into a pane and press Enter

tmux capture-pane -p -t name

Print the visible text of a pane

tmux source-file ~/.tmux.conf

Reload your configuration

tmux list-keys

Print every key binding

The send-keys command is what makes TMUX scriptable, and it is how the development layout script in the examples section works.

Troubleshooting Common TMUX Problems

Most TMUX problems fall into a handful of patterns. Find your symptom in the table, then read the fix below it.

Symptom

Likely cause

Quick fix

no server running on /tmp/tmux-...

No session is running

Start one with tmux new -s name

sessions should be nested with care, unset $TMUX to force

You ran tmux inside TMUX

Detach first, or use tmux new -s name from a plain shell

duplicate session: name

A session with that name exists

Attach with tmux attach -t name

open terminal failed: missing or unsuitable terminal

The TERM value is not known on this machine

Set TERM=xterm-256color, or install ncurses-term

Colors look wrong or washed out

default-terminal is not set

Add set -g default-terminal 'tmux-256color' and restart the server

Vim feels slow after pressing Esc

High escape-time

Add set -sg escape-time 10

Config changes do not apply

The config was not reloaded

Run tmux source-file ~/.tmux.conf, or tmux kill-server and start again

Mouse scroll does nothing

Mouse mode is off

Add set -g mouse on

Cannot select text with the mouse

TMUX is capturing the mouse

Hold Shift (or Option on macOS) while dragging

Sessions disappeared after a reboot

Sessions live in memory

Use tmux-resurrect and tmux-continuum

Using TMUX Inside TMUX (Nested Sessions)

If you SSH from a local TMUX session into a server that also runs TMUX, your prefix keys go to the outer session. To send a command to the inner session, press the prefix twice. For example, Ctrl + b Ctrl + b then c opens a window in the inner session. Many people avoid the confusion by running TMUX only on the remote machine.

Check Your Version

When an option is rejected with unknown option or invalid option, your TMUX is probably older than the guide you are following. Run tmux -V, then upgrade through your package manager or build from source.

Common TMUX Mistakes (and How to Avoid Them)

  1. Forgetting the prefix key. Beginners often press c or % on its own. Always press Ctrl + b first, release it, then press the command key.

  2. Typing exit when you meant to detach. exit closes the pane, and closing the last pane ends the session and the programs in it. Use Ctrl + b then d to leave a job running.

  3. Not naming sessions. A plain tmux creates sessions called 0, 1, 2, which are hard to tell apart. Use tmux new -s project-name.

  4. Running kill-server casually. It ends every session and every program inside them. Prefer kill-session -t name unless you really want a clean slate.

  5. Starting TMUX inside TMUX. This leads to the nested-session error and confusing key presses. Check with echo $TMUX before starting a new one.

  6. Expecting sessions to survive a reboot. They live in memory. Use tmux-resurrect and tmux-continuum if you need that.

  7. Editing the config and not reloading it. Changes apply only after source-file, or after the server restarts for some options.

  8. Staying on the defaults. The default setup is minimal. Mouse support, sensible splits and a readable status bar make the first week much more pleasant.

Best Practices

  • Keep one session per project and name it after the project.

  • Name windows by task, such as editor, server and logs.

  • Put your ~/.tmux.conf in version control so your setup follows you from machine to machine.

  • Use a script (like the one above) for any layout you rebuild more than twice.

  • Learn a few shortcuts well, such as detach, split, zoom and copy mode, before collecting dozens.

  • Remember that nohup and disown can also keep a single command alive, but they cannot give you an interactive terminal to return to the way TMUX does.

Benefits of Using TMUX

  1. Session persistence. Your processes keep running after you log out or lose your connection.

  2. Fewer windows to juggle. Panes and windows keep related shells together in one terminal.

  3. A better SSH workflow. Remote work becomes safe, because a flaky network no longer costs you work.

  4. Lightweight and fast. It uses very little memory and works over slow connections.

  5. Repeatable and scriptable. A short script recreates your whole workspace on demand.

  6. Works everywhere. The same keys behave the same on a laptop, a cloud server and a Raspberry Pi.

TMUX vs GNU Screen

GNU Screen is the older terminal multiplexer and is still available on many systems. Both tools keep sessions alive after you disconnect. TMUX is generally preferred for new setups because of its cleaner configuration and scripting.

Feature

TMUX

GNU Screen

Persistent, detachable sessions

Yes

Yes

Split panes

Yes, easy to arrange and resize

Yes, more limited

Configuration and scripting

Consistent commands, easy to script

Older, less consistent syntax

Mouse support

Built in

Limited

Status bar customization

Extensive

Basic

Plugin ecosystem

Large (TPM)

Small

Serial device connections

No

Yes (screen /dev/ttyUSB0 9600)

Often preinstalled

Sometimes

Sometimes, on older systems

Choose TMUX unless you need Screen's built-in serial terminal or are stuck on a machine where only Screen is installed.

Conclusion

TMUX turns a single terminal into a persistent, organized workspace that survives disconnects, and it takes only a few minutes to start getting value from it. Its three layers, sessions, windows and panes, cover almost every workflow you will meet on local machines and remote servers.

Here is a sensible path to follow:

  1. Install TMUX and practice the start, split, detach and reattach loop for a few days.

  2. Add the starter configuration so the mouse, splits and status bar work the way you expect.

  3. Install TPM with tmux-resurrect and tmux-continuum so reboots stop costing you your layout.

  4. Write a small script for the workspace you rebuild most often.

If you work on Linux servers or remote machines regularly, a week of daily use is usually enough to make TMUX a habit you will not want to give up.

Was this article helpful?

Comments

Leave a comment

Loading comments...

Frequently Asked Questions

What is TMUX used for?
TMUX is used to manage multiple terminal sessions inside a single window. It allows splitting panes, detaching sessions, and running long processes safely.
How do I start and stop TMUX?
Start TMUX with: tmux
Does TMUX keep processes running after logout?
Yes. TMUX allows you to detach from a session and reattach later, keeping all processes running in the background.
What is the difference between TMUX and Screen?
TMUX is more modern, actively maintained, and offers better customization compared to GNU Screen.
How do I vertical split the screen in TMUX?
Ctrl + b then %
How do I horizontal split the screen in TMUX?
Ctrl + b then "
How do I reattach to a TMUX session?
List sessions: `tmux ls` Attach: `tmux attach -t session-name`
Is TMUX good for remote servers?
Yes. TMUX is widely used on remote Linux servers because it keeps sessions alive after SSH disconnects.

Related Articles