npm install Sanity CLI but "command not found: sanity" error

11 replies
Last updated: Jan 28, 2026
Hello everyone, I just can’t get the sanity cli up and running.
After typing in

npm install -g @sanity/cli
I only get the following output

changed 1 package, and audited 2 packages in 2s

found 0 vulnerabilities
after typing in
sanity
I get the following error message
zsh: command not found: sanity
AI Update

This is a common issue on macOS with zsh! The problem is that npm's global binary directory isn't in your $PATH environment variable, so your shell can't find the sanity command.

Based on this community discussion about the exact same issue, the recommended solution is to use NVM (Node Version Manager) to manage your Node.js installation.

The Solution: Use NVM

  1. Install NVM by following the instructions at https://github.com/nvm-sh/nvm

  2. Install Node.js through NVM:

    nvm install 16  # or any recent version like 18, 20
    nvm use 16
  3. Set the default Node version so you don't have to run nvm use every time you open a new terminal:

    nvm alias default 16
  4. Reinstall the Sanity CLI:

    npm install -g @sanity/cli

Now the sanity command should work in any new terminal window!

Why This Happens

When you install Node.js directly (not through NVM), the npm global binary path sometimes doesn't get properly added to your shell's $PATH. This is especially common on macOS with zsh. NVM handles this path configuration automatically and also makes it easier to manage multiple Node.js versions.

Alternative Quick Fix (Without NVM)

If you prefer to stick with your current Node.js installation, you can manually add the npm bin directory to your PATH:

  1. Run npm bin -g to find your global npm bin directory (likely something like /Users/yourusername/node_modules/.bin)
  2. Add this line to your ~/.zshrc file:
    export PATH="/Users/yourusername/node_modules/.bin:$PATH"
    Make sure to include the .bin part at the end!
  3. Restart your terminal or run source ~/.zshrc

However, using NVM is generally more reliable and is the approach recommended by the Sanity community for avoiding these types of PATH issues. Note that Sanity Studio v4 requires Node.js 20 or higher, so you'll want to use a recent Node version anyway.

Show original thread
11 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?