Skip to content

Instantly share code, notes, and snippets.

@JimJafar
Created December 10, 2014 22:02
Show Gist options
  • Save JimJafar/d0c11eda77eccc127fc6 to your computer and use it in GitHub Desktop.
Save JimJafar/d0c11eda77eccc127fc6 to your computer and use it in GitHub Desktop.
# before you begin, I suggest you get a list of your globally installed packages so you know what to reinstall later:
npm list -g --depth=0
# /usr/lib
# ├── bower@1.3.12
# ├── grunt-cli@0.1.13
# ├── gulp@3.8.10
# ├── npm@1.4.28
# └── yo@1.3.3
# tell npm to install packages to home (instead of /usr/lib or /usr/local depending on your OS)
npm config set prefix ~/npm
# now you need to update your path environment variables
# open your .bashrc or .bash_profile file for editing
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
# check to see if anything is owned by root:
ls -la ~/.npm
# take ownership of everything in your ~/.npm directory (must be run with sudo):
sudo chown -R $USER:`id -g -n $USER` ~/.npm
# now you can reinstall all your global packages - no sudo necessary :)
npm install -g bower
npm install -g grunt-cli
npm install -g gulp
npm install -g yo
# etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment