visit
A common use-case for tmux is on a remote server where you have a common layout that you always use, and want a way to quickly jump into and out of. An example would be if you’re connecting through a jump server and have other remote SSH sessions you would like to be connected to simultaneously. Similarly, if you have to hop into Vim, you can use tmux to give you access to your shell or a REPL in the same terminal window for a IDE-like experience.
This guide will go through the installation and basic usage of tmux to get you up and running. Alternatively, you can just skip all the reading and go straight to the need-to-know commands under the Summary of Primary Commands section.
This guide will focus on MacOS and Ubuntu. If you are on CentOS or Amazon Linux, you can use yum
in place of apt-get
.
1. If you don’t have Homebrew installed yet, open either Terminal or and paste the below command:
/usr/bin/ruby -e "$(curl -fsSL //raw.githubusercontent.com/Homebrew/install/master/install)"
2. Once Homebrew is installed, you can use brew
to install tmux:
3. Confirm that it installed by checking the version (note the uppercase _V_
):
Installation for Ubuntu is similar to Mac, except that we will be using the apt-get
package manager that comes pre-installed. Note that we will have to run apt-get
as sudo
. This is because a user account won’t have enough privileges to install tmux, so sudo
will allow us to install it as superuser.
1. Update apt-get
to make sure we are on the latest and greatest:
2. Install tmux:
sudo apt-get install tmux3. Confirm that it installed by checking the version:
tmux -Vtmux is based around sessions. To start a new session in tmux, simply type tmux new
in your terminal. Once you are in tmux, the only thing that will be visibly different is the ever-present green bar at the bottom (see Getting Fancy with Custom Themes section for customization options).
Default view after starting new session
To get out, you can type exit
if you’re in a single pane, and you’ll return from whence you came.
An important note is that exit
is not the only way to get out, and usually not the best way. For that we have detach
. However before we get to that, we first have to cover the prefix…
All commands in tmux require the prefix shortcut, which by default is ctrl+b
. We will be using the prefix a lot, so best to just commit it to memory. After entering ctrl+b
you can then run a tmux command, or type :
to get a tmux prompt.
“ctrl+b :” to get tmux command prompt
When entering the prefix, tmux itself will not change in any way. So, if you enter ctrl+b
and nothing changes, that does not necessarily mean you typed it wrong.
As mentioned, a better way to get out of a session without exiting out of everything is to detach
the session. To do this, you first enter the prefix command and then the detach shortcut of d
:
The tmux sessions will each have a number associated with them on the left-hand side (zero indexed as nature intended). This number can be used to attach and get back into this same session. For example, for session number 3 we would type:
tmux attach-session -t 3
or we can go to the last created session with:
tmux a #
Now we could just rely the session numbers, but it would make our life much easier if we give our sessions names based on their intended use.
To start a new session with a specific name we can just do the below: tmux new -s [name of session]With named sessions in place, now when we do tmux ls
we see the session name instead. Likewise, we can then attach a session by using the name:
Note that we substituted a
for attach-session
to help save on keystrokes.
Unlike a standard GUI desktop, these panes are tiled, and are primarily managed by tmux shortcuts as opposed to a mouse (although mouse functionality can be ). To create a new pane you simply split the screen horizontally or vertically.
To split a pane horizontally: ctrl+b " To split pane vertically: ctrl+b %tmux split horizontally, with lower pane split vertically
You can split panes further using the same methodology. For example, in the above screenshot, the screen was first split horizontally using ctrl+b "
and then split vertically within the lower pane using ctrl+b %
.
From there we can type resize-pane
followed by a direction flag: -U
for up, -D
for down -L
for left and -R
for right. The last part is the number of lines to move it over by.
resize-pane -D 2 being entered
Customizing tmux is done primarily through the .tmux.conf
file.
Simply pick the one you want and copy the config into ~/.tmux.conf
and then source it with tmux source-file ~/.tmux.conf
.
tmux running with 3-pane layout
Questions/Comments/Other? Drop me a line via or