Why I don't like Popular Options
After evaluating different popular options including NVM, Ubuntu Repos, Ubuntu PPAs, OSX Homebrew and OSX Macports I experienced a lot of issues with them including
- They are OS specific
- You cannot install specific Node.js versions
- They can cause conflicts when more than one users try to run different versions of same global modules
- You have to use
sudowhen installing global modules or linking local ones (except for homebrew)
Having to do
sudo for npm is bad for a lot of reasons, for examples the directories/files it creates while running as sudo will be owned by root and you won't get to modify them afterwords.
How I do it
I use the n Node.js version manager by TJ Holowaychuk. Here's it's pros and cons in comparison
Things awesome about n
- Zero overhead (unlike NVM)
- Works on any POSIX environment
- Never asks for or requires sudo
- Can download any Node.js version
- Installs modules in
~/n(configurable) so they are isolated per user
Possible downsides of n
- Too easy if you are a real programmer 😁
How you can too
You should uninstall the currently installed Node.js before anything else and then execute these in order
curl -L https://git.io/n-install | bash # Press y in the prompt or configure the directory if you want # Then restart your shell to update it's $PATH and be able to use n/node exec $SHELL
That's it fellaws, now you have an isolated, working Node.js setup. If you went with the defaults you should have an
n directory in your home directory.
n is a bash script so it's lightweight/minimal but still includes all the necessary features.
To upgrade to the latest version of Node.js do
or to install the lts version do
or say you want to download Node.js v8.9.4 do
If you want to access the list of installed versions and select between them, do
You can find more about n in it's README.
Note: When switching between shells, remember to also include the line inserted by
n-install in your shell's config file such as
That's all for now folks, happy coding!