Global Node modules not installing correctly. Command not found

This may mean your node install prefix isn't what you expect.

You can set it like so:

npm config set prefix /usr/local

then try running npm install -g again, and it should work out. Worked for me on a mac, and the solution comes from this site:

http://webbb.be/blog/command-not-found-node-npm/

EDIT: Note that I just came across this again on a new Mac I'm setting up, and had to do the process detailed here on stackoverflow as well.


Add $(npm get prefix)/bin to your PATH (e.g., in .bashrc), like so:

echo "export PATH=$PATH:$(npm get prefix)/bin" >> ~/.bashrc

For more info, see npm help npm:

global mode: npm installs packages into the install prefix at prefix/lib/node_modules and bins are installed in prefix/bin.

You can find the install prefix with npm get prefix or npm config list | grep prefix.


My npm couldn't find global packages as well. I did what Brad Parks suggested:

npm config set prefix /usr/local

Then I got a EACCES permissions error (DON'T USE sudo npm install -g <package>) and fixed it through the official npm docs: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

  1. On the command line, in your home directory, create a directory for global installations:
 mkdir ~/.npm-global
  1. Configure npm to use the new directory path:
 npm config set prefix '~/.npm-global'
  1. In your preferred text editor, open or create a ~/.profile file and add this line:
 export PATH=~/.npm-global/bin:$PATH
  1. On the command line, update your system variables:
 source ~/.profile
  1. Then install a package globally and test it! For example:
npm install -g awsmobile-cli
awsmobile configure