326

I am trying to set ZSH as my default shell, however it keeps reverting back to bash.

I have tried this code:

sudo chsh -s $(which zsh)

I've also tried:

sudo chsh -s /bin/zsh 

Also tried these commands without sudo. Any ideas on what else I need to do. When running ZSH from within bash it loads up and works fine but I'd like to set it as the default shell.

Diogo Gomes
  • 560
  • 3
  • 16
Tom
  • 3,629
  • 4
  • 18
  • 10
  • 7
    quick answer that worked for me: logging out and then logging back in to the desktop session fixed it for me. – aderchox Jul 13 '20 at 23:27

7 Answers7

525

Just using chsh:

chsh -s $(which zsh)

without sudo should work. If you use sudo it will change the shell not for your working user but for root

Finally, log out of your computer and log back in.

Troubleshooting:

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
71

I found this on superuser forum

Open /etc/passwd:

sudo vi /etc/passwd

Find the line with your username:

username:x:1634231:100:Your Name:/home/username:/bin/bash

and replace bash with zsh:

username:x:1634231:100:Your Name:/home/username:/bin/zsh

Log out and log in back for the changes to take effect.

  • 26
    You should be very careful with this approach - it's not usually the best idea to go mucking around with `/etc/passwd` – Thomas Ward Jan 07 '16 at 13:13
  • 5
    Even though I didn't use this method, it helped me verify the effect of `chsh -s \`which zsh\`` – jchook Sep 30 '17 at 00:43
  • 1
    To **Log out and log in back** is very important step. Maybe it is should even be somehow emphasized. – luke Dec 23 '22 at 17:03
43

You may also do this:

open your bashrc file in your favourite editor

sudo nano ~/.bashrc

then add the line below top of the file

exec zsh

It will execute the command every time you load the terminal and run your zsh shell.

muru
  • 193,181
  • 53
  • 473
  • 722
Saddam H
  • 581
  • 4
  • 3
  • 25
    and it will also break all your non-interactive jobs (`scp` for example). – Jakuje Mar 11 '16 at 16:45
  • 3
    Sorry for the downvote, but changing `/etc/passwd` or `chsh` are better solutions and more reliable. – Timo Dec 25 '18 at 11:57
  • Thanks that did it. @Timo I did the change on /etc/passwd and or chsh but my default kept going back to bash. I added exec zsh as per posted response and it worked. – Stryker Feb 11 '19 at 21:42
  • 1
    Adding exec zsh is most likely going to break your Gnome Shell session. – fracca Oct 26 '19 at 10:58
  • This was the only one that worked for me on the work machine with active directory, my username is always not found, whoami works fine, but certain commands such as chsh always cannot locate my username – element11 May 15 '20 at 18:20
  • editing /etc/passwd is never better for someone who cant read the chsh manpage. – RichieHH Aug 07 '20 at 14:58
  • You saved my day by this answer – Hazem Hagrass Dec 17 '21 at 11:37
  • DO NOT TRY THIS............DO NOT TRY THIS.This is the worst ever reply for setting the zsh as default shell. Since i had done this and my system is keep in loop of showing login screen after entering username/password. – TarangP Dec 16 '22 at 14:20
18

I had an issue with permissions to change shell under the current user but next helps me (you should set correct 'zsh' folder for your computer):

sudo chsh -s /bin/zsh <myUserName>
Rib47
  • 649
  • 1
  • 8
  • 11
3

If zsh is not /bin/zsh then chsh won't work. On Ubuntu it is /usr/bin/zsh. so doing chsh -s /usr/bin/zsh or chsh -s `which zsh` should work. Also need to re-login to desktop session.

jbp
  • 139
  • 3
2

Strange, the "accepted" answer didn't work for me as I got

chsh: PAM: Authentication failure

To solve this issue edit your /etc/passwd and make sure it points to the zsh location. (You can find this by running "which zsh") In my case my user called "webmaster" looked like this:

webmaster:x:1001:1001:webmaster,,,:/var/www/webmaster:/usr/bin/zsh
wjandrea
  • 14,109
  • 4
  • 48
  • 98
John Crawford
  • 280
  • 2
  • 5
  • 15
  • I believe it's supposed to ask for a password. I got the same error on my previous mint install. Current one worked fine though – Wilhelm Erasmus Dec 09 '15 at 12:40
  • [Someone else](https://serverfault.com/q/500865/403609) had the same problem, and it turned out they had ran `chsh -s zsh`, which made their passwd entry incorrect. – wjandrea Oct 21 '17 at 00:46
0

As well as chsh (or editing /etc/passwd, which does the same thing), you might need to edit the settings in your terminal emulator (Gnome terminal, Konsole, xfce4-terminal, etc). Your profile will probably have a login shell, which will be run when you open a new tab instead of the shell in /etc/passwd.
In Konqueror it's Settings | Edit Current Profile | Command.

andrew lorien
  • 1,263
  • 11
  • 14