How can I make tmux use my default shell?

163

52

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

How can I force it to use zsh?

re5et

Posted 2011-03-06T05:04:53.257

Reputation: 1 743

12figured it out. Can set the following in tmux config: set -g default-command /bin/zsh set -g default-shell /bin/zsh – re5et – 2011-03-06T05:33:29.010

4FWIW, you don't need to set default-command if you've set default-shell. – Nicholas Riley – 2012-02-29T20:03:14.527

Answers

215

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

Posted 2011-03-06T05:04:53.257

Reputation: 2 174

14Or simply run tmux source-file ~/.tmux.conf from the command line. – Petr Pudlák – 2014-10-29T12:43:48.903

13@js-coder: to more cleanly kill your tmux server I'd recommend tmux kill-server instead. – Chuim – 2015-02-13T22:32:45.013

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 – 2016-06-07T05:48:20.117

2killall not working on zesty. I had to pkill tmux. The processes were named 'tmux: server' and 'tmux: client'. – loxaxs – 2017-10-03T15:57:29.430

6If 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 – 2012-09-20T20:55:33.743

29BTW: Restarting tmux means killall tmux; tmux. Took me quite a while to figure out. – js-coder – 2012-12-21T14:48:09.907

5Configs could be reloaded without killing a server: bind R source-file ~/.tmux.conf \; display-message " Config reloaded..". – ДМИТРИЙ МАЛИКОВ – 2013-07-02T08:01:26.800

44

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

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

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

set-option -g default-shell $SHELL

DebugXYZ

Posted 2011-03-06T05:04:53.257

Reputation: 594

1It is unnecessary to set user shell (chsh -s) as tmux offers an option independent of that. – Mahmoud Al-Qudsi – 2017-05-30T06:00:11.800

I thought it was more robust to use the $SHELL variable. But it adds an extra step and confusion so I do prefer the accepted answer. – DebugXYZ – 2019-01-13T22:05:28.860

This is better than the accepted answer. My zsh is not installed in /bin/zsh. – HappyFace – 2019-08-04T17:56:51.997

21

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.

wyattdanger

Posted 2011-03-06T05:04:53.257

Reputation: 321

1Although it wasn't the answer the OP asked for, I ended up in this thread and indeed I am on OS X, using this wrapper, and this is the solution I needed; so Thank You! – Jose Alban – 2015-09-24T11:47:07.593

1how does this differ from set-option -g default-shell? the above does not seem to work with the Fish shell. – Tommy – 2016-02-09T01:50:41.650

Change zsh to $SHELL to make it work without hard-coding your shell. – awendt – 2017-11-28T11:00:34.137

2Er, is there any indication that re5et (the OP) is on a Mac, or has that wrapper program installed? – Chris Johnsen – 2012-02-01T07:13:06.283

1I think this answer only works for Mac OS X – EhevuTov – 2013-07-25T06:29:40.390

5tmux kill-server is the command to end all tmux servers – Keith Smiley – 2013-10-14T17:05:55.130

6

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

Posted 2011-03-06T05:04:53.257

Reputation: 190

1This is the only answer that worked for me (the tmux kill-server command) – undefined – 2018-01-27T00:30:47.867

5

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

Posted 2011-03-06T05:04:53.257

Reputation: 1 071

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 – 2016-11-04T08:38:15.060

Yeah.. maybe env SHELL=/usr/bin/zsh tmux is better? (updated the answer). – blueyed – 2016-11-06T00:33:53.583

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

Patrick Cho

Posted 2011-03-06T05:04:53.257

Reputation: 121

2

Use chsh(1):

chsh -s /bin/zsh $USER

amphetamachine

Posted 2011-03-06T05:04:53.257

Reputation: 1 443

1i already had this set, but tmux was ignoring it. – re5et – 2011-03-06T05:33:03.223

1

The accepted answer did not work for me.

I had to write both

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

and

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

in my ~/.tmux.conf — Dont forget to tmux kill-server; tmux, to reload the tmux.conf


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.

anarchist912

Posted 2011-03-06T05:04:53.257

Reputation: 111

1

Add this into your ~/.tmux.conf

set -g default-command /usr/local/bin/fish

IanVaughan

Posted 2011-03-06T05:04:53.257

Reputation: 173

0

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

Posted 2011-03-06T05:04:53.257

Reputation: 101

This is a duplicate of answer https://superuser.com/a/1370909/174140.

– 174140 – 2019-09-18T09:31:10.560

@john I've used set-option -g instead of set -g. different versions of tmux most probably – Ali Amin – 2019-09-19T11:24:18.027

set is an alias for set-option. – 174140 – 2019-09-19T11:28:11.067