How to Install and Use TMUX on Ubuntu
It’s imperative that you know how to install and manage TMUX if you want to get all the benefits you can from using the Linux Command-Line Interface. The package installation is a two-step process that is easy to complete. In this article, you’ll learn everything you need to start using TMUX effectively, from scratch.
What Is TMUX and Why It’s Useful
TMUX allows users to switch between multiple programs in one terminal. Users can detach and reattach the multiple programs to different terminal sections. In essence, TMUX is a terminal multiplexer that allows users to open multiple programs in a session. Each window will occupy the whole screen but can be split into rectangular panes.
TMUX sessions are persistent. The running programs continue to run even if you are disconnected, and of course, all the commands start with a prefix. TMUX takes advantage of the client-server model allowing you to attach different terminals to a TMUX session. Users can run multiple terminals concurrently in a single TMUX session without the need to spawn a new actual terminal session.
Sudden disconnection of the cloud server doesn’t kill the running processes in the TMUX session. TMUX has a window-pane mentality making it run more than one terminal on one screen. The benefits of having the client-server model and the window-pane mentality is useful in understanding TMUX.
How to Install TMUX on Ubuntu
Installing TMUX on Ubuntu is super easy as long as you follow the instructions properly. All you have to do is copy and paste the commands below.
Remember, if you’re running a VPS server and your machine uses Microsoft Windows, you’ll need to use a client like PuTTY to start an SSH connection with your server. If you’re running OS X, simply open a terminal window and connect to the VPS server.
The first thing you should do is checking your Ubuntu version since if you’re running an older version, you might run into issues.
Afterward, run the command:
sudo apt-get update
Which should be followed by:
sudo apt-get install tmux
The first step simply updates your repositories and ensures you have the latest TMUX package information. The second step installs the TMUX package itself along with its dependencies.
How to Use TMUX on Ubuntu
With TMUX you can run multiple command prompts simultaneously in a single TMUX session. The terminal multiplexer is equivalent to the graphical window manager. It uses a client-server model to get persistent connections.
Basically, you can begin to start a session from your computer and run several programs. Afterward, you can connect back to that session from another computer. When reconnecting to the session, you can start from where you left and find the same programs to still be running without interruption.
Let’s learn some basic TMUX terminology before we start:
● Pane – this is a terminal prompt.
● Window – a window that holds multiple terminals or panes in one screen.
● Session – consists of multiple windows.
Starting to Work with TMUX
Start a new TMUX session by entering
tmux new-s start
There is a bar on the screen with the session name “start” in brackets. Clicking on the link means you have started a new session and a default window is opened holding one terminal. Creating the terminal automatically logs you with your user account.
You can make maneuvers in TMUX once inside your session. Simply use the prefix key to trigger your commands to tell TMUX what to do. The default prefix key CTRL+b applies. For instance, if you want to tell the TMUX to split your screen into two vertical sessions to create a new terminal, first hit CTRL+b, then %.
Creating multiple terminals is easy. After creating an additional terminal by splitting the current pane by using CTRL+b, %, you can split your current terminal into two horizontal sections by simply keying in CTRL+b, “. Besides, you can rotate or cycle through the three terminals by using CTRL+b, o.
Users can create multiple windows in the same session they are working in by hitting CTRL+b, c. After hitting enter, you see a new blank terminal. You can proceed to split the resultant terminal into two horizontal panes by hitting CTRL+b, “. Create your third window by hitting CTRL+b, c. Issue the command tmux list-windows and press enter to confirm the opening of three windows.
Besides, you can use CTRL+b, n if you want to cycle through your created three windows.
Users can detach or reattach from or to a session by following simple instructions. Use CTRL+b, d to detach. This only applies to the “start” session you created earlier.
To reconnect back to your start session use tmux attach -t start. To cycle between the created windows, use CTRL+b, n. When you are using a different computer simple SSH into your server. Log in and issue the tmux attach -t start command. It connects you directly to your start session and all your three windows are intact and running without any disruption or disconnection.
Must-Know TMUX Commands
Now that you know the basic principle of TMUX, we can list off the must-know commands you’ll be using on a daily basis:
CTRL+b, then c – creates a new window.
CTRL+b, then, – renames a window.
CTRL+b, then n – cycles to next window.
CTRL+b, then p – cycles to previous window.
CTRL+b, then & – kills the current window.
CTRL+b, then % – splits the current pane into two vertically.
CTRL+b, then ” – divides the current pane horizontally.
CTRL+b, then o – switches to the next pane.
CTRL+b, then q – shows pane numbers (type # to switch to a particular pane.)
CTRL+b, then d – detaches from the current session.
CTRL+b, then? – lists all key bindings.
Other Important TMUX Commands
Finally, let’s cover some commands that you should know to get the most out of using TMUX:
tmux list-sessions – to list all existing TMUX sessions.
tmux new -s session-name – to create a new TMUX session named session-name.
tmux attach -t session-name – to connect to an existing TMUX session named session-name.
tmux switch -t session-name – to switch to existing TMUX session named session-name.
TMUX is similar to a graphical windows manager but only used with a command-line interface. It can be a great help to anyone who regularly performs tasks in a terminal environment. It boosts productivity significantly and works like tabs for browsers. We hope this tutorial helps you improve your workflow. Good luck.