An issue that I’ve run into is that root privileges are required to install packages globally. Judging by a quick stackoverflow search, I’m not the only one! Solutions that are suggested include installing node through nvm (Node Version Manager), but the github repo for that notes that the build is failing… not a positive sign.
A better solution is to change the directory that npm installs the global packages into, to one that the user already has privileges.
This guide walks through the process of doing this. I’ve reiterated it here to help stave off link rot.
npm installs packages locally within your projects by default. You can also install packages globally (e.g.
npm install -g <package>) (useful for command-line apps). However the downside of this is that you need to be root (or use
sudo) to be able to install globally.
Here is a way to install packages globally for a given user.
1. Create a directory for your global packages
2. Reference this directory for future usage in your
3. Indicate to
npm where to store your globally installed package. In your
$HOME/.npmrc file add:
node will find them. Add the following to your
5. Ensure you’ll find installed binaries and man pages. Add the following to your
PATH="$NPM_PACKAGES/bin:$PATH" # Unset manpath so we can inherit from /etc/manpath via the `manpath` # command unset MANPATH # delete if you already modified MANPATH elsewhere in your config MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
NOTE: If you are running OS X, the
.bashrc file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as
.bash_profile. These files also reside in the user’s home folder. In this case, simply adding the following line to them will instruct Terminal to also load the