Install tmux on Ubuntu 24.04

Install tmux on Ubuntu 24.04

The tmux is a terminal multiplexer that allows users to manage multiple terminal sessions within a single window. It enables you to split the terminal into multiple panes, run several commands simultaneously, and easily switch between them. With features like session persistence, you can detach from a session, keep processes running in the background, and later reattach, even if the terminal session is disconnected. This tutorial explains how to install tmux on Ubuntu 24.04.

Install tmux

Verify that the package lists are updated:

sudo apt update

Run the following command to install tmux:

sudo apt install -y tmux

After installation, you can verify the tmux version using the following command:

tmux -V

Testing tmux

To use tmux, you can start a new session in the background with the command. Here's the basic usage:

tmux new-session -d -s session_name 'myprog arg1 arg2'
  • new-session - starts a new tmux session.
  • -d - runs the tmux session detached, meaning it will run in the background without attaching to the terminal.
  • -s session_name - specifies the name of the new tmux session.
  • 'myprog arg1 arg2' - specifies the command to run.

For example:

tmux new-session -d -s test 'for i in {1..3}; do echo "Hello world"; sleep 2; done > log.txt'

This will create a detached tmux session named test that executes the command in the background. It outputs "Hello world" three times with a 2-second delay between each, and logs the output to a file.

Uninstall tmux

To fully uninstall tmux along with its dependencies, execute the following command:

sudo apt purge --autoremove -y tmux

Leave a Comment

Cancel reply

Your email address will not be published.