How can I make tmux use my default shell?
Solution 1
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
Solution 2
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
Solution 3
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.
Solution 4
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
Solution 5
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.
Related videos on Youtube
re5et
Updated on September 17, 2022Comments
-
re5et over 1 year
On a new setup, tmux is using bash instead of my default (zsh).
How can I force it to use zsh?
-
re5et about 13 yearsfigured it out. Can set the following in tmux config: set -g default-command /bin/zsh set -g default-shell /bin/zsh
-
Nicholas Riley about 12 yearsFWIW, you don't need to set default-command if you've set default-shell.
-
-
Anup Dey over 11 yearsIf this doesn't work for you then make sure you've restart
tmux
. Seems obvious but took me a good hour to figure out! -
js-coder over 11 yearsBTW: Restarting tmux means
killall tmux; tmux
. Took me quite a while to figure out. -
ДМИТРИЙ МАЛИКОВ almost 11 yearsConfigs could be reloaded without killing a server:
bind R source-file ~/.tmux.conf \; display-message " Config reloaded..".
-
EhevuTov almost 11 yearsI think this answer only works for Mac OS X
-
Keith Smiley over 10 years
tmux kill-server
is the command to end all tmux servers -
Petr over 9 yearsOr simply run
tmux source-file ~/.tmux.conf
from the command line. -
Lorenzo over 9 years@js-coder: to more cleanly kill your tmux server I'd recommend
tmux kill-server
instead. -
Jose Alban over 8 yearsAlthough 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!
-
Tommy over 8 yearshow does this differ from
set-option -g default-shell
? the above does not seem to work with the Fish shell. -
dylnmc almost 8 yearsnot 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.
-
Sam Brightman over 7 yearsNot 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 ifdefault-shell
is not set explicitly. -
blueyed over 7 yearsYeah.. maybe
env SHELL=/usr/bin/zsh tmux
is better? (updated the answer). -
Mahmoud Al-Qudsi almost 7 yearsIt is unnecessary to set user shell (
chsh -s
) as tmux offers an option independent of that. -
loxaxs over 6 years
killall
not working on zesty. I had topkill tmux
. The processes were named'tmux: server'
and'tmux: client'
. -
awendt over 6 yearsChange
zsh
to$SHELL
to make it work without hard-coding your shell. -
undefined over 6 yearsThis is the only answer that worked for me (the tmux kill-server command)
-
DebugXYZ over 5 yearsI 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.
-
HappyFace almost 5 yearsThis is better than the accepted answer. My zsh is not installed in /bin/zsh.
-
174140 over 4 yearsThis is a duplicate of answer superuser.com/a/1370909/174140.
-
Ali Amin over 4 years@john I've used
set-option -g
instead ofset -g
. different versions of tmux most probably -
174140 over 4 years
set
is an alias forset-option
. -
dessert over 3 yearsIs the double command substitution intended?
-
Community about 2 yearsAs 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.
-
Zach_is_my_name about 2 yearsYou can find more information on how I meant exactly what I typed in the help center...