36

I installed ZSH on a VM of mine, where I compiled it from source. The location of ZSH is /usr/local/bin/zsh when I run chsh -s /usr/local/bin/zsh it outputs chsh: /usr/local/bin/zsh is an invalid shell. I also tried this with sudo as well. How can I change this?

  • possible duplicate of Where do I change my shell? – Mikel Jan 28 '14 at 19:56
  • 6
    @Mikel, no, that question is "I don't know about chsh" rather than "chsh isn't working for me". – cjm Jan 28 '14 at 20:01
51

Add zsh to /etc/shells:

command -v zsh | sudo tee -a /etc/shells

You can now use chsh to set zsh as shell:

sudo chsh -s "$(command -v zsh)" "${USER}"

See this documentation: Changing your login shell

| improve this answer | |
8

You need to add /usr/local/bin/zsh to /etc/shells.

| improve this answer | |
4

First, check if zsh is listed as a valid shell by

cat /etc/shells

If zsh is not listed, install it. For example, if you use apt

sudo apt-get install zsh

Do, step 1 again and see the path of zsh. In my case, both /usr/bin/zsh and /usr/zsh is listed. As @Stéphane Chazelas mentioned in the comment, if you like to compile and install the shell from scratch, be sure to add the path in /etc/shells.

Change the shell using

chsh -s /usr/bin/zsh

From man page:

-s, --shell SHELL The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell.

Logout and login again.

| improve this answer | |
  • Yes, if you install the shell as part of a OS package, the OS packaging will typically add the shell to /etc/shells. The point here is that if you compile and install the shell by hand, you also need to add the path to /etc/shells yourself by hand. – Stéphane Chazelas Apr 28 '17 at 9:11
  • Good point. I was thinking of a package manager like 'apt'. I have edited the answer to include your point. – Sat Yam Apr 28 '17 at 9:22
  • This is essentially what the other two answers have already said, though. – Jeff Schaller Apr 28 '17 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.