Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Last active March 26, 2016 16:33
Show Gist options
  • Save ryaninvents/d7413b40b72f026b3ee2 to your computer and use it in GitHub Desktop.
Save ryaninvents/d7413b40b72f026b3ee2 to your computer and use it in GitHub Desktop.
Fix npm global install
# This script is the **correct** way to allow installation and use
# of npm executables without sudo.
# Declare where you want your global packages installed to.
npm config set prefix '~/.local/share/npm'
# Ensure the directory exists.
mkdir -p ~/.local/share/npm
# Change `.zshrc` to `.bashrc` if appropriate, but consider instead
# switching to zsh.
SHELL_PROFILE=~/.zshrc
# Make sure the executables folder is in your $PATH.
echo 'export PATH="$HOME/.local/share/npm/bin:$PATH"' >> $SHELL_PROFILE
# Make sure global node modules can find their dependencies correctly (think `yo`)
echo 'export NODE_PATH="$NODE_PATH:$HOME/.local/share/npm/lib/node_modules"' >> $SHELL_PROFILE
# Make the changes take effect.
source $SHELL_PROFILE
# Now you'll have to reinstall all global modules so your user has control.
# Here's my general set of defaults; I may be forgetting some.
npm i -g npm yo gulp webpack n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment