Skip to content

Instantly share code, notes, and snippets.

@jamiekurtz
Last active April 25, 2016 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiekurtz/31fc0b6ff55acf52f2d0 to your computer and use it in GitHub Desktop.
Save jamiekurtz/31fc0b6ff55acf52f2d0 to your computer and use it in GitHub Desktop.
Configures NPM to allow global package installs without sudo, thereby avoiding the typical permissions issue with updating node packages
# Install NodeJS and related on Ubuntu without requiring sudo on subsequent "npm -g" installs
# Went this direction when certain packages where trying to update global files owned by root...
# ... since the global packages were installed with sudo
# if using Vagrant, recommend to set "privileged: false" on the provisioning script where this code resides
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get -y install git nodejs build-essential
mkdir -p ~/.npm_packages
npm set prefix $HOME/.npm_packages
echo "export NPM_PACKAGES=~/.npm_packages" >> ~/.bash_aliases
echo "export NODE_PATH=~/.npm_packages/lib/node_modules" >> ~/.bash_aliases
echo "export PATH=$PATH:~/.npm_packages/bin:~/.npm_packages/lib/node_modules" >> ~/.bash_aliases
source ~/.bash_aliases
# once this is done, you can install npm packages globally without requiring sudo... happy trails!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment