Logo

Install tmux: A Comprehensive Guide With Practical Examples

Try this guide with our instant dedicated server for as low as 40 Euros

Whether you’re managing multiple projects, running parallel scripts, or simply trying to keep your workflow clutter-free, tmux unlocks a new level of efficiency and control.

tmux is a robust terminal multiplexer, enabling users to create, manage, and navigate between multiple terminal sessions all within a single window.

In this tutorial, we will discuss tmux and its use cases. We will start with an introduction to the tmux and then go into the installation.

Table Of Contents

  1. What is tmux?
  2. Key Features of tmux
  3. Advantages of tmux
  4. Disadvantages of tmux
  5. How to Install tmux
    1. Installation of tmux on Debian and Ubuntu Systems
    2. Install tmux on RedHat and CentOS
  6. How to Configure tmux
  7. tmux Commands
  8. Conclusion
  9. FAQs

What is tmux?

tmux is a free and open-source terminal multiplexer for Unix-based operating systems like Linux. It allows users to create multiple terminal sessions within a single window. 

It also allows users to open multiple terminal windows and switch between them, making it an invaluable resource for developers and system administrators to run several command-line programs simultaneously.

Key Features of tmux

Some of the key features of tmux are:

Multiple Panes

tmux split a single terminal window into multiple panes, each running a separate session. It is useful for monitoring different processes or running several commands simultaneously.

Session Management

tmux creates, detaches, and reattachs sessions, allowing users to leave tasks running in the background and attend later. This is particularly useful for long-running processes or remote server management.

Persistent Sessions

tmux sessions continue to run even if the terminal is closed or the network connection is lost. Users can reconnect to the same session from any location, ensuring uninterrupted workflow.

Customizable Layouts

tmux arranges panes and windows in various layouts to suit your workflow. You can resize, move, and organize them as needed.

Scripting and Automation

tmux can be scripted to automate repetitive tasks, enhancing productivity and reducing manual input.

Advantages of tmux

The following table summarizes the advantages of tmux.

advantages of tmux

Disadvantages of tmux

The following table summarizes the disadvantages of tmux.

Disadvantages of tmux

Now that you have an understanding of tmux, let us discuss how to install it. However, before that, let us take a quick look at the prerequisites. 

The Prerequisites 

Before diving into the installation, ensure you have the following.

  • A Linux-based system
  • A user account with sudo or administrative privilege.
  • Terminal or command line access

How to Install tmux

Installing tmux is a simple process, though the steps may differ slightly based on your operating system. 

To install tmux from the default repositories, use your system’s standard package manager and run the appropriate installation command.

Installation of tmux on Debian and Ubuntu Systems 

Update your system’s package repository to ensure your system has access to the latest software versions.

# sudo apt update

Next, download and install tmux from the official repositories.

# sudo apt install tmux

Install tmux on RedHat and CentOS

Installing tmux on RedHat and CentOS is similar to installing tmux on Debian and Ubuntu systems.

Update your system’s repository package and install tmux. 

# sudo yum update

# sudo yum install tmux

Install tmux on RedHat and CentOS

Now that you know how to install tmux, let us understand how to configure it to the user’s requirement.

How to Configure tmux

tmux offers a wide range of customization options to tailor the terminal experience. Some of the common configuration options are:

Configuration #1: Change tmux’s Activation Key

By default, tmux uses Ctrl+b as the prefix key to activate commands. You can change this to your desired key, such as Ctrl+a, by adding the following line to your ~/.tmux.conf file.

Open a text editor. We recommend Vim or Nano (here we use Nano). 

Add the following lines to the configuration file ~/.tmux.conf.

set-option -g prefix C-a

unbind C-b

bind C-a send-prefix

Save and exit the file.

You can now utilize Ctrl+a as the prefix key to activate commands.

Configuration #2: Change Keys to Split Panes

The default key bindings for splitting panes horizontally and vertically might not be ideal for everyone. Users can change them to suit their preferences.

For instance, to split the pane horizontally with the | key and vertically with the key, add the following lines to the configuration file (~/.tmux.conf).

bind | split-window -h

bind - split-window -v

Configuration #3: Change Status Bar Appearance

The status bar displays information like session name, window number, and pane details.

To change the appearance of the status bar, you can customize various options in tmux configuration file (~/.tmux.conf).

For instance, to change the status bar background color, add:

set -g status-bg colour235

set -g status-fg colour136

Change Status Bar Appearance

Configuration #4: Change Pane Numbering

By default, panes are numbered starting from 0. You can change this to start from 1 for a more intuitive experience.

To change pane numbering, add the following line to ~/.tmux.conf file.

set -g base-index 1

tmux Commands

Once the tmux package is installed, you can begin utilizing it by familiarizing yourself with key commands. Here are some of the essential tmux commands to streamline the terminal sessions.

Start New tmux Session

To start a new tmux login session, simply enter the below command in your server SSH session:

# tmux

Start a New Named Session

To start a new tmux session with a specific name, execute the following command:

# tmux new -s session_name

Split Pane tmux

To split the current tmux pane horizontally, enter:

Ctrl+b %

To split the current tmux pane vertically, use:

Ctrl+b "

Split Pane tmux

Exit tmux Pane

To close the current pane, enter:

exit

Navigate Between Panes

To navigate between panes, use the following key combinations.

To switch focus to the right pane, use:

Ctrl+b o

To navigate to the previous pane, enter:

Ctrl+b ;

Resize Panes

To resize the current pane, use these key combinations:

To resize the pane upward:

Ctrl+b Up Arrow

To resize the pane downward:

Ctrl+b Down Arrow

To resize the pane leftward:

Ctrl+b Left Arrow

To resize the pane rightward:

Ctrl+b Right Arrow

Zoom Into Pane

To toggle zoom mode for a magnified view of the current pane, use the following:

Ctrl+b z

Detach and Reattach

To detach from the current tmux session while keeping it active, enter:

Ctrl+b d

To resume a detached session by name, run:

# tmux attach -t session_name

List Active Sessions

To list all active tmux sessions, use Is command:

# tmux ls

tmux ls

Window Management

tmux allows users to manage multiple windows within a single session. The following section discusses various window management options. 

Rename Window

To rename the current window, use:

Ctrl+b ,

Switch Between Windows

To switch to the next window, enter:

Ctrl+b n

To switch to the previous window:

Ctrl+b p

Display List of Active Windows

To display a list of all windows in the current session, enter:

Ctrl+b w

Close a Window

To exit from the current window, enter:

exit

Conclusion

tmux stands out as a remarkably adaptable tool, enhancing productivity by efficiently managing multiple SSH sessions. 

Through mastering the commands and configurations detailed in this tutorial, you’ll embark on a journey toward tmux mastery.

FAQs

Q. What is tmux?

tmux is a powerful tool and terminal multiplexer that allows you to create, manage, and switch between multiple terminal windows within a single session. It helps you manage multiple terminal sessions and improve your productivity.

Q. How do I install tmux on Ubuntu?

Use the following commands to install tmux on Ubuntu:

sudo apt update and sudo apt install tmux

Q. How do I start a new tmux session?

To start a new tmux session, simply type tmux in your terminal. This will open a new session where you can create and manage multiple terminal windows.

Q. How can I split a tmux pane?

To split a pane horizontally, use Ctrl+b %. To split a pane vertically, use Ctrl+b “.

Q. How do I detach from a tmux session?

To detach from a tmux session without closing it, use Ctrl+b d. This allows you to disconnect from the session while keeping it running in the background.

Q. How do I reattach to a detached tmux session?

To reattach to a detached session, use tmux attach -t session_name. This command reconnects you to your previously detached session.

Q. How do I list all active tmux sessions?

Use the command tmux ls to list all active tmux sessions. This is useful for managing multiple sessions and ensuring you can easily switch between them.

Q. Can I customize tmux key bindings?

Yes, you can customize tmux key bindings by editing the ~/.tmux.conf configuration file. For example, you can change the prefix key from Ctrl+b to Ctrl+a.

Q. How can I use tmux with SSH connections?

tmux is very useful for managing multiple SSH connections. You can start a tmux SSH session on a remote machine via a single SSH connection, detach it, and reattach later, ensuring your work continues even if the SSH connection drops.

Q. What are some common tmux keyboard shortcuts?

Some common tmux keyboard shortcuts include:

Ctrl+b d to detach from a session.

Ctrl+b % to split a pane horizontally.

Ctrl+b ” to split a pane vertically.

Ctrl+b o to switch to the next pane.

Q. How do I create a new tmux window?

To create a new tmux window within the same session, use Ctrl+b c. Each window can contain multiple panes and run different commands.

Q. How do I switch between tmux windows?

To switch between tmux windows, use Ctrl+b n to move to the next window and Ctrl+b p to move to the previous window. Alternatively, you can use Ctrl+b w to list all windows and select one.

Try this guide with our instant dedicated server for as low as 40 Euros