2

I am using ZSH with oh-my-zsh on OS X.

Today I used hombrew to update to the latest version of git (1.8.something).

However, if I run

➜  ~  git --version
git version 1.7.10.2 (Apple Git-33)

I see that still an older version is used. On bash everything works fine and the latest version of git is called.

Since I am new to ZSH, any advice on how to set up ZSH to use the "new" git is appreciated!

Best,

Tobi

tacaswell
  • 84,579
  • 22
  • 210
  • 199
tobias.henn
  • 225
  • 2
  • 13

3 Answers3

6

This means that your $PATH variable isn't set up to include the right git (and everything else homebrew installs).

Try doing echo $PATH from both bash and zsh. You should see at least one difference: the directory where you installed homebrew, probably /usr/local/bin. (It'll either not be in there, or be after /usr/bin, where the Apple-supplied binary lives.)

To fix it, add a line like

export PATH=/usr/local/bin:$PATH

to your ~/.zshenv.

Danica
  • 28,423
  • 6
  • 90
  • 122
3

If the PATH modification didn't instantly work, you need to realize that with zsh you need to type "rehash" for zsh to recognize there are new executables in the path. Or just log out and back in.

Kalle Pokki
  • 4,939
  • 2
  • 17
  • 18
  • Thanks for the comment! I also tried your method and even rebooted several times, but so far my additions to ~/.zshenv seem to be ignored. – tobias.henn Feb 13 '13 at 10:25
  • @tobias.henn What does `echo $PATH` say? Does it completely exclude everything you put in .zshenv? If you set it manually, like `export PATH=/usr/local/whereyourgitis:$PATH`, `rehash`, replacing the path with the path you installed new version of git to, does it then run the correct version? – Kalle Pokki Feb 13 '13 at 12:29
  • FWIW: `rehash` doesn't actually change the binary that gets called when you type e.g. `git`, it just changes what zsh knows about to do auto-completion and whatnot. – Danica Feb 17 '13 at 06:58
  • 1
    @Dougal That's not true. Zsh hashes the available executables, and this is done again with the rehash command, see http://zsh.sourceforge.net/Guide/zshguide03.html – Kalle Pokki Feb 17 '13 at 14:51
  • Hmm, interesting. I suppose the times I've thought were it running without the hash table we're actually when it wasn't in the dictionary at all. – Danica Feb 17 '13 at 18:05
  • Neither adding `/usr/local/git/bin/git`, the correct path used in bash, nor typing `rehash` afterwards helps. Rebooting and typing `git --version` still shows `git version 1.9.3 (Apple Git-50)`. What else could be the problem? – Eekhoorn Dec 27 '14 at 13:14
1

Compare the outputs of which git (and the outputs of echo "$PATH") in bash and zsh.

The directory containing an up-to-date git is probably not present in $PATH variable for zsh, but it is in bash. It's likely caused by $PATH items being added in your ~/.bashrc and/or ~/.bash_profile file, which zsh doesn't source on startup. If it's so, add the same assignment to PATH to your ~/.zshrc

Anton Kovalenko
  • 20,999
  • 2
  • 37
  • 69
  • 1
    Well, we gave basically the same answer at the same time :) – except that `.zshenv` is preferable to `.zshrc`, since the latter only runs in interactive shells. – Danica Feb 12 '13 at 06:36