Skip to content

Instantly share code, notes, and snippets.

@aamnah
Last active March 27, 2019 11:46
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 aamnah/2aff3e5e87674af7ec8a220f585c4d14 to your computer and use it in GitHub Desktop.
Save aamnah/2aff3e5e87674af7ec8a220f585c4d14 to your computer and use it in GitHub Desktop.
Fix npm permissions for running global packages
#!/bin/bash
# source:
# https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
fix_npm_permissions () {
# create a new directory for installing npm pacages
mkdir ${HOME}/.npm-global
# Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
# Update PATH in ~/.bashrc
echo -e "
# changing npm global install folder to fix permission errors
PATH=\"${HOME}/.npm-global/bin:$PATH\"" >> ${HOME}/.bashrc
# On the command line, update your system variables:
source ${HOME}/.bashrc
}
fix_npm_permissions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment