Skip to content

Instantly share code, notes, and snippets.

@eszterkv
Last active October 17, 2016 15:26
Show Gist options
  • Save eszterkv/f653bd485368fdcb166a115e45dd6073 to your computer and use it in GitHub Desktop.
Save eszterkv/f653bd485368fdcb166a115e45dd6073 to your computer and use it in GitHub Desktop.
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