Mac – Install NPM / Nodejs without sudo or root

I don’t like to use sudo/root while installing third party softwares. I ran into issues while installing nodejs. Then I found a nice article which takes cares of this issue.

npm installs packages locally within your projects by default. You can also install packages globally (e.g. npm install -g ) (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

mkdir “${HOME}/.npm-packages”

2. Reference this directory for future usage in your .bashrc/.zshrc:


3. Indicate to npm where to store your globally installed package. In your $HOME/.npmrc file add:


4. Ensure node will find them. Add the following to your .bashrc/.bash_profile:


5. Ensure you’ll find installed binaries and man pages. Add the following to your .bashrc/.zshrc:


unset MANPATH # delete if you already modified MANPATH elsewhere in your config

source ~/.bashrc

Source: Original Article

Leave a comment

Your comment