Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Last active November 27, 2024 06:01
Show Gist options
  • Save derhuerst/12a1558a4b408b3b2b6e to your computer and use it in GitHub Desktop.
Save derhuerst/12a1558a4b408b3b2b6e to your computer and use it in GitHub Desktop.
Installing the Z Shell (zsh) on Linux, Mac OS X and Windows

Installing zsh on Linux

Some Linux systems come preloaded with zsh. You can check if it exists as well as its version by writing zsh --version in a terminal window. In case this zsh version is ok for you, you're done now!

Determine on which Linux distribution your system is based on. See List of Linux distributions – Wikipedia for a list. Most Linux systems – including Ubuntu – are Debian-based.

Debian-based linux systems

Open a terminal window. Copy & paste the following into the terminal window and hit Return. You may be prompted to enter your password.

sudo apt update
sudo apt upgrade
sudo apt install zsh

You can use zsh now.

Red Hat-based linux systems

Open a terminal. Copy & paste the following into the terminal window and hit Return. You may be prompted to enter your password.

sudo yum upgrade
sudo yum install zsh

Suse-based linux systems

Open a terminal. Copy & paste the following into the terminal window and hit Return. You may be prompted to enter your password.

sudo zypper upgrade
sudo zypper install zsh

You can use zsh now.

More information

How to install the zsh shell in Linux; how to set it as a default login shell

Installing zsh on a Mac

OS X comes preloaded with zsh. You can check its version by writing zsh --version in a terminal window. In case this zsh version is ok for you, you're done now!

If you want the latest and greatest, use Homebrew: Proceed with the following steps to install a recent version.

Step 1 – Install Homebrew

Open a terminal window.

Homebrew [...] simplifies the installation of software on the Mac OS X operating system.

Homebrew – Wikipedia

Copy & paste the following into the terminal window and hit Return.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor

You will be requested to install the Command Line Developer Tools from Apple. Confirm by clicking Install. After the installation finished, continue installing Homebrew by hitting Return again.

Step 2 – Install zsh

Copy & paste the following into the terminal window and hit Return.

brew install zsh

You can use zsh now.

Optional step 3 – default shell

To set zsh as your default shell, execute the following.

sudo sh -c "echo $(which zsh) >> /etc/shells" && chsh -s $(which zsh)
@sashaaldrick
Copy link

sashaaldrick commented Jun 4, 2019

Third Step on Mac gives error of: zsh
/bin/bash: echo /usr/local/bin/zsh >> /etc/shells: No such file or directory
screen shot 2017-10-30 at 9 17 56 am
Just to be clear I know that I have it installed, I was just trying to make sure that it is the default.

Try
sudo sh -c 'echo /usr/local/bin/zsh >> /etc/shells'

Thanks @agueroveraalvaro
Your command worked for me and the /etc/shells file shows the new entry for /usr/local/bin/zsh
Also i executed chsh -s /usr/local/bin/zsh command
But echo $SHELL still shows me /bin/zsh instead of /usr/local/bin/zsh
Can you please help?

I had the same issue on Mojave 10.14.5, this was resolved for me by using the answer provided by @XerxesNoble above:
chsh -s /bin/zsh

@mochadwi
Copy link

mochadwi commented Nov 19, 2019

thanks for this awesome docs

// register our zsh to the shells, idk why "sudo -s" is showing not below error on my mojave:
/bin/bash: echo /usr/local/bin/zsh >> /etc/shells: No such file or directory

// instead do register below to also avoid: "chsh: /usr/bin/zsh: non-standard shell"
sudo sh -c "echo $(which zsh) >> /etc/shells" && chsh -s $(which zsh)

Also, don't forget to re-open your terminal and re-setup all "recommended" zsh option.
Screen Shot 2019-11-19 at 4 24 07 PM

Or if you want to re-configure/forgot to configure it, you run this command below:

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

@derek-adair
Copy link

@kurianaws
Copy link

kurianaws commented May 27, 2020

Tried the OSX install script and got an error:
ruby -e "$(curl -fsSL https://raw.zshhubusercontent.com/Homebrew/install/master/install)"

curl: (6) Could not resolve host: raw.zshhubusercontent.com
replace
zshhubusercontent with githubusercontent

@DanielMarinBeltran
Copy link

Screen Shot 2021-02-28 at 10 59 41 AM

I got this error when i try to install zsh, i dont know what I should do.

@derhuerst
Copy link
Author

@DanielMarinBeltran your system seems quite mess up.

  • Your brew executable is not in your $PATH. I can see that you tried to add it, but it seems like something didn't work. Also, whenever you adapt .zshrc, you need to evaluate it again using source ~/.zshrc or (better) start a new shell/terminal. Did you even have zsh installed at that point? Because you try to install it below.
  • Homebrew/brew couldn't download ncurses (which I think is required for zsh) because the SSL/TLS versions seem to mismatch. Make sure you have an up-to-date computer.

@vanessarowe
Copy link

could someone help me please?

I downloaded home-brew and I keep trying to download ZSH but it keeps showing me this message

/Users/vanessarowe/.zshrc:source:75: no such file or directory: /Users/vanessarowe/.oh-my-zsh/oh-my-zsh.sh
vanessarowe@Vanessas-MacBook-Air ~ %

what do I do?

@derhuerst
Copy link
Author

@vanessarowe Hm, it seems your system is a bit broken as well. The error message is not related to ZSH itself but to Oh my ZSH which is a plugin system for ZSH.

Because it complains about .oh-my-zsh missing in your home directory, I assume that you don't have Oh my ZSH installed but a reference to it in the ZSH config file .zshrc.

You could remove the Oh my ZSH reference from line 75 of .zshrc in your home directory and try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment