npm install Sanity CLI but "command not found: sanity" error
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
Install NVM by following the instructions at https://github.com/nvm-sh/nvm
Install Node.js through NVM:
nvm install 16 # or any recent version like 18, 20 nvm use 16Set the default Node version so you don't have to run
nvm useevery time you open a new terminal:nvm alias default 16Reinstall 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:
- Run
npm bin -gto find your global npm bin directory (likely something like/Users/yourusername/node_modules/.bin) - Add this line to your
~/.zshrcfile:Make sure to include theexport PATH="/Users/yourusername/node_modules/.bin:$PATH".binpart at the end! - 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 thread11 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.