Making ZSH default Shell in MacOSX

BashShellZsh

Bash Problem Overview


I installed zsh on my Mac. and now i want to make it the default shell instead of Bash. But I seem to be running into the following error:

$ echo $SHELL
/bin/bash
$ chsh -s /usr/bin/zsh
Changing shell for harshamv.
Password for harshamv:
chsh: /usr/bin/zsh: non-standard shell

Bash Solutions


Solution 1 - Bash

The correct answer should've addressed your problem:

> chsh: /usr/bin/zsh: non-standard shell

The reason this is the case is because chsh will only accept shells that are defined in the file /etc/shells, as you can see by reading the manual for chsh:

> chsh will accept the full pathname of any executable file on > the system. However, it will issue a warning if the shell is not > listed in the > /etc/shells file.

To solve this problem and make zsh the default shell, you should thus:

$ sudo echo "$(which zsh)" >> /etc/shells
$ chsh -s $(which zsh)

Obviously, I assume that zsh is in your path here. This solution will also work if you, for example, choose to install the latest zsh with brew install zsh.

EDIT (thanks for ThisIsFlorianK for the comment):

Depending on your shell setup you may get a message saying /etc/shells: Permission denied. You can find information about this issue here. To work around it, use the following instead:

$ sudo sh -c "echo $(which zsh) >> /etc/shells"
$ chsh -s $(which zsh)

Solution 2 - Bash

The three easy steps:
  1. which zsh this gives you your path to zsh
  2. Then chsh -s /bin/zsh or replace path to your zsh if different
  3. Restart your machine

Solution 3 - Bash

I was able to get this working by doing the following:

  1. Go to System Preferences
  2. Click on "Users & Groups"
  3. Click the lock to make changes.
  4. Right click the current user -> Advanced options
  5. Change the login shell to /bin/zsh in the dropdown.
  6. Open a new terminal and verify with echo $SHELL

Solution 4 - Bash

On my work MacBook I had to do this:

sudo chsh -s /usr/local/bin/zsh my_user_name

Then I had to create a .bash_profile file to make my terminal switch to z-shell every time I open it:

touch ~/.bash_profile
echo 'export SHELL=$(which zsh)' >> ~/.bash_profile
echo 'exec $(which zsh) -l' >> ~/.bash_profile

The last idea was borrowed from here.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarsha M VView Question on Stackoverflow
Solution 1 - BashdangomView Answer on Stackoverflow
Solution 2 - BashQuentin PerezView Answer on Stackoverflow
Solution 3 - BashNate JensonView Answer on Stackoverflow
Solution 4 - BashsakoviasView Answer on Stackoverflow