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?
4 Answers
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
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. 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 YamApr 28, 2017 at 9:22
-
This is essentially what the other two answers have already said, though.– Jeff Schaller ♦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
Password:
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.
chsh
" rather than "chsh
isn't working for me".