Skip to content

Instantly share code, notes, and snippets.

@martincr
Last active March 20, 2021 11:24
Show Gist options
  • Save martincr/96fcb70d054a2c2e874594862b89a2b8 to your computer and use it in GitHub Desktop.
Save martincr/96fcb70d054a2c2e874594862b89a2b8 to your computer and use it in GitHub Desktop.
Installing NPM to avoid using sudo on Mac OS X El Capitan. Node.js installed via https://nodejs.org/en/
$ node -v
v6.9.5
$ which gcc
/usr/bin/gcc
$ npm -v
3.10.10
$ mkdir "${HOME}/.npm-packages"
$ echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
$ echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
$ echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules\:\$NODE_PATH\" >> ${HOME}/.bashrc
$ echo PATH=\"\$NPM_PACKAGES/bin\:\$PATH\" >> ${HOME}/.bashrc
$ echo source "~/.bashrc" >> ${HOME}/.bash_profile
$ source ~/.bashrc
Note: mostly taken from from https://johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/
Note: Node.js installed via their OS X installer as per the description (above).
Run checks:
$ nano ~/.npmrc
$ nano ~/.bashrc
$ nano ~/.bash_profile
All should work as per https://johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/
See also: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment