Search Icon, Magnifying Glass

Marmanold.com

Graduation Cap Heart Question Mark Magnifying Glass

Migrate from Bash to Z Shell (On macOS)

In macOS Catalina, Apple is switching the default shell to Z Shell from Bash. Even if you haven’t upgraded to Catalina yet, getting used to Zsh is a good idea and pretty simple to do.

1. Install Latest Z Shell

First, install the latest verison of Z Shell from Hombrew. Since you’re going down the path of learning an alternate shell, you might as well keep on the newest version instead of just taking whatever Apple gives you.

brew install zsh

2. Set Z Shell to Default Shell

Once you’ve got Z Shell installed, you have to set macOS to us it as the default. Run the following commands in bash and you’ll be on your way.

The first command adds the custom path to /etc/shells so that it will be allowed by the chsh command. The second command actually changes your default shell to Zsh.

sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)

Open a new terminal window and you should find yourself in Zsh instead of Bash.

3. Install Fira Fonts

This is totally optional, but if you plan on using a Oh My ZSH theme that uses Powerline, you’re going to want a font that supports it. I use Fira Code in my IDEs, so it makes sense for me in the terminal. YMMW.

brew tap homebrew/cask-fonts
brew cask install font-fira-mono-for-powerline

4. Install Oh My ZSH

Run the following to install Oh My ZSH.

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

5. Set a Z Shell Theme

Angoster is a theme I like, but more can be found here. Make sure to set DEFAULT_USER if you don’t want to see your username in the terminal in many themes.

In .zshrc set:

ZSH_THEME="agnoster"
DEFAULT_USER=`whoami`

6. Install Useful Plugins

All the plugins can be found here. These, below, are a few that I like to have installed. All you have to do is set plugins in the .zsh configuration file.

plugins=(git copyfile cpanm extract osx web-search)

7. Update Conda Environment

If you use Conda to manage your Python environments, you can update it to work with Z Shell by running the following.

If you’ve already opened a session in zsh, you’ll have to launch a bash session to run these commands.

The first command updates Conda to the newest version. Older versions don’t have the conda init command, so you really need to do this. The second command makes Conda ready to use with Zsh. The third command is totally optional, but it gets rid of the annoying (base) at the front of your terminal prompt. The downside to this is that you’ll revert to system Python, so use with caution.

conda update conda
conda init zsh
conda config --set auto_activate_base false

That’s it. All-in-all it just takes a few minutes to get up and running with Z Shell. Once you’re up and running to check out the many plugins and themes available. Just a few weeks in to Z Shell I’m wondering why I didn’t switch sooner.