Tmux runs inside your terminal app and keeps shell work alive in the background. In this guide, you install it, create one session, leave that session running, and attach to it again.
The likely reader here is an English-speaking beginner on macOS who has already seen the basic idea of sessions, windows, and panes in Part 1 and now wants the first hands-on workflow.
What We'll Cover
- Install Tmux with Homebrew
- Create one session and run a simple command inside it
- Detach from that session and attach to it again
- Close the session cleanly when you are done
Before You Begin
You need a terminal on macOS and Homebrew installed. iTerm2 is fine, but Terminal.app works too.
- Terminal app: iTerm2, Terminal.app, or another macOS terminal
- Homebrew already installed
- About 10 minutes
If you skipped Part 1, keep this mental model in mind: a session is a workspace that stays alive even after you leave it.
Previous guide: Tmux Series Part 1: What is Tmux?
Step 1: Install Tmux
Start by confirming that Homebrew is available.
brew --version
If that command works, install Tmux.
brew install tmux
Typical install output looks something like this:
==> Downloading https://ghcr.io/v2/homebrew/core/tmux/...
==> Installing tmux
==> Pouring tmux--3.5...
The exact version and file path can vary. Apple Silicon Macs usually use /opt/homebrew, while Intel Macs usually use /usr/local.
Now confirm that tmux is available in your shell.
tmux -V
Expected result:
tmux 3.5
Your version number may differ. The important part is that the command succeeds.
Step 2: Create Your First Session
Create a session named mysession.
tmux new -s mysession
The name is just a label. Short names without spaces are easier to reuse later, such as work, study, or api_server.
When the session opens, your terminal still looks mostly normal, but Tmux adds a status bar at the bottom.
[mysession]is the session name0:bash*or0:zsh*usually means window 0 is active- Colors and exact layout depend on your terminal theme and shell
Run a simple command inside the session so you can recognize it later.
echo "Hello from tmux"
date
At this point, you are working inside Tmux even though it still feels like a normal shell.
Step 3: Detach From the Session
Detaching means leaving the Tmux view without stopping the work inside it.
Tmux commands usually start with a prefix key. The default prefix is Ctrl+b.
To detach:
- Press
Ctrl+b - Release both keys
- Press
d
It should feel like: Ctrl+b, release, then d.
Expected message:
[detached (from session mysession)]
After that message, you are back in your normal shell, but the session is still running in the background.
Step 4: Check Running Sessions
If you want to see which sessions currently exist, use tmux ls.
tmux ls
Typical output:
mysession: 1 windows (created Fri Mar 13 10:30:00 2026) [80x24]
The timestamp and terminal size may differ. The important part is seeing mysession in the list.
Step 5: Attach to the Session Again
Now reconnect to the session you just left.
tmux attach -t mysession
You should return to the same session with the same scrollback and command history still visible. That is the core Tmux workflow: leave a workspace, then come back to it later.
Step 6: Close the Session
If you are done with the session, close it from inside Tmux.
exit
That ends the shell running in the current window. If it is the only window in the session, the session closes and you return to your normal shell prompt.
If you are already detached and want to close the session from outside, use:
tmux kill-session -t mysession
Use kill-session only when you intentionally want to terminate that session from the outside.
Test the Full Workflow
Run this short practice loop once from start to finish.
# Create a session
tmux new -s practice
# Inside the session, run something easy to recognize
echo "Tmux is working"
# Detach with: Ctrl+b, release, then d
# Back in the normal shell, confirm the session still exists
tmux ls
# Reattach to it
tmux attach -t practice
# Exit from inside the session
exit
How to read the results:
[detached ...]means you left the session but it is still running- returning to your normal shell after
exitmeans the session closed tmux lshelps when you forget a session name
Shortcut Recap
These are the only commands and shortcuts you need from this lesson.
| Command or shortcut | What it does |
|---|---|
tmux new -s name |
Create a new session |
Ctrl+b, then d |
Detach from the current session |
tmux ls |
List running sessions |
tmux attach -t name |
Attach to a session |
exit |
Close the current shell inside Tmux |
Common Mistakes
command not found: tmux
This usually means Tmux was not installed successfully or your shell cannot find it.
which tmux
brew install tmux
If needed, close and reopen the terminal after installation.
The detach shortcut does not work
The usual mistake is pressing Ctrl+b+d all at once.
Use this timing instead:
- Press
Ctrl+b - Release both keys
- Press
d
I forgot the session name
Use:
tmux ls
That shows the names of running sessions.
Session names with spaces are annoying
Quoted names can work, but they are harder to type later.
tmux new -s my_project
tmux attach -t my_project
Prefer letters, numbers, dashes, or underscores in session names.
I want to close a detached session
Use:
tmux kill-session -t mysession
If you want to terminate every running Tmux session, use tmux kill-server, but treat that as a last-resort cleanup command.
Practice Checklist
You are ready for the next post when you can do all of these without looking up every step.
- Install Tmux and confirm
tmux -Vworks - Create a session with
tmux new -s name - Detach with
Ctrl+b, thend - List sessions with
tmux ls - Reattach with
tmux attach -t name - Close the session with
exit
Up Next
Once session creation, detach, and reattach feel natural, the next step is learning how to organize more than one task inside a session.
Tmux Series Part 3: Manage Sessions and Windows shows how to create multiple windows, switch between them, and keep different kinds of work organized.
💬 댓글
이 글에 대한 의견을 남겨주세요