Your Search Bar For Shrewd Tips

How To Install Tmux


How To Install Tmux

In today's command-line environment, productivity tools like tmux have become essential for developers, sysadmins, and power users. Tmux, short for Terminal Multiplexer, allows you to manage multiple terminal sessions within a single window, detach and reattach sessions, and keep processes running in the background even when you disconnect. If you're new to tmux or looking to set it up on your system, this comprehensive guide will walk you through the process of installing tmux on various operating systems, along with helpful tips to get you started.

Prerequisites Before Installing Tmux

Before you proceed with installing tmux, ensure that your system meets the following prerequisites:

  • A supported operating system (Linux, macOS, or Windows)
  • Access to a terminal or command prompt
  • Administrative or root privileges to install software
  • Basic knowledge of command-line operations

Installing Tmux on Linux

Many Linux distributions include tmux in their default repositories, making installation straightforward. The method varies depending on your Linux flavor.

Installing Tmux on Debian and Ubuntu

Follow these steps to install tmux on Debian-based systems like Ubuntu:

  1. Open your terminal.
  2. Update your package list to ensure you have the latest information:
    sudo apt update
  3. Install tmux using apt:
    sudo apt install tmux
  4. Verify the installation:
    tmux -V
    This should display the installed version of tmux.

Installing Tmux on CentOS, RHEL, and Fedora

For Red Hat-based distributions, use the following commands:

  1. Open your terminal.
  2. On CentOS/RHEL, install epel-release first:
    sudo yum install epel-release
  3. Then install tmux:
    sudo yum install tmux
    Or, for Fedora:
    sudo dnf install tmux
  4. Verify the installation:
    tmux -V

Installing Tmux from Source (Advanced)

If you want the latest version of tmux or need a custom build, compiling from source is an option. Here's how:

  1. Install dependencies:
    sudo apt install -y automake pcregrep pkg-config libevent-dev libncurses5-dev build-essential
  2. Download the latest tmux source code from the official GitHub releases:
    wget https://github.com/tmux/tmux/releases/download/3.3a/tmux-3.3a.tar.gz
  3. Extract the archive:
    tar -xzf tmux-3.3a.tar.gz
  4. Navigate into the directory:
    cd tmux-3.3a
  5. Compile and install:
    ./configure && make && sudo make install
  6. Verify the installation:
    tmux -V

Installing Tmux on macOS

On macOS, the easiest method is using a package manager like Homebrew. If you haven't installed Homebrew yet, install it from brew.sh.

Using Homebrew

  1. Open the Terminal app.
  2. Update Homebrew:
    brew update
  3. Install tmux:
    brew install tmux
  4. Verify the installation:
    tmux -V

Building Tmux from Source on macOS

If you prefer, you can compile tmux from source similarly to Linux. Ensure you have Xcode Command Line Tools installed:

xcode-select --install

Then follow the Linux source compilation steps above.

Installing Tmux on Windows

Windows users can run tmux through environments like Windows Subsystem for Linux (WSL), Cygwin, or Git Bash. Here, we'll focus on WSL, which provides a Linux environment within Windows.

Using Windows Subsystem for Linux (WSL)

  1. Enable WSL on your Windows machine by following Microsoft's official guide.
  2. Install your preferred Linux distribution from the Microsoft Store (e.g., Ubuntu).
  3. Open the WSL terminal.
  4. Update package lists:
    sudo apt update
  5. Install tmux:
    sudo apt install tmux
  6. Verify the installation:
    tmux -V

Alternatively, for native Windows use, you can install tmux via Cygwin or download precompiled binaries, but WSL is recommended for a full Linux experience.

Basic Tmux Usage and Configuration

Once tmux is installed, it's helpful to understand how to start using it and customize your environment.

Starting a Tmux Session

To initiate a new tmux session, simply run:

tmux

This opens a new tmux session with a single window.

Detaching and Reattaching Sessions

  • Detach from a session by pressing:
    Ctrl + b
    then release and press:
    d
  • Reattach to a session:
    tmux attach
    or if multiple sessions exist:
    tmux attach -t session_name

Creating and Navigating Windows and Panes

  • Create a new window:
    Ctrl + b
    then press
    c
  • Switch between windows:
    Ctrl + b
    then press the window number or
    n
    (next) /
    p
    (previous)
  • Create a new pane (split window):
    Ctrl + b
    then press
    "
    for a horizontal split or
    %
    for a vertical split.
  • Navigate between panes:
    Ctrl + b
    then use arrow keys or
    o
    to switch.

Customizing Tmux with a Configuration File

Enhance your tmux experience by creating a configuration file at ~/.tmux.conf. Here are some common settings:

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

# Enable mouse support
set -g mouse on

# Improve pane border appearance
setw -g window-status-current-fg green

After editing, reload the configuration within a tmux session by pressing:

Ctrl + b
then type:
:source ~/.tmux.conf

Conclusion

Installing and configuring tmux can significantly boost your productivity in the terminal, allowing you to run multiple tasks simultaneously, detach sessions to keep processes alive, and customize your workspace to suit your workflow. Whether you're using Linux, macOS, or Windows with WSL, the process is straightforward and well-supported. Once set up, tmux becomes an invaluable tool for managing complex command-line environments efficiently. Take the time to explore its features, customize your configuration, and integrate tmux into your daily workflow for a seamless command-line experience.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →