How to use multiple node versions with nvm (macOS)

Von am 24.10.2016

When we think about Web development today, some of us subconsciously get goosebumps, especially when thinking about node and npm packages. If you ever came across node and got the chance to try it out or you already have used it in production, you might have come across one BIG (pronounced w/ a strong intonation) issue: versions. Depending on how you take it, it’s either an issue or a challenge. Let me illustrate this problem in a couple of words, after which we will look at a possible solution: nvm.

Imagine you are coding on a bunch of projects and you’re currently using node v5.1.0. Let’s assume that next week you are going to join a workshop about Ionic 2, where you will get first glimpses of what it actually is. The only thing you have to do is get Ionic 2 (and Cordova) up and running and wait for time to pass (like you don’t have anything better to do) until the workshop. So you go to the Installation guide on the official Ionic website and because you are a good developer, you start carefully reading the documentation:

“Ionic 2 apps are created…”, you are reading silently, “… bla bla blah… To create Ionic 2 projects… mhmm…”, after which you stop and stare in complete devastation to your desktop screen in disbelief of what you’ve just read: “you’ll need a recent version of Node.js”speechless! However your heart only totally stopped beating after you’ve read the next line: “Download the installer for Node.js 6 or greater”What?!

Those of you, who know what I’m talking about, can understand my feelings about installing a new node version and the need of a kilometre long story. Furthermore, the idea of an installer for node is quite uncomfortable, since this could potentially break my existing tens of projects – thus personally unacceptable. What about all my npm packages? Will those still be compatible with the new node version? Do they also have to be updated? What if I have different requirements for different projects and therefore the need of multiple node versions? There has to be a better way!

And luckily there is! 🙃

Node Version Manager (nvm)


If you start reading the README.markdown file, it says that Windows is not supported – what a shame. This tutorial will only target platforms / systems, that are supported by nvm. Other recommended Windows alternatives are:

Install nvm

Following the installation instructions from the README file, we can simply install or update nvm using cURL:

or Wget:

To load nvm you need the following source lines to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc):

You might need to manually source your profile:

Now open up a new Terminal window / tab and type nvm. You should see the available nvm commands. If anything went wrong or you can’t find the nvm command, please further refer to the nvm README file for more information.

Install desired node versions

To install the latest node version – you guessed it right – run:

To request a list of all remotely available version run:

To install a specific version run:

Conveniently, this comes with npm, which opens the gates to the gazillion of good stuff.

You can easily switch between node version:

Last but not least you check your current node version:

As you can see nvm provides a very convenient way of switching between node versions and it’s the way to go when you have different requirements for your projects or you simply remained a little behind considering the pace at which web development tools are evolving nowadays.

Biggest benefits

Besides being able to choose between multiple node versions, the biggest benefits using nvm in my opinion are:

  1. Version specific npm packages – meaning that your global npm packges will be installed per node version.
  2. You don’t have to run npm with sudo anymore !

Hopefully, this helped you out ! 😀

The comments are closed.