Kevin Suttle
Kevin Suttle

Reputation: 8489

What is the definitive way to install/upgrade/set the default version of ZSH?

OSX Mountain Lion ships with ZSH 4.3.1 in /bin/zsh. After downloading, ./configure, make, make check, and make install-ing version 5.0.0,

which zsh still returns /bin/zsh/

and zsh --version still returns zsh 4.3.11 (i386-apple-darwin12.0)

Items of note to help answerers:
I had no errors running the install commands.

In /usr/local/bin, I have these 3 files:
-rwxr-xr-x 2 kevinsuttle admin 622K Aug 20 00:59 zsh
-rwxr-xr-x 2 kevinsuttle admin 622K Aug 20 00:59 zsh-5.0.0
-rwxr-xr-x 1 kevinsuttle admin 622K Aug 20 00:50 zsh.old

My $PATH
$ echo $PATH
/Users/kevinsuttle/.rbenv/shims:/Users/kevinsuttle/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

Questions I need answered:
1. What is the cleanest way to install ZSH? (From git, homebrew, curl-ing source?)
2. Does it matter where you run the install commands?
3. How do I upgrade or override the version of ZSH that ships with Mountain Lion?
4. Is this why people end up using oh-my-zsh?

Upvotes: 27

Views: 16960

Answers (4)

essjar
essjar

Reputation: 1

In the past, the solution I came up with for this type of upgrade was roughly as follows:

  • Install the newer version somewhere ( in my case the default for fink /sw/bin )
  • Rename the OS-installed version in /bin /bin/zsh => /bin/zsh.moved
  • Set up a symlink in /bin to the /sw/bin/zsh installation

This seemed to work.

Upvotes: 0

rodeinator
rodeinator

Reputation: 711

You have to set your default shell in OSX with:

chsh -s /usr/local/bin/zsh $USER

Relogin to OSX and it should work!

Homebrew way

I recommand you to use homebrew. It makes things much easier. Install homebrew, like described on Link .

Homebrew installs your stuff in /usr/local/bin, so make sure /usr/local/bin comes before /usr/bin .

Add the following line in ~/.zshrc and ~/.bashrc :

PATH="/usr/local/bin:/usr/local/sbin:$PATH"

Install zsh:

brew install zsh

Set your default shell to zsh:

chsh -s /usr/local/bin/zsh $USER

Finally set permission to use zsh from brew installation. Add "/usr/local/bin/zsh" to "/etc/shells" file to allow zsh. Else you'll get an error "You are not authorized to run this application. The administrator has set your shell to an illegal value."

echo "/usr/local/bin/zsh" | sudo tee -a /etc/shells

I recommand to fix the zsh environment bug in OSX. Rename /etc/zshenv to /etc/zshrc

sudo mv /etc/{zshenv,zshrc}

Relogin to OSX and it should work!

If you have trouble, type:

brew doctor

Upvotes: 49

Burhan Khalid
Burhan Khalid

Reputation: 174682

I will attempt to answer your questions, but I have a feeling this is better suited for superuser

What is the cleanest way to install ZSH? (From git, homebrew, curl-ing source?)

Acquiring the source however you want; but the cleanest way would be to create a private bin, I like /Users/burhan/bin/, and install things there. This is, in my opinion, the cleanest and simplest way since you don't need to rely on other libraries/installers/magic.

Does it matter where you run the install commands?

No, it does matter what arguments you give the commands - especially the target installation location and path to libraries. If you don't provide these (or set them in the environment before hand), the installer will place items in the default system paths; and to do that you need to run the installer with elevated permissions ie, with sudo or while logged in as root.

How do I upgrade or override the version of ZSH that ships with Mountain Lion?

I would recommend against upgrading it; simply because I am not sure what side effects it will have on the various other scripts that are expecting to it to ship with the advertised version. For your sanity, I would avoid this.

Instead, if you build and install it into a private bin and point your PATH appropriately; you can use the updated version without modifying the shipped version.

Upvotes: 2

Kevin Suttle
Kevin Suttle

Reputation: 8489

OK, so Burhan's comment reminded me of a situation where I had to explicitly add the path of the preferred version to my .bash_profile. Version 5.0.0 is in /usr/local/bin, so now the $PATH in my .bash_profile looks like so:

export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"

and now when I run which zsh, I get /usr/local/bin/zsh
and zsh --version returns zsh 5.0.0 (x86_64-apple-darwin12.0.0).

Woot! Hopefully this helps someone who is having the same problem.

Upvotes: 3

Related Questions