CLI Error - zsh: command not found
This is a classic PATH issue with npm global installations. The zsh: command not found: sanity error means your terminal can't find the globally installed Sanity CLI binary. Here's how to fix it:
Quick Fix
The most reliable solution is to use NVM (Node Version Manager) as it properly manages your PATH configuration:
- Install NVM if you haven't already:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash- Install Node through NVM:
nvm install 16 # or whatever version you prefer
nvm use 16- Set default Node version:
nvm alias default 16- Reinstall Sanity CLI:
npm install -g @sanity/cliThis should resolve the issue permanently for all new terminal sessions.
Alternative: Manual PATH Fix
If you prefer not to use NVM, you need to add npm's global bin directory to your PATH:
- Find your npm bin path:
npm bin -g- Add it to your
.zshrc(note the.binat the end):
export PATH="/Users/yourusername/node_modules/.bin:$PATH"- Reload your shell:
source ~/.zshrcUsing npx as a Workaround
While fixing your PATH, you can always run Sanity commands using npx:
npx -y sanity@latest [command]The NVM approach is recommended because it handles all the PATH configuration automatically and avoids permission issues with global npm installations. Based on the Sanity CLI documentation, this is a common setup issue that's typically resolved by proper Node.js environment configuration.
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.