Quick Guide to Install tmux on Ubuntu & CentOS

Install tmux on Ubuntu & CentOS

tmux is a terminal multiplexer that allows you to manage multiple terminal sessions within a single window.

This is particularly useful for tasks like running long-running processes, managing multiple servers, or working on multiple projects simultaneously.

On Ubuntu and CentOS, tmux is widely used for its ability to create and organize multiple terminal environments, enhancing productivity and workflow efficiency.

tmux has an easy installation on Linux:

  • On Ubuntu: sudo apt-get install tmux
  • On CentOS: sudo yum install tmux

To learn how to start using and configuring tmux on Ubuntu and CentOS, follow this tutorial.

Prerequisites to Install tmux on Linux Ubuntu & CentOS

To Install tmux on Ubuntu & CentOS, your machine needs to meet all the below specifications:

  • A Linux VPS running a compatible Linux distribution (e.g., Ubuntu, Debian, CentOS).
  • A non-root user with sudo privileges.
  • Access to the Terminal /Command line.

How to Install tmux on Linux

Let’s go through this guide to learn How to install tmux Ubuntu and install tmux on Centos​.

On Ubuntu/Debian:

sudo apt-get update
sudo apt-get install tmux

This would update your Package lists and finish Ubuntu install tmux.

On CentOS:

sudo yum update
sudo yum install tmux

tmux installation on CentOS must be completed by now.

Finally, run the command below to verify installation for Ubuntu & CentOS:

tmux -V

Terminal Multiplexer Commands

While a session can have multiple windows, a window can have multiple panes, and each pane is part of a window within a session.

Here’s the explanation:

Sessions

  • A session is the top-level container in tmux. It’s a collection of windows.
  • You can create multiple sessions and switch between them.
  • Each session has its independant environment and configuration.

Windows

  • A window is a single terminal instance within a session.
  • Each window has its own command history, buffers, and configuration.
  • You can create multiple windows within a session and switch between them.

Panes

  • A pane is a split view within a window.
  • You can split a window into multiple panes to work on different tasks simultaneously.
  • Each pane has its own command history and input/output.

Most tmux Commands Usages on Ubuntu & CentOS [Manage session, window, pane]

Once you finish the tmux installation on your target distribution, you are ready to start tmux on Linux.

Here are some of the main activities you would need to start using tmux on Linux:

Start tmux on Linux

  • To start using tmux on Ubuntu & CentOS, run the following command:
tmux
  • Run the command below to create a new tmux session and attach your current terminal to it:
tmux new-session

Detaching from a tmux Session

  • To temporarily step away from your tmux session without losing your work, use:
Ctrl-b d

Reattaching to a Detached Session

  • To return to a previously detached session, run:
tmux attach

Creating a New Named Session

  • To start a new tmux session with a specific name, type:
tmux new -s <session_name>

Attaching to a Named Session

  • Use the following command to reconnect to a named session:
tmux attach -t <session_name>

Listing Active Sessions

  • To view all running tmux sessions, run:
tmux ls

Renaming a Session

  • Run the command below to change the name of an active session:
Ctrl-b $ <new_name>

Switching Between Sessions

  • To quickly switch between active sessions, run:
Ctrl-b s

Getting Help

  • To view the tmux help screen and learn more about its commands and options, run:
Ctrl-b ?

Creating a New Window

  • To open a new window within your current session, run:
Ctrl-b c

Renaming a Window

  • To rename a window, run:
Ctrl-b , <new_name>

Destroying a Window

  • To close a tmux window, run:
Ctrl-b x

Switching Between Windows

  • Use the command below to navigate between windows, run:
Ctrl-b [0-9]  # Switch to a specific window
Ctrl-b Arrow keys  # Cycle through windows
  • Next window: Ctrl-b + n
  • Previous window: Ctrl-b + p

Viewing a List of Windows

  • The command below displays a list of a window:
Ctrl-b w

Splitting Windows

  • Run the command below to divide a window horizontally or vertically:
Ctrl-b %  # Horizontal split
Ctrl-b "  # Vertical split

Splitting Panes

  • Tmux offers flexibility in dividing your screen into multiple panes for efficient multitasking:

Horizontal Split:

Ctrl-b "

Vertical Split:

Ctrl-b %

Moving Between Panes

  • To Navigating Panes, consider:
  • Cycle through panes: Ctrl-b + arrow keys
  • Jump to a specific pane: Ctrl-b + [pane number]

Resizing Pane

  • Enter resize mode: Ctrl-b + :
  • Move the boundary line:
  • Downward: resize-pane -D
  • Upward: resize-pane -U
  • Right: resize-pane -R
  • Left: resize-pane -L
  • Specify a specific movement: resize-pane -D 10 (moves the boundary line down 10 cells)

Zooming In and Out of a Pane

  • To zoom into a pane:
  1. Enter command mode: Press Ctrl-b :.
  2. Execute the zoom command: Type resize-pane -Z and press Enter.
  • To zoom out of a pane and return to its previous size:
  1. Enter command mode: Press Ctrl-b :.
  2. Execute the zoom command: Type resize-pane -Z and press Enter again.

Session, Pane, and Window Commands

Let’s have a glance at what you reviewed above:

CommandDescriptionExample
Sessions
tmux new-sessionCreates a new tmux session.tmux new-session -s my_session
tmux new-windowCreates a new window within the current session.tmux new-window -n new_window
tmux select-window -t Switches to the specified window.tmux select-window -t 2
tmux detachDetaches the current session from the terminal.tmux detach
tmux attachAttaches to a detached session.tmux attach -t my_session
tmux lsLists all active sessions.tmux ls
tmux rename-session Renames the current session.tmux rename-session my_new_session
tmux kill-sessionKills the current session.tmux kill-session -t my_session
Panes
tmux split-windowSplits the current window into two panes.tmux split-window -h
tmux split-window -hSplits the current window horizontally.tmux split-window -h
tmux split-window -vSplits the current window vertically.tmux split-window -v
tmux select-pane -t Switches to the specified pane.tmux select-pane -t 2
tmux kill-paneKills the current pane.tmux kill-pane
tmux resize-pane -DResizes the current pane downward.tmux resize-pane -D 10
tmux resize-pane -UResizes the current pane upward.tmux resize-pane -U 5
tmux resize-pane -RResizes the current pane to the right.tmux resize-pane -R 20
tmux resize-pane -LResizes the current pane to the left.tmux resize-pane -L 15
tmux zoom-paneZooms in or out of the current pane.tmux zoom-pane
Other
tmux list-windowsLists all windows in the current session.tmux list-windows
tmux send-keys Sends text to the current pane.tmux send-keys "Hello, world!"
tmux paste-bufferPastes the contents of the clipboard into the current pane.tmux paste-buffer
tmux show-bufferDisplays the contents of the clipboard.tmux show-buffer
tmux set-optionSets a tmux option.tmux set-option -g status-keys ":%k"
tmux show-optionsShows all current tmux options.tmux show-options

Steps to Use and Configure tmux on Linux

To customize tmux’s behavior on Ubuntu and CentOS, you can edit its configuration file.

1. Creating and Editing the Configuration File

  • Single-user configuration: Create a file named .tmux.conf in your home directory (~/.tmux.conf).
  • System-wide configuration: Create a file named tmux.conf in the system directory (/etc/tmux.conf).

Example:

sudo nano /etc/tmux.conf

2. Changing the Activation Key

  • Default: Ctrl-b
  • Change to Ctrl-a:

Example:

unbind C-b
set -g prefix C-a

3. Changing Split Pane Keys

  • Default: Ctrl-b % (horizontal), Ctrl-b " (vertical)
  • Change to Ctrl-b h and Ctrl-b v:

Example:

unbind %
bind h split-window -h
unbind '
bind v split-window -v

4. Changing Status Bar Appearance

  • Set colors:
set -g status-bg blue
set -g status-fg black
  • Highlight and display activity:
setw -g monitor-activity on
setw -g visual-activity on

5. Changing Pane Numbering

  • Start numbering at 1:
set -g base-index 1
set -g pane-base-index 1

Note: Remember to save your changes and restart any active tmux sessions for them to take effect.

Benefits of using tmux

  • Enhanced productivity: Efficiently manage multiple tasks simultaneously.
  • Improved workflow: Organize and streamline your terminal-based activities.
  • Simplified server management: Easily monitor and control multiple servers.
  • Customizable environment: Tailor tmux to your specific needs and preferences.

What is tmux used for?

Tmux is a terminal multiplexer that allows you to manage multiple terminal sessions within a single window.

It’s particularly useful for tasks like running long-running processes, managing multiple servers, or working on multiple projects simultaneously.

Can I customize tmux’s behavior?

Yes, you can customize tmux’s behavior by editing the ~/.tmux.conf file. This file allows you to change the prefix key, set default window and pane sizes, and enable various plugins.

How do I send text to a specific pane?

Use the tmux send-keys command followed by the text you want to send. For example, tmux send-keys "ls".

What are some popular tmux plugins?

Some popular tmux plugins include:

  • tmux-plugins: A collection of various plugins for tmux.
  • tmuxinator: A tool for managing multiple tmux sessions.
  • tmux-powerline: Provides a fancy status line for tmux

Can I run tmux commands from a script?

Yes, you can run tmux commands from a script. For example, you could create a script to automatically start a tmux session with specific windows and panes.

Why Tmux is not starting?

To troubleshoot tmux start, consider:

  • Check installation: Ensure tmux is installed correctly using tmux -V.
  • Permissions: Verify that you have the necessary permissions to run tmux.
  • Configuration: Inspect the ~/.tmux.conf file for any errors or conflicting settings.

Why I cannot detach from a tmux session?

To solve this issue, check for:

  • Prefix key: Verify that you’re using the correct prefix key (usually Ctrl-b).
  • Configuration: Check the ~/.tmux.conf file for any settings that might be interfering with detachment.

Why my tmux session is crashing?

To find a good solution to this issue, consider:

  • Configuration: Check the ~/.tmux.conf file for any invalid settings or plugins that might be causing instability.
  • Plugins: Temporarily disable any third-party plugins to isolate the issue.
  • System resources: Ensure your system has sufficient resources (CPU, memory) to run tmux.

How to find my detached session?

  1. Session name: If you gave your session a name, use tmux attach -t <session_name> to reattach.
  2. List sessions: Use tmux ls to list all active sessions.

Conclusion

In this article, we have explored the installation, configuration, and usage of tmux, a powerful terminal multiplexer.

We have covered essential concepts like sessions, windows, and panes, along with practical commands for managing them.

This guide helps you to understand the core concepts of sessions, windows, and panes to effectively organize and control your terminal environment, enhancing your productivity and efficiency.

Leave a Reply

Your email address will not be published. Required fields are marked.