By John Papa
When running npm and node, you may find yourself getting permission errors that ultimately lead you to using `sudo` in your commands. While this helps get around the issue in the short-term, it also places stricter permissions on those installs and it becomes a slippery slope where soon you may need sudo for more than you bargained for. Also, do you really want to be using `sudo` to install npm packages?
First, we want to use the official Node.js install. I mean, its official, right? And if we don’t trust the Node folks with installing Node, then, well, what are we doing here anyway?
Next we create a folder for the global npm packages. I made mine
Then we use the
npm config command to tell npm where we want them.
Here are the steps, in detail …
Install Node.js from https://nodejs.org/en/download/
Update to the latest version of npm
npm install npm -g
Make a new folder for the npm global packages
Tell npm where to find/store them
npm config set prefix ~/.npm-packages
Verify the install
# this should show the versions node -v npm -v # this should show npm and ng with no errors npm list -g --depth=0
Handling Multiple Node Versions
What happens when a new version of node is released? What if you need version 4.4.2 for one app and 8.9.1 for another? Did you know version 9 is out now too? Yikes! it would be great if we could manage multiple versions of node on the same computer.