Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Last active May 13, 2023 17:56
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)
@neo
Copy link

neo commented Nov 16, 2016

Windows 10 now has bash which makes the it easier.

@elliott-beach
Copy link

elliott-beach commented Jan 26, 2017

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

@yuseferi
Copy link

And also for me

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

@yuseferi
Copy link

@e-beach

brew install zsh
then
sudo -s 'echo /usr/local/bin/zsh >> /etc/shells' && chsh -s /usr/local/bin/zsh

Worked for me
Now I have zsh :)

@vjyanand
Copy link

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

@ilhamdoanggg
Copy link

i was installed a git bash on windows and can i change git bash with zsh themes?

@rueTH
Copy link

rueTH commented May 15, 2017

@e-beach @zhilevan
I encountered that very same issue! For me, it was quickly resolved, though:
Prior to pasting the above into the terminal, I had used:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-- meaning I had installed Homebrew according to the instructions on their actual site. It appears that version and the version instructed above are just two different roads leading to the same destination. As was the case for me, there's a chance you may already have a version of Homebrew installed.
I have only been diving into the dev game since the start of the year (and until today was only familiar setting things up on PC/Linux), so rather than potentially leading you astray, I suggest you check out https://brew.sh/ for guidance on all things Homebrew.

Or, if you are the reckless or impatient sort, you can do what I did and press on by entering brew doctor into the terminal. If you have Homebrew already, it should be immediately evident. Boom.

**ATTN: I am no seasoned vet, and I hope those more knowledgable will correct any misinformation I have supplied & elaborate on the rest!

@mscheel
Copy link

mscheel commented May 27, 2017

@derhuerst Mac instructions require updating, see: https://gist.github.com/mscheel/1c8e956d0b842ff42551a60b99cdf303 for revisions, thanks for putting this together. The revised instructions work for me on Sierra.

@a2ron
Copy link

a2ron commented Sep 20, 2017

$ ruby -e "$(curl -fsSL https://raw.zshhubusercontent.com/Homebrew/install/master/install)"
curl: (6) Could not resolve host: raw.zshhubusercontent.com

@gprestes
Copy link

How to install on Mac:

  • Install Brew (https://brew.sh)
    Double check it before, but as of now the command is: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • brew install zsh
  • Profit

@polyglotdev
Copy link

polyglotdev commented Oct 30, 2017

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.

@NemanjaMandic
Copy link

This is not working on Mac:
curl: (6) Could not resolve host: raw.zshhubusercontent.com

@larsenwork
Copy link

@derhuerst Shouldn't it be githubusercontent instead of zshhubusercontent?

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

@drewlustro
Copy link

Yep. zshhubusercontent is a typo.

Also @TheDom1's note is true too... I got the same error.

@XerxesNoble
Copy link

Installing on macOS High Sierra

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

# Install zsh
$ brew install zsh

# (optional) set default shell
$ chsh -s /bin/zsh

# Verify, open new terminal
$ echo $SHELL

@mhsaghatforoush
Copy link

thanks

@dayaki
Copy link

dayaki commented Jan 8, 2019

Thanks @XerxesNoble yours work for me

@agueroveraalvaro
Copy link

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'

@jagdishadusumalli
Copy link

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?

@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