220

On a new setup, tmux is using bash instead of my default (zsh).

How can I force it to use zsh?

Gaff
  • 18,569
  • 15
  • 57
  • 68
re5et
  • 2,313
  • 2
  • 14
  • 4

13 Answers13

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

in ~/.tmux.conf or /etc/tmux.conf. Works on Fedora.

You can reload the config with <leader>: source-file <conf file> e.g.

<C-b>: source-file ~/.tmux.conf

You would need to do it for every tmux instance. Otherwise you may restart tmux with killall tmux; tmux

Alex Hammel
  • 2,994
  • 1
  • 14
  • 3
  • 11
    If this doesn't work for you then make sure you've restart `tmux`. Seems obvious but took me a good hour to figure out! – Andy Smith Sep 20 '12 at 20:55
  • 37
    BTW: Restarting tmux means `killall tmux; tmux`. Took me quite a while to figure out. – js-coder Dec 21 '12 at 14:48
  • 7
    Configs could be reloaded without killing a server: `bind R source-file ~/.tmux.conf \; display-message " Config reloaded..".` – ДМИТРИЙ МАЛИКОВ Jul 02 '13 at 08:01
  • 18
    Or simply run `tmux source-file ~/.tmux.conf` from the command line. – Petr Oct 29 '14 at 12:43
  • 19
    @js-coder: to more cleanly kill your tmux server I'd recommend `tmux kill-server` instead. – Chuim Feb 13 '15 at 22:32
  • not sure if it's just a newer version of tmux, but I never had to kill the tmux server or tmux itself. Once you set the option, it should work. – dylnmc Jun 07 '16 at 05:48
  • 3
    `killall` not working on zesty. I had to `pkill tmux`. The processes were named `'tmux: server'` and `'tmux: client'`. – loxaxs Oct 03 '17 at 15:57
59

First, ensure your default shell is set properly to zsh by running this in your command line:

chsh -s $(`which zsh`) $USER

Placing the following in your ~/.tmux.conf is a more robust option for any shell.

set-option -g default-shell $SHELL
NotTheDr01ds
  • 17,574
  • 4
  • 44
  • 81
DebugXYZ
  • 754
  • 5
  • 7
25

For MacOS users, drop this line in the bottom of your ~/.tmux.conf

set-option -g default-command "reattach-to-user-namespace -l zsh"

After you add that, kill and restart your tmux server and all should work.

NotTheDr01ds
  • 17,574
  • 4
  • 44
  • 81
wyattdanger
  • 361
  • 3
  • 3
12

tmux appears to use the SHELL environment variable, so the following should work:

SHELL=/usr/bin/zsh tmux

or

env SHELL=/usr/bin/zsh tmux
blueyed
  • 1,201
  • 11
  • 20
  • Not sure why this was down-voted. It appears to be correct: a common problem is using a different shell for e.g. iTerm but leaving login shell as `/bin/bash` to ensure nothing non-iteractive breaks. iTerm will not set `$SHELL` to the new shell name (unsure why), and bash initialisation will set it to the login shell if unset at startup. tmux then uses this value if `default-shell` is not set explicitly. – Sam Brightman Nov 04 '16 at 08:38
  • Yeah.. maybe `env SHELL=/usr/bin/zsh tmux` is better? (updated the answer). – blueyed Nov 06 '16 at 00:33
9

If you want to force tmux to use the same shell as specified in your environment variable, you could use:

# force SHELL ENV variable as shell
set-option -g default-shell ${SHELL}

in your ~/.tmux.conf or /etc/tmux.conf.

To get the change to actually take effect, you may need to tmux kill-server and then tmux to restart tmux.

mareoraft
  • 250
  • 2
  • 8
6

The accepted answer did not work for me.

I had to write both

set -g default-shell  "/bin/bash"

and

set -g default-command "/bin/bash"

in my ~/.tmux.conf — Dont forget to run the following commands to reload the tmux.conf:

tmux kill-server; tmux

Im am using tmux -V 2.6 under Ubuntu 18 in the gnome-shell emulator.

I also enhanced tmux with https://github.com/samoshkin/tmux-config. Check it out, it's really cool.

Dmitry
  • 103
  • 3
Wu Wei
  • 171
  • 1
  • 3
3

Use chsh(1):

chsh -s /bin/zsh $USER
amphetamachine
  • 1,668
  • 2
  • 12
  • 15
2

Log-out and log-in again fixed my problem. When echoed $SHELL it was still /bin/bash but after log-out it was changed to /usr/bin/zsh

nKn
  • 5,549
  • 6
  • 32
  • 38
Patrick Cho
  • 121
  • 1
2

For me I had to replace:

default-command "/usr/local/bin/fish"
default-shell "/usr/local/bin/fish"

with

set-option -g default-command "/usr/local/bin/fish"
set-option -g default-shell "/usr/local/bin/fish"

in .tmux.conf and run command tmux kill-server; tmux

Ali Amin
  • 121
  • 1
2

Add this into your ~/.tmux.conf

set -g default-command /usr/local/bin/fish
IanVaughan
  • 213
  • 1
  • 3
  • 9
1

I wanted it to force to use an custom .bashrc. The following should work for any shell. My new is .tmux-bashrc is just an copy of .bashrc , minus the ncal or cowsay, etc... The speed improvements are now apparent.

in ~/.tmux.conf

set-option -g default-shell $SHELL
set-option -g default-command "$SHELL --init-file .tmux-bashrc"
Will Budic
  • 13
  • 3
0

Obvious but When trying the other answers... Check if another shell is printed below the line you're inserting before you blow a gasket

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 01 '22 at 04:00
  • You can find more information on how I meant exactly what I typed in the help center... – Zach_is_my_name Apr 01 '22 at 04:03
0

As for me, I use Arch Linux inside Windows WSL2 and I have done chsh -s /bin/zsh $USER and when entering tmux it would not correctly load zsh(show some errors e.g. add-zsh-hook function definition file not found and so on. If I enter zsh manually again, everything works fine. And I found that inside ~/.tmux.conf add one line set -g default-command /bin/zsh should be the answer to fix this problem but I don't know why setting default-shell or setting SHELL variable was in vain.

FYI, tmux(1) — Linux manual page

d0zingcat
  • 131
  • 3