Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with installing and running Sanity CLI, resolved by using NVM.

11 replies
Last updated: Dec 19, 2021
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
Dec 19, 2021, 10:08 AM
Looks like your npm binary path is not part of
$PATH
indeed.
Not sure how familiar you are with node and npm, but I tend to recommend that people use a node versioning manager like NVM (
https://github.com/nvm-sh/nvm ).
Anyway, you should be able to run
npm bin
to see the path that you need to add to your
$PATH
. Temporarily you could do something like:

export PATH=$(npm bin):$PATH
Which should fix it for the current terminal session. Or you can add it to your shell environment for a more long-term solution. (This is usually taken care of during the node.js installation process, though)
Dec 19, 2021, 10:21 AM
If I run
npm bin
I get the response
/Users/henryauffahrt/node_modules/.bin

I put in my .zshrc file the following line
export PATH="/Users/henryauffahrt/node_modules/:$PATH"

But the errors stay the same
Dec 19, 2021, 10:32 AM
I just installed nvm as you recommend. But the error stays the same 😞
Dec 19, 2021, 10:38 AM
But running
/Users/henryauffahrt/node_modules/.bin/sanity
works?
Dec 19, 2021, 11:43 AM
I complete throw away my ~/.zshrc config.. it was a mess build up over the years. I also throw away my oh-my-zsh folder. And build up everything new. Currently try to install sanity cli but get an EACCES error. But I don’t want to install it as superuser. Found this documentation to solve it: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
Dec 19, 2021, 11:56 AM
There I found this information in the very beginning “Reinstall npm with a node version manager (recommended),”
The same you recommend me. I already installed nvm. But my current session is not using npm over nvm… after type in
nvm use 16
it works!
Dec 19, 2021, 11:58 AM
But I’m wondering how could I make sure in a new terminal windows session that it will use the nvm version as default?
Dec 19, 2021, 11:58 AM
also on a new terminal windows I need to type in
nvm use16
before I can use
sanity
Dec 19, 2021, 12:00 PM
This is the solution:
nvm alias default 16
Dec 19, 2021, 12:01 PM
Ah, ok. Glad you got it figured out!
Dec 19, 2021, 12:08 PM
Thanks for your help
user Z
!
Dec 19, 2021, 12:20 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?