Using 'npm install' without Sudo

Mandy Sidana
May 14, 2016 · 1 min read

Npm packages installs should be done without sudo. Infact sudo should be never be used unless tinkering with system wide permissions. Node puts npm packages in a specific folder, usually /usr/local/lib/node_modules. But the trouble is you need sudo permissions to write here. This leads to an endless use of non-requisite sudo permissions. This location is what we need to change and here are handy terminal commands to achieve the same

mkdir ~/.npmnpm config set prefix ~/.npmnano ~/.bashrcexport PATH="$PATH:$HOME/.npm/bin"source ~/.bashrc

Complete guide by NPM can be found here :

For OsX, this is a well written guide:

Mandy Sidana

Written by

Product manager. Building Analytics related technology products. Part time Startup consultant. Blockchain enthusiast.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade