Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix: npm packages not installing correctly

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.

Solution 1:

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

Solution 2:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.