You are reading the right document if you install packages with npm, e.g.:
npm i -g unicorns
and after typing unicorns -v
, you get unicorns: command not found
.
sudo chown -R $USER /usr/local
should solve the problem.
Make sure your prefix is /usr/local
, (you can check it with npm config get prefix
).
If not, you can set it with npm config set prefix /usr/local
If above method doesn’t work, set $HOME as npm’s root directory with below commands:
npm config set prefix=$HOME/node
nano ~/.bash_profile
export PATH=$HOME/node/bin:$PATH
source ~/.bash_profile
Further info:
Installing global node modules (Linux and Mac)
Command not found with a node module (NPM) solution