Run multiple NodeJS versions with Node Version Manager (NVM) — for MacOS
If you use Node.js for your applications, you may want to use different versions of Node. Fortunately, there is a tool to manage them all using Node Version Manager.
Node.js uses an event-driven, non-blocking I/O model unlike other server-side platforms e.g. PHP whereby functions tend to block until completion, which means that commands execute one at a time. In, Node.js, commands are executed in parallel, and callbacks are used to determine completion or failure.
Node.js Version Updates
A new release of Node.js is cut from the GitHub master branch every six months. Whenever a new odd-numbered version comes out, the most recent even version goes to long-term support, or LTS. Versions under LTS receive active support for 18 months followed by an additional 12 months of maintenance support.
What is Node Version Manager (NVM)?
Node Version Manager is a tool that allows programmers to seamlessly switch between different versions of Node. With NVM, you can easily switch and install each Node version with a simple command line interface command. In addition, you can also set a default version for use.
When you are faced with bugs, using a version manager makes it simple to switch node versions for quick troubleshooting. Otherwise, it would be tedious and time-consuming to have to uninstall and reinstall node versions and their global packages.
Installing NVM for MacOS
Install Node Version Manager using either cURL or Wget.
For cURL, run the following from your terminal:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
The above commands will clone the repository to ~/.nvm and apply changes to your bash profile and that allows you to access NVM from your terminal.
We can then run these 3 lines in the terminal in order to use NVM right away:
export NVM_DIR="$HOME/.nvm"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# This loads nvm[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
And these are what you can use with NVM:
A useful command is default alias. To use the latest version of Node.js as default, run:nvm alias default node
You are also able to name your own aliases using the following format:
nvm alias side-project 10.13.0
The above command creates an alias called ‘
side-project’ for version 10.13.0. To use this version, you can use it like so:
nvm use side-project
If you want to removethis alias, just run:
nvm unalias side-project
To view the list of Node.js versions on your computer, run:
The version which is being currently used will appear in green and have an arrow pointing to it.
$ nvm current