'Attempting to use Sanity.io CLI results in 'zsh: command not found'

I am having a problem running Sanity's CLI. I have installed the CLI with npm install -g @sanity/cli which works without a problem, and everything is installed correctly (as far as I can tell).

However, trying to use any of their CLI instructions, such as sanity init, I get this error message:

zsh: command not found: sanity

I am using npm version 6.14.11 and node version v14.16.0.

I've also been noticing a few random commands return the same zsh: command not found for various packages.



Solution 1:[1]

with npx it works

npx @sanity/cli init

Solution 2:[2]

@user1934428 is right.

I just change in the command "sanity ..." to "usr/local/Cellar/node/16.3.0/lib/node_modules/@sanity/cli/bin/sanity ..." and it worked

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kabir
Solution 2 João Macedo