Skip to content

Instantly share code, notes, and snippets.

@hedcler
Last active August 24, 2017 14:56
Show Gist options
  • Save hedcler/97858b2dbdf5384fbcaec5539697d10f to your computer and use it in GitHub Desktop.
Save hedcler/97858b2dbdf5384fbcaec5539697d10f to your computer and use it in GitHub Desktop.
Install npm globally without sudo
#!/bin/sh
# No need to download this script, just run it on your terminal:
#
# $ curl -L git.io/v5qOi | sh
#
mkdir "${HOME}/.npm-packages"
echo "prefix=${HOME}/.npm-packages" >> ~/.npmrc
echo "# RUN NPM WITHOUT SUDO" >> ~/.bashrc
echo "NPM_PACKAGES=\"${HOME}/.npm-packages\"" >> ~/.bashrc
echo "export NPM_PACKAGES" >> ~/.bashrc
echo "PATH=\"$NPM_PACKAGES/bin:$PATH\"" >> ~/.bashrc
echo "export PATH" >> ~/.bashrc
echo "unset MANPATH" >> ~/.bashrc
echo "export MANPATH=\"$NPM_PACKAGES/share/man:$(manpath)\"" >> ~/.bashrc
sudo chown -R $(whoami) /usr/local/
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment