Installing Tmux on Linux

Tmux can be installed on Linux using the package manager specific to your distribution. Below are the installation commands for popular Linux distributions:

Distribution Command
Debian/Ubuntu sudo apt update && sudo apt install tmux
Fedora sudo dnf install tmux
CentOS/RHEL sudo yum install epel-release && sudo yum install tmux
Arch Linux sudo pacman -S tmux
openSUSE sudo zypper install tmux
Alpine Linux sudo apk add tmux

Installing Tmux on macOS

On macOS, Tmux can be easily installed using Homebrew, a popular package manager for macOS. First, ensure Homebrew is installed, and then run:

bash
1
brew install tmux

This command will download and install Tmux along with its dependencies.


Verifying the Installation

After installation, verify that Tmux is correctly installed by checking its version:

bash
1
tmux -V

If the installation was successful, this command will output the version number of Tmux.


Basic Usage

To start a new Tmux session, simply run:

bash
1
tmux

This will create a new session with a status bar at the bottom of the terminal window.

To detach from the current session (while keeping it running in the background), press Ctrl+b followed by d. You can reattach to the session later by running:

bash
1
tmux attach

To list all running Tmux sessions, use:

bash
1
tmux ls

Advanced Installation (From Source)

If you prefer to install Tmux from source, you can follow these steps:

  1. Install the necessary dependencies (e.g., libevent, ncurses, gcc, make, pkg-config).

  2. Download the latest Tmux source code from the official GitHub repository.

  3. Compile and install Tmux:

    bash
    1
    2
    3
    4
    tar -zxf tmux-*.tar.gz
    cd tmux-*/
    ./configure
    make && sudo make install

This method ensures you have the latest version of Tmux.


Common Issues and Solutions

  1. Dependencies Missing: Ensure you have libevent and ncurses installed. For example, on Debian-based systems, run:

    bash
    1
    sudo apt install libevent-dev libncurses-dev
  2. Static Build Issues: If you encounter issues with static builds, ensure you have the necessary static libraries installed (e.g., glibc-static on RHEL/CentOS).

  3. Running from ~/local: If you install Tmux locally, ensure LD_LIBRARY_PATH is set to point to the correct library paths.


Conclusion

Tmux is a versatile tool that can significantly improve your terminal workflow. By following the steps outlined in this guide, you can easily install Tmux on your system and start managing multiple terminal sessions efficiently. Whether you’re working on Linux or macOS, the installation process is straightforward and well-supported by package managers.

Happy coding!