Command Line: z is installed but can't find the command

11,089

Solution 1

One can inspect the list of files installed by a Homebrew formula via brew list -f <formula_name>. In this case, the output should like

> brew list -f z
/usr/local/Cellar/z/1.9/etc/profile.d/z.sh
/usr/local/Cellar/z/1.9/INSTALL_RECEIPT.json
/usr/local/Cellar/z/1.9/README
/usr/local/Cellar/z/1.9/share/man/man1/z.1

Note that in this case there's no command (and not even bin), just a z.sh. This makes sense because z is a shell tool, and have to be sourced into the shell as functions to get and set the shell environment; running as an external command simply doesn't offer deep enough integration. Therefore, you have to source z.sh into your shell, probably in .bash_profile, .bashrc, or .zshrc.

Usually, Homebrew formulae that require post-installation interactions in order to be usable will have instructions listed in caveats, which will be shown post-install, or manually retrieved via brew info <formula_name>. In this case,

> brew info z
<irrelevant info omitted>
==> Caveats
For Bash or Zsh, put something like this in your $HOME/.bashrc or $HOME/.zshrc:
  . `brew --prefix`/etc/profile.d/z.sh

Of course you should take that advise with a grain of salt, and use more modern and human-readable shell syntax:

source "$(brew --prefix)/etc/profile.d/z.sh"

Or

source /usr/local/etc/profile.d/z.sh

if you know your Homebrew installation is in /usr/local.

Solution 2

in Mac osx with iterm2 with zsh just put:

First:

vim ~/.zshrc

and add this line (or just add z)

plugins=(
    git
    z
)

exit with

:x!

that's it.

Share:
11,089

Related videos on Youtube

Fabio Bracht
Author by

Fabio Bracht

Updated on September 18, 2022

Comments

  • Fabio Bracht
    Fabio Bracht over 1 year

    I recently installed iTerm2 and ZSH (with oh-my-zsh) after some months of very light usage of the stock Terminal on Mac OS.

    I heard of a tool called "z" and installed it via brew with brew install z. I used it for one night with no problems. Later on it stopped working, saying zsh: command not found: z. I tried installing it again, and was met with Warning: z-1.8 already installed.

    How does this make sense? It's installed but the command is not found? How could I go about restoring this functionality?

    Thanks!

    • 4ae1e1
      4ae1e1 over 8 years
      brew list -f z to see all files installed for the z formula.
    • Fabio Bracht
      Fabio Bracht over 8 years
      I'm sorry, but what do I do with the result of this command? How is this useful for me?
    • 4ae1e1
      4ae1e1 over 8 years
      In fact, if you run the command I gave you, you'll see that no such command as z is installed. You'll have /usr/local/Cellar/z/1.9/etc/profile.d/z.sh (or 1.8 in your case; you appear to have outdated formula definitions). You should follow the caveats sections of brew info z, which says For Bash or Zsh, put something like this in your $HOME/.bashrc or $HOME/.zshrc: . `brew --prefix`/etc/profile.d/z.sh.
    • 4ae1e1
      4ae1e1 over 8 years
      Oh, by the way you shouldn't use that obsolete syntax. Replace that brew --prefix with /usr/local, or at least wrap it in $() instead.
    • Fabio Bracht
      Fabio Bracht over 8 years
      Thanks! This worked for me! If you'd like to post this as an actual answer instead of a comment, I will certainly upvote and accept as the correct answer.
    • 4ae1e1
      4ae1e1 over 8 years
      Sure, will try to expand into a potentially useful answer.
  • Fabio Bracht
    Fabio Bracht over 8 years
    Looks like it's already added. When I echo my $PATH, I get /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/‌​bin, it seems like in there.
  • 4ae1e1
    4ae1e1 over 8 years
    P.S. By "more modern and human-readable shell syntax" I'm comparing to the POSIX shell... Unfortunate folks writing shell-agnostic shell tools are stuck to POSIX, but the rest of us who know we're using something better don't have to conform to that.
  • Scott - Слава Україні
    Scott - Слава Україні about 5 years
    Put it where?  Type it?  When?  Every time you login?  What does it do?    Please do not respond in comments; edit your answer to make it clearer and more complete.