Use `npm install -g` w/o `sudo` using oh-my-zsh

NOTE (Jan 22, 2017): I no longer use brew to install node; I use nvm to install node instead.

I followed John Papa’s “How to use npm global without sudo on OSX” guide here.

I noticed that my installation of npm seemed to not persist when using oh-my-zsh, even though I confirmed it was still installed.

I read about .zshenv.zshrc.zlogin, and some other files for a good chunk of time before I realized, "Hey, npm works for a little bit after using John Papa's guide. Why don't I just see which line of code makes it work?"

Here’s the list of commands that I used (please read the guide first before using any of them):

brew install node --without-npm
mkdir "${HOME}/.npm-packages"
echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
curl -L | sh
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

Well.. duh. Now the answer seemed obvious (to me). The npm command doesn't work until we source our ~/.bashrc file in, so once I added the final line to my ~/.zshrc file, everything worked magically.

Like what you read? Give Robin Kim a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.