Skip to content

macOS ZShell Installation

Set up ZSh

  1. Install zsh and zsh-completions 1:
    brew install zsh zsh-completions
    brew install zsh-syntax-highlighting

    Homebrew installs to usr/local/bin/zsh

    Check:
    which zsh outputs:
    /usr/local/bin/zsh

  2. Add the new shell to the list of legit shells:

    Note: using dscl instead of the previous procedure of adding to /etc/shells

    First check the current shell for the current user:
    dscl . -read /Users/$USER UserShell

    Then set zsh as the current user's shell:
    sudo dscl . -create /Users/$USER UserShell /usr/local/bin/zsh

    Then check that the current shell for the current user has been updated:
    dscl . -read /Users/$USER UserShell

    The above should output:
    UserShell: /usr/local/bin/zsh

    The . is short for localhost, and the $USER variable expands to your username.

    Previous solution was to add the shell to /private/etc/shells
    sudo bash -c "echo $(brew --prefix)/bin/bash >> /private/etc/shells"

    In a previous iteration of this post, I mentioned looking into /etc/shells to find out what shells your OS X knows about. It’s not necessary to view or append this file, if you’re setting your shell with dscl like we’ll do below. It seems that /etc/shells is used to specify allowable user shells for users connecting via FTP , and it used to need to be edited to include any new shells, that you were going to change to using chsh. 2

  3. Set zsh as the default shell:
    chsh -s $(which zsh)

Result:

$ ~ >> chsh -s $(which zsh)
Changing shell for ska.
Password for ska:
chsh: /usr/local/bin/zsh: non-standard shell
  1. Finally, check the name of the running process by doing echo $0. It should return -zsh.

  2. Go through the first-time tutorial/setup

This is the note generated for future use:

The function will not be run in future, but you can run it yourself as follows:
autoload -Uz zsh-newuser-install
zsh-newuser-install -f

The code added to ~/.zshrc is marked by the lines:
# Lines configured by zsh-newuser-install
# End of lines configured by zsh-newuser-install
You should not edit anything between these lines if you intend to run zsh-newuser-install again. You may, however, edit any other part of the file.

Set up Oh-My_Zsh

  • Run the script
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Result (note for future ref in case needed)

This is the note generated in the terminal:

Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /Users/ska/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.

        __                                     __
____  / /_     ____ ___  __  __   ____  _____/ /_
/ __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!

Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us on https://twitter.com/ohmyzsh

p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh
  • Edit the config file .zshrc to set some defaults

References