How to change the default shell in tmux?

Quick Answer

To change the default shell in tmux, add set-option -g default-shell /path/to/shell to your ~/.tmux.conf file. You can also change it temporarily with Ctrl+b :set-option -g default-shell /path/to/shell.

set-option -g default-shell /bin/zsh

Detailed Explanation

tmux uses your system's default login shell by default. However, you might want to use a different shell specifically within tmux sessions. You can configure this either permanently in your configuration file or temporarily during a session.

Permanently changing the default shell:

To set a permanent default shell for tmux, add the following line to your ~/.tmux.conf file:

set-option -g default-shell /bin/zsh

Replace /bin/zsh with the path to your preferred shell. Common shells include:

  • /bin/bash - Bash shell
  • /bin/zsh - Z shell
  • /bin/fish - Fish shell
  • /usr/local/bin/fish - Fish shell (Homebrew installation on Mac)

Temporarily changing the default shell:

You can also change the default shell for your current tmux session without modifying your configuration file:

  1. Press Ctrl+b to activate tmux command prefix
  2. Press : to enter command mode
  3. Type set-option -g default-shell /bin/zsh and press Enter

This change will only affect the current tmux server instance and will be lost when you restart tmux.

Finding the path to your shell:

If you're unsure of the exact path to your preferred shell, you can find it using:

$ which zsh
/bin/zsh

Pro Tip

If you're using a non-standard shell like Fish, you might want to ensure tmux uses a login shell to properly source your profile files:

# Use Fish as default shell in login mode
set -g default-command "/usr/local/bin/fish -l"
set -g default-shell "/usr/local/bin/fish"

Compatibility Note

After changing your default shell, you may need to restart your tmux server for the changes to take effect. You can do this by stopping all sessions (tmux kill-server) and then starting a new session.