Installing npm packages global on OSX
October 4, 2015
Quick guide to install node and npm globally and avoid using sudo to install npm packages.
We’ll be using the Z shell (zsh) instead of bash. Replace any reference to .zshrc
with .bash_profile/.bashrc
in case you are running on bash instead.
Install Node
We’ll install node via homebrew. If you have Node installed already via brew, remove it, then:
Install NPM
Create a directory for your global packages.
Add a reference to the directory into zshrc
Tell NPM where to install global packages (in our case ~/.npm-packages)
Install the latest version of NPM
Add the following lines to your .zshrc to be ensure that node will find the packages and that you’ll find the installed binaries:
To verify if everything installed successfully just run the following commands:
Enjoy! You should now be able to install npm modules globally without having to use sudo!