When using tools like
n or even
homebrew you can end up installing multiple verisons of Node. This could mean that when you run
npm install -g over time you’ll have the same executible installed in a bunch of different places. See for yourself:
type -a expo-cli
Do multiple versions come up?
Create a global
npmbin: one place to store all of your global dependencies without having to call them with the global flag! This folder will have its own
package.json and specific node version. No more node_module bloat, no more linking, it just works.
Create a new directory under home and cd into it:
mkdir ~/npmbin/ && cd $_
Init with package.json. None of the fields really matter, its all local.
yarn init (or npm init)
~/npmbin to your path. Open your
~/.zshrc and on a new line:
What this does is makes
~/npmbin available to use everywhere. Save & restart your terminal window.
Then navigate back to your
~/npmbin directory and install a module you’d typically use globally (
gatsby-cli are two I use a lot):
-g! You don’t need to anymore :smile:
npm install `expo-cli`
You might think its annoying to have to cd into
~/npmbin every time you want to install something globally. Although it doesn’t happen alot, I still did. I created a simple alias function to make it easier:
yarn global but call it whatever you’d like!
yarn add $@
- Cd into
- add the file that was passed in as an argument
- cd back to wherever you were
Place this inside your
~/.bashrc file and restart your terminal. Give it a go.