DEV Community

Cover image for Managing multiple NodeJS versions

Managing multiple NodeJS versions

Ido Shamun on September 14, 2020

We all switch around different projects, sometimes even daily. Every project has its own requirements in terms of dependencies and runtime. Lucky f...
Collapse
 
stereoplegic profile image
Mike Bybee • Edited

A few extra pointers:

  • Homebrew for Mac or Linux is the easiest way to install NVM (brew install nvm), and it's one less separate update to manage (just update it with the rest of your brew packages).
  • Contrary to popular belief, it's entirely possible to use NVM as well as a "system" version of Node installed elsewhere (e.g. via brew install node@[version] on Mac and Linux, or from your Linux distro's repository, or from the official NodeSource deb or rpm repo). For everyday use, set NVM to use this version with nvm use system. The benefit of this is not having to redo your global node_modules for every new point release (and not needing to worry about either uninstalling previous ones or having several stale node_modules folders), as well as not needing to install yarn (e.g. via Homebrew) only to follow up by removing the Node it pulls down as a dependency. From there, when you need a specific NVM-provided version of Node, just do nvm use [version] or, even better, specify it in your project with a .nvmrc file.
Collapse
 
joelrozen profile image
Joel Rozen

Check out asdf version manager.
A lot more fiddly but oh-so-much more powerful.

Collapse
 
ojoanalogo profile image
Alfonso Reyes

On other alternatives to nvm I found Volta (github.com/volta-cli/volta) I haven't tried it personally but seems like a good alt

Collapse
 
idoshamun profile image
Ido Shamun

I love the simplicity of NVM. But never heard of asdf

Collapse
 
mjgs profile image
Mark Smith

Nvm is for sure a cool tool, the version switching functionality is great.

I’ve skimmed through docs but couldn’t find this - Does nvm have a feature to install and compile node from source?

Collapse
 
idoshamun profile image
Ido Shamun

I'm not familiar with such feature. Why would you need it?

Collapse
 
mjgs profile image
Mark Smith

Compiling from source (as opposed to using pre-compiled binaries) is considered by some to be more secure.

Collapse
 
anzhari profile image
Anzhari Purnomo

Great article!

I personally use nvm and it is really helpful between switching the latest and LTS version.

Collapse
 
idoshamun profile image
Ido Shamun

Thanks. Yeah, it's super cool!

Collapse
 
budimirbudimir profile image
Budimir

One of my fav tools ever is tj/n. N is so much easier and more reliable than NVM. It is also somewhat more intelligent. Only downside is it's OSX-only tool.

Collapse
 
kasiriveni profile image
Srinivas Kasiriveni

👏👍