122

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
codeforester
  • 39,467
  • 16
  • 112
  • 140
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
  • 1
    What does `chsh -l` output? (If that doesn't work what are the contents of `/etc/shells`?) Are you sure this is failing and not just warning? Does adding `/usr/bin/zsh` there make this work? – Etan Reisner Jun 24 '15 at 19:05
  • 1
    chsh: option requires an argument -- l usage: chpass [-l location] [-u authname] [-s shell] [user] – Harsha M V Jun 24 '15 at 19:09
  • /bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh – Harsha M V Jun 24 '15 at 19:10
  • What's wrong with `/bin/zsh`? – jxh Sep 26 '17 at 22:56
  • 1
    There is official way to change the default shell to zsh now. See the Apple document "Use zsh as the default shell on your Mac" https://support.apple.com/en-ca/HT208050 – Anthonyeef Jun 04 '19 at 05:09
  • 1
    iTerm2 --> Preference --> Profiles --> Command --> Custom Shell --> /usr/local/bin/zsh – Sachin Raut Aug 18 '20 at 07:37

4 Answers4

225

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)
Daniel
  • 11,332
  • 9
  • 44
  • 72
  • 5
    this is more accurate than the accepted answer in my opinion. assuming zsh is installed at /usr/bin/zsh, the other answers do not work. They worked for OP because by default, Apple installs zsh at /bin/zsh. However, if you wanted to use homebrew's zsh (which is installed under /usr/local/bin/zsh), this would be the proper way to do it – verboze Jul 11 '17 at 20:37
  • I've got "bash: /etc/shells: Permission denied". The answer via System Preferences worked for me. – Ricardo Stuven Aug 02 '17 at 19:17
  • 46
    If you get the `/etc/shells: Permission denied` ==> Do that instead: `sudo sh -c "echo $(which zsh) >> /etc/shells"` – ThisIsFlorianK Aug 10 '17 at 15:32
  • 1
    https://stackoverflow.com/a/44547726/99834 -- worked without messing with system files. Only thing missing is a CLI verson for doing the same operation. – sorin Mar 02 '19 at 15:12
  • @sorin Is this downvote gratuitous vandalism or is there anything actually wrong with the answer? System files are editable text files for a reason. `chsh` is available per default for a reason. Although there is nothing inherently wrong with clicking through loads of menus to accomplish the same thing, that is not only unportable and error prone, but also misleading in that it hides from users where the change is coming from. – Daniel Mar 02 '19 at 23:22
  • @dangom Yes there is an issue: your change would be lost on system update, user would lose support because alteration of system file. I love CLI solution and prefer them whenever is possible but in this case the GUI approach is much safer. I am not sure why yet but the gui method did not need alteration of /etc/shells. – sorin Mar 03 '19 at 15:50
  • @sorin AFAIK system updates do not touch `/etc/shells`. I've gone through heaps of MacOS updates and never had an issue of losing my configuration. This may well be true for mac-specific system files or preference files. But then, to each his own. Luckily there are multiple correct answers here so users can pick whatever they want. – Daniel Mar 03 '19 at 22:07
  • Also, to append `zsh` to `/etc/shells`, you can do `echo $(which zsh) | sudo tee -a /etc/shells`. I think it's the best way to do it – Pablo K Oct 16 '19 at 13:57
97

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
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Quentin Perez
  • 2,833
  • 20
  • 22
  • yay that worked. is it Yosemite specific? – Harsha M V Jun 24 '15 at 19:10
  • 2
    No I don't think, it was just for your information :) – Quentin Perez Jun 24 '15 at 19:11
  • 9
    Another relevant [comment](http://superuser.com/questions/362372/how-to-change-the-login-shell-on-mac-os-x-from-bash-to-zsh#comment680433_362374) on the same older question that says to add `/usr/bin/zsh` to `/etc/shells` solves the problem. – bric3 Nov 04 '16 at 16:32
  • It works perfect – Olkunmustafa May 16 '17 at 08:16
  • 1
    Set it accordingly to /etc/shells! Look for zsh path with '$ nano /etc/shells'. Mine was at /bin/zsh instead of /usr/bin/zsh on 10.12.2 – oikonomopo May 26 '17 at 08:19
  • One thing I didn't realize is zsh is already installed on the Mac. One other way to change the shell is use the popular oh-my-zh framework which will change the shell to zsh for you when you issue the curl or wget command listed on their website http://ohmyz.sh/ Such as `sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"` – What Would Be Cool Dec 10 '17 at 15:04
  • @Brice works for me, thanks – Jonas WebDev Nov 13 '18 at 16:38
  • you don't have to restart machine, just open new tab – daymosik Nov 14 '18 at 21:01
  • This does not work but https://stackoverflow.com/a/44547726/99834 works! – sorin Mar 02 '19 at 15:12
  • Here are the steps Apple provides on their website if someone still needs it: https://support.apple.com/en-us/HT208050 – goto Jun 07 '19 at 18:45
57

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
Nate Jenson
  • 2,664
  • 1
  • 25
  • 34
  • 4
    if you install zsh via homebrew it will place zsh in `/usr/local/bin/zsh`. Therefore you will need to edit `/etc/shells` under sudo and add an entry for `/usr/local/bin/zsh` before you can select the zsh executable that hombrew installed – Baldy Jul 28 '17 at 07:58
9

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.

sakovias
  • 1,356
  • 1
  • 17
  • 26
  • Note that instead of simply starting zsh (desired behavior) this instead starts bash and then spawns zsh _from within bash_ (an anti-pattern sometimes called "nested shell invocation"). – Austin York May 09 '23 at 12:09