-
-
Save stalinkay/6d2d84059cd505dc5688f31aac74390f to your computer and use it in GitHub Desktop.
Use npm global without sudo on OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Install or Update Homebrew as needed | |
# | |
which -s brew | |
if [[ $? != 0 ]] ; then | |
# Install Homebrew | |
# https://github.com/mxcl/homebrew/wiki/installation | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
else | |
brew update | |
fi | |
# | |
# Install Node/NPM globally without sudo. | |
# http://www.johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/ | |
# | |
# This adds node, sans npm | |
brew install node --without-npm | |
# Create a directory for your global packages. | |
mkdir "${HOME}/.npm-packages" | |
# Reference this directory for future usage in your .bashrc file. | |
echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc | |
# Indicate to npm where to store your globally installed package, in your ~/.npmrc file. | |
echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc | |
# This gets and installs the latest npm, which is 2.1.16 at the time of this writing. | |
curl -L https://www.npmjs.org/install.sh | sh | |
# Ensure node will find the packages by adding the path to your .bashrc. | |
echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules:\$NODE_PATH\" >> ${HOME}/.bashrc | |
# Ensure you’ll find installed binaries by adding the following to your .bashrc. | |
echo PATH=\"\$NPM_PACKAGES/bin:\$PATH\" >> ${HOME}/.bashrc | |
# Ensure that you source your .bashrc file by adding the following to your .bash_profile. | |
echo source "~/.bashrc" >> ${HOME}/.bash_profile | |
# Source your .bashrc file once. Previous step did this for the future, but this does it right away. | |
source ~/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment