Yes, since macOS Catalina (released in October 2019), the default interactive shell for new user accounts is zsh (Z shell), replacing bash. This change applies to macOS only; most Linux distributions still default to bash, though zsh is available as an installable option.
Why Apple Switched to zsh
Apple moved to zsh primarily because of licensing. Bash versions newer than 3.2 are licensed under the GNU General Public License version 3 (GPLv3). Apple had shipped bash 3.2 (under GPLv2) and did not want to adopt GPLv3, which has stricter copyleft requirements. zsh is licensed under the MIT-like license, which is more permissive and aligns with Apple’s distribution model.
Additionally, zsh offers features that many users find superior: better tab completion, spelling correction, shared command history, and a rich theming/plugin ecosystem (e.g., Oh My Zsh). While these features existed long before the switch, the licensing factor was the decisive one.
How to Check Your Current Shell
To see which shell you are currently using in a terminal, run:
echo $SHELL
This prints the login shell (e.g., /bin/zsh or /bin/bash). To see the default shell for new users on a system, you can check the /etc/passwd file or use the dscl command on macOS. On Linux, the default is typically bash, but you can verify with getent passwd $(whoami).
How to Change Your Default Shell
If you prefer bash or want to try zsh on a system where it is installed, you can change your default shell with the chsh command. The syntax is the same on macOS and Linux:
chsh -s /bin/zsh
Replace /bin/zsh with the full path to your desired shell. You may need to log out and back in for the change to take effect. To list available shells, run cat /etc/shells.
On macOS, if you want to revert to bash (which is still present but older), you can use chsh -s /bin/bash. Note that bash 3.2 lacks many features of newer bash versions, so you might prefer installing a newer bash via Homebrew and then pointing chsh to that path.
Key Differences Between zsh and bash
While zsh is largely compatible with bash, there are notable differences that can affect your scripts and interactive usage:
- Array indexing: bash arrays start at index 0, zsh arrays start at index 1 by default. This is a common source of off-by-one errors.
- Prompt customization: zsh uses
PS1but also hasPROMPTand more advanced prompt expansion (e.g.,%dfor directory). - Globbing: zsh supports recursive globbing (
**/*.txt) without needingglobstarenabled, which bash requires. - Autocorrection: zsh can suggest corrections for mistyped commands if you enable
setopt correct. - Shared history: zsh can share history across multiple terminal sessions instantly with
setopt sharehistory.
For scripting, bash is still more universally used, so if you write portable scripts, test them in bash. zsh is excellent for interactive use due to its completion and customization.
Common Problems and How to Solve Them
Switching to zsh can cause a few issues, especially if you have existing bash configurations:
- Missing aliases and functions: Your
.bashrcor.bash_profilesettings do not apply to zsh. You need to migrate them to.zshrc. Copying the content often works, but some bash-specific syntax may need adjustment. - PATH environment variable: If your PATH was set in
.bash_profile, it won’t be loaded in zsh. Add the same export lines to.zshrc. - Scripts that use
#!/bin/bash: These still work because they invoke bash explicitly, regardless of your interactive shell. Only interactive commands are affected. - Oh My Zsh performance: If you install Oh My Zsh, it can slow down terminal startup. Disable unused plugins or use a lighter framework.
If you encounter errors like command not found after switching, check that your PATH is correctly set in .zshrc.
Should You Switch to zsh?
If you are on macOS, you are already using zsh by default. On Linux, you can choose. Consider zsh if you want:
- Better autocompletion (especially for git and other tools).
- Spelling correction for commands.
- Extensive theming (e.g., powerlevel10k).
- Plugin management via Oh My Zsh or Antigen.
Stick with bash if you:
- Write many portable shell scripts.
- Prefer minimal configuration.
- Work on servers where bash is the default and you don’t want to install extra packages.
Both shells are powerful; the choice is mostly about workflow preference.
zsh vs. Other Shells (fish, dash, etc.)
zsh is not the only alternative to bash. Fish (Friendly Interactive SHell) offers out-of-the-box autosuggestions and a more user-friendly syntax, but it is not POSIX-compliant, so many bash scripts won’t run without modification. Dash is a lightweight, POSIX-compliant shell used as /bin/sh on Debian-based systems for faster script execution. For interactive use, zsh is often favored over fish because it is closer to bash, making the transition easier.
Frequently Asked Questions
Is zsh backwards compatible with bash?
Mostly, but not perfectly. zsh can run most bash scripts if you set emulate sh or emulate bash, but some features like [[ ]] and source work, while arrays and certain expansions differ. For critical scripts, test them in zsh or keep the shebang as #!/bin/bash.
Will my .bashrc work in zsh?
No, zsh reads .zshrc instead. You can copy the contents of .bashrc to .zshrc, but some bash-specific syntax may cause errors. It’s safer to manually migrate the parts you need.
Does zsh slow down my terminal?
Plain zsh is fast. However, if you use Oh My Zsh with many plugins, startup time can increase. You can measure startup time with time zsh -i -c exit and optimize by disabling unused plugins.
How do I set zsh as the default shell on Linux?
Install zsh with your package manager (e.g., sudo apt install zsh on Debian/Ubuntu), then run chsh -s $(which zsh). Log out and back in for the change to take effect.
Can I still use bash after switching to zsh?
Yes, you can always type bash to start a bash session, or run scripts with bash script.sh. Your default shell only affects new terminal sessions.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It