I know I can set "Shells open with" in the Terminal preferences, but I'm curious if there's any system-wide way of setting this (similar to updating /etc/passwd in some Unixes).
5 Answers
Use the chsh utility like so:
chsh -s bash
Apple has changed chsh a bit on Mac OS X compared to the chsh you'd see in Linux for example. You can read up on theirs in the chsh Mac OS X Man Page.
-
And here I figured it was something complicated with some OSX-specific utility, heh. Thanks. – nall Sep 29 '09 at 00:11
-
@john - nicely learned :) – akira Sep 29 '09 at 04:42
-
Yeah I knew the answer last time too, I was just beaten to it! :( – Sep 29 '09 at 05:02
-
The link doesn't work anymore. Do I have to restart the system to take effect for this? – Daniel W. Mar 09 '20 at 14:09
-
@DanielW. Logout should be enough – Tim4497 Aug 17 '22 at 18:51
Note that you will only be allowed to change to a shell listed in /etc/shells. This is normally fine, but it means that if you want to install Bash 4 (from Homebrew, MacPorts, or compiling your own), you need to add a line to /etc/shells. (I ran into this a few weeks ago, and figured it might help others to know...)
Edit: Tim Smith points out that you can get around the /etc/shells limitation if you run chsh as root via sudo. E.g. sudo chsh -s /usr/local/bin/my_shell $USER will work, even if my_shell is not listed in /etc/shells. I prefer to edit /etc/shells, but in the end, it's one use of sudo either way since you can't edit /etc/shells as a regular user. So perhaps six of one, half dozen of the other.
- 6,925
-
Why change
/etc/shellsif you don't have to? For sanity, I prefer to keep system files the same. – ma11hew28 Oct 19 '15 at 23:34 -
1@MattDiPasquale I'm not sure what you mean by "sanity".
/etc/shellsis the file on the system that defines recognized shells. I change that file because I want to add a shell to the list of recognized shells. Seems pretty reasonable to me. – Telemachus Oct 20 '15 at 14:35 -
Good alt. way , for some reason chsh would not work for me . I got this ;
chsh: bash: non-standard shell– RyBolt Aug 02 '16 at 03:30 -
@RyBolt Right: the reason is probably what I mention in the answer. You can't use
chshalone if you're trying to use a shell that isn't listed in/etc/shells. – Telemachus Aug 02 '16 at 10:20 -
@Telemachus , I was just trying to change to the original bash shell that came with my default Mac OSX build. Maybe it's not in
/etc/shellswhich seems strange to me. – RyBolt Aug 02 '16 at 13:24 -
1@RyBolt The original default bash should be in
/etc/shells. You can test by runningcat /etc/shells. My guess is that when you tried, you entered only the wordbash. That won't work. You need to enter the whole path, namely/bin/bash. – Telemachus Aug 02 '16 at 20:13
To do this using the Mac OS X GUI:
- Open “System Preferences.”
- Open the “Accounts”/“Users & Groups” preference pane and unlock the preference pane if applicable.
- On the user you wish to change the shell, control+click or right click on the user and choose “Advanced Options…”
- Where it says “Login Shell:” change this to the shell you wish to use.
Of note, this location is where you can change your home directory, UUID, User ID, Group ID, and short name if you're uncomfortable with the Terminal. There is a similar question located here as well.
Using the answers above I was getting an error message:
$ chsh -s zsh
Changing shell for myuser.
Password for myuser:
chsh: zsh: non-standard shell
To work around this:
sudo chsh -s zsh $(whoami)
whoami in a subshell is to change the shell for your user, not the root.
One more thing if you're using homebrew. When you run commands as root (using sudo), zsh points to /bin/zsh, which comes with OSX and might be outdated. To use the up to date one that is installed via homebrew, use the following:
sudo chsh -s $(which zsh) $(whoami)
- 185
For newer and for homebrew-installed shells:
Edit
/etc/shells, adding your new shell to the list- either
sudo vim /etc/shells(or your preferred editor) - or
echo '/usr/local/bin/fish' | sudo tee -a /etc/shells ; cat /etc/shells
- either
Then you can
chsh -s /usr/local/bin/fish
Unlike other answers, I find (macOs Monterey in 2022) that I have to give chsh the full path to the shell. Similarly, the default Apple message if bash is my shell says
To update your account to use zsh, please run
chsh -s /bin/zsh.
- 416
- 3
- 12
-
two more thinks, you can check your shell with:
echo "Current shell is: $SHELL"if its not correct try to log out of macOS and log in again!
Also check if it's in the “Accounts”/“Users & Groups” preference pane as statet in @Chealion answer
– Tim4497 Aug 17 '22 at 18:49