324

I'm learning to develop in Rails, and have discovered the power of zsh. However, for some of my other tasks, I wish to use normal bash.

Although they are the same, I just feel comfortable with the layout of bash in some situations.

How do I switch back and forth, or turn zsh on and off?

13 Answers 13

630

You can just use exec to replace your current shell with a new shell:

Switch to bash:

exec bash

Switch to zsh:

exec zsh

This won't affect new terminal windows or anything, but it's convenient.

6
  • 1
    Or, just invoke zsh, and when you’re done exit to get back to bash. Exec’ing it seems unnecessary and undesirable.
    – Chris Page
    May 3, 2012 at 7:32
  • All depends on what you expect your terminal window to do when you exit. I find starting a subshell unnecessary and undesirable, myself.
    – larsks
    May 3, 2012 at 15:40
  • 3
    How do you change the default? Also, when I do "exec bash" in zsh, it does not source my bash_profile.
    – hxkl
    Jan 11, 2014 at 17:59
  • 1
    There are times when I want to use zsh and other times when it interferes with what I want to do. Setting the default back and forth is a bad idea so this is the perfect solution!!! kudos!! Jan 20, 2017 at 4:55
  • 1
    But if you run echo $SHELL it keep saying /bin/zsh, which have unexpected results like this problem with MC (bug 3580). Apr 28, 2018 at 23:32
240

you can try chsh -s /bin/bash to set the bash as the default, or chsh -s /bin/zsh to set the zsh as the default.

Terminal will need a restart to take effect.

2
  • 7
    Not entirely true. One can simply enter command: "bash", or "zsh" to use that shell.
    – Kevin C
    Dec 1, 2021 at 14:25
  • I don't think this work anymore in 2022 Aug 1, 2022 at 21:59
85

I switch between zsh and bash somewhat frequently. For a while, I used to have to source my bash_profile every switch. Then I found out you can (typically) do

exec bash --login

or just

exec bash -l
3
  • 2
    Thanks phill, I installed thoughtbot/laptop and it mess all my configs. Your tip helps to get my bash environment back.
    – Seralto
    Oct 1, 2015 at 13:45
  • 3
    Would be useful hat you wrote what is "--login" for?
    – Ewoks
    Jan 9, 2018 at 2:35
  • 1
    Make bash act as if it had been invoked as a login shell (see INVOCATION below). Source
    – lony
    May 18, 2020 at 6:43
22

if it is just a temporary switch

you can use exec as mentioned above, but for more of a permanent solution.

you can use chsh -s /bin/bash (to switch to bash) and chsh -s /bin/zsh (to switch to zsh)

1
  • 2
    Mine is zsh right now but when I try chsh -s /bin/bash and type my password it show no changes made Apr 11, 2021 at 5:59
20

For Bash, try

chsh -s $(which bash)

For zsh, try

chsh -s $(which zsh)
0
8

In Mac OS Catalina default interactive shell is zsh. To change shell to zsh from bash:

chsh -s /bin/zsh

Then you need to enter your Mac password. Quit the terminal and reopen it. To check whether it's changed successfully to ssh, issue the following command.

echo $SHELL

If the result is /bin/zsh, your task is completed.

To change it back to bash, issue the following command on terminal.

chsh -s /bin/bash

Verify it again using echo $SHELL. Then result should be /bin/bash.

6

zsh has a builtin command emulate which can emulate different shells by setting the appropriate options, although csh will never be fully emulated.

emulate bash
perform commands
emulate -R zsh

The -R flag restores all the options to their default values for that shell.

See: zsh manual

1
  • 1
    Not clear though what version of bash it will emulate, will it emulate bash 4.x? or 5.x?
    – user1971598
    Aug 15, 2019 at 16:14
6

you can just type bash or if you always want to use bash:

on "iTerm2"

  • Go to preferences > Profiles > Command
  • Select "Command" from the dropdown
  • Type bash

Test by closing iTerm and open it again

0
5

Follow the below steps:

chsh -s /bin/bash
Restart terminal
Check which shell is in use: echo $SHELL
source .profile

You are back with Bash!

1
  • 1
    Users need to wait little bit before Restart terminal
    – yasin89
    Nov 23, 2022 at 10:00
4

You should be able just to type bash into the terminal to switch to bash, and then type zsh to switch to zsh. Works for me at least.

3
  • This is even simpler.
    – Cepheus
    Feb 24, 2019 at 8:37
  • 3
    This does work, but each time you type zsh or bash you are going into a sub-shell (subprocess under current shell). You will need to type exit a number of times to return to the top-most shell.
    – RichVel
    Jun 15, 2019 at 11:23
  • this is much better. Oct 3, 2022 at 21:19
1

You can achieve this also via the UI by the following steps.

Step 1: Go to Preferences -> Users & Groups

Step 2: Select the user and press the unlock button and follow by entering the password

Step 3: Right click on the user and then select Advanced Options

Step 4: Select /bin/bash as the Login Shell

enter image description here

Note: You need to restart the shell to take this into effect.

0

For me, the solution was this:

Edit:

sudo vi /etc/passwd

Find your user, for me it was for example:

ubuntu:x:1000:1001::/home/ubuntu:/bin/sh

For you it might be:

ubuntu:x:1000:1001::/home/ubuntu:/bin/zsh

And change it to:

ubuntu:x:1000:1001::/home/ubuntu:/bin/bash

If you want bash to be defaul, or the line above if you want it to be zsh by default.

-8

You can easily switch back to bash by using command "bye"

1
  • 2
    bye will exit zsh but not back to bash Jun 8, 2018 at 15:11

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