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
    Commented Jan 28, 2014 at 19:56
  • 7
    @Mikel, no, that question is "I don't know about chsh" rather than "chsh isn't working for me".
    – cjm
    Commented Jan 28, 2014 at 20:01

4 Answers 4


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

  • 1
    Word of warning: /ec/shells is not always created by default. If you use the above command, it will be created with ONLY zsh. Users with other shells, including the default bash shell, will NOT be able to login to the system. Spent 45 minutes pulling my hair out trying to figure out why I couldn't log into the system as root or any other user, even after booting from USB drive and repeatedly resetting passwords.
    – Dan J.
    Commented Nov 23, 2022 at 11:22

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


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.

  • 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. Commented Apr 28, 2017 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
    Commented Apr 28, 2017 at 9:22
  • This is essentially what the other two answers have already said, though.
    – Jeff Schaller
    Commented Apr 28, 2017 at 10:22

I am running Ubuntu 21 on ARM64 (Raspberry Pi 4), and there is more to this issue than the answers reveal. I installed zsh and ksh and tried changing my shell to zsh and to ksh using chsh, and both times I got the "invalid shell" message. I checked /etc/shells, and that file contained both shells. I tried the chsh command using just the bare shell names (zsh, ksh) and also using the full path names as listed in /etc/shells. I couldn't get it to work. Finally, out of frustration I just changed my shell in the /etc/passwd file, and then it worked. Later, I learned that there are two different ways of invoking chsh. What I was trying was: chsh -s , which gave the error message. But chsh can also be invoked by simply typing chsh . This opens an interactive session:

$ chsh
Changing the login shell for tom
Enter the new value, or press ENTER for the default
    Login Shell [/bin/ksh93]: /usr/bin/zsh

When I do it this way, it works. However, entering the command as chsh -s still doesn't work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .