Kiến Thức Linux

How to Switch from Zsh to Bash on Mac

Introduction

Zsh replaced Bash as macOS’s default terminal shell in macOS Catalina. While Zsh is in many ways superior to Bash, thanks to its floating-point support, hash data structures, customization options, etc., there are still use cases where Bash may prove helpful in the macOS terminal.

This article teaches you how to switch to Bash from Zsh on macOS using CLI and System Settings.

How to switch from zsh to bash on macOS.

Prerequisites

  • macOS Catalina or later.
  • Administrative access to the system.

How to Check What Shell Mac Is Using?

If you are unsure about which shell you are using, open the terminal application and enter the following ps command:

ps -p $$

The output shows the active shell process. The CMD column shows the name of the currently running shell.

The ps command displaying the process related to the currently running shell.

How to Change Zsh to Bash on Mac?

Change the default terminal shell in macOS using the CLI or the System Preferences GUI. The following sections explain both methods.

Via Terminal

Using the terminal to switch from Zsh to Bash on macOS is a short and straightforward procedure.

Follow the steps below to replace Zsh with Bash:

1. View the list of available shells on the system by typing:

cat /etc/shells

2. Find and note the path to the Bash executable in the list. Most often, the default Bash path is /bin/bash.

Viewing the list of available shells on macOS.

3. Use the chsh command to change the currently running shell:

chsh -s [path-to-bash]

4. Enter the administrative password when prompted.

Changing the shell to Bash in macOS.

5. Exit the terminal by entering:

exit

Next time you open the terminal, the Bash prompt appears alongside a warning stating that Zsh is the default shell.

Bash shell showing up in the macOS terminal.

Via System Settings

The System Settings app allows users to access all the critical system configuration options in one place. Follow the steps below to change the terminal shell using System Settings.

1. Click the Apple logo, then select System Settings in the menu.

Finding System Settings on macOS.

2. Select the Users & Groups section in the menu on the left side of the window.

3. Hold the Control key and select your user to show the Advanced Options item. Select the item to access more user-related options.

Finding advanced user options in System Settings on macOS.

4. Type your password to confirm the administrative privileges for your user and select Unlock.

Providing administrative access password for the advanced user options.

5. Expand the list of available shells and select the /bin/bash option. Confirm the selection by clicking OK.

Selecting Bash from the list of the available shells in System Settings.

Open the terminal and confirm that it is now running Bash.

How to Update Bash on Mac?

By default, macOS provides an outdated Bash version (Bash 3.2.57 from 2007). If you wish to install the newest version of Bash, use the Homebrew package manager. Follow the steps below to install Bash with Homebrew.

1. Update and upgrade your Homebrew formulae:

brew upgrade

2. Install the Bash Homebrew formula:

brew install bash
Installing Bash with Homebrew.

3. Reload the shell with the exec command:

exec bash

4. Add the Bash Homebrew installation path to the list of available shells:

echo $(brew --prefix)/bin/bash | sudo tee -a /private/etc/shells
Adding the Homebrew version of Bash to the list of available shells in macOS.

5. Change the default shell with the chsh command:

chsh -s [path-to-bash]
Changing the shell to the Homebrew version of Bash in macOS.

Conclusion

The article showed you how to switch from Zsh to Bash shell on macOS. It also provided instructions on how to ensure your system runs the latest Bash version.

If you plan to use Bash to run scripts, check out our Bash script tutorial.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !