In this article, we will learn to install multiple version of node-js in your machine having ubuntu 16.04 LTS (most of the setup is identical for Mac as well).

Installation instruction will be outdated in coming years. We will cover the process of installation along with some authentic source to look.

Prerequisite to follow this tutorial

  • A working machine with Ubuntu/Mac.
  • Some working experience with Terminal.

To install Node Version Manager you can just copy paste the following code snippet.

curl -o- | bash

In an event of any error you can follow this link to GitHub, and copy the snippet directly from the repository.

Restart your terminal and type in the following command to check the installation of nvm has succeded or not.

To check if nvm is installed correctly in your system you will have to exit your current terminal and start it again.
Type in following command.

# To check if nvm is correctly installed
nvm --version

If you ran into command not found an error, then you should update your .bashrc for Ubuntu and .bash_profile for Mac with following snippet, which will add nvm to your system path.

export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm

Afterwards to install node-js of your choice you should execute following command.

# Install node-js, this will install latest LTS version of node
nvm install --lts

# Install specific version of nodejs
nvm install <version> # e.g. nvm install 10.0

# To list out the version installed
nvm ls

Migrating global packages while installing, to install the packages of old version of node to the new one you can execute following code snippet.

# To install new version of node with global packages of old version
nvm install <new-node-version> --reinstall-packages-from=<old-node-version>
output of nvm list command

Now you should check if your node-js is installed correctly or not by following command

# Check version of node-js
node --version 

To choose between multiple version of node-js installed in your system you can use following command

# To switch between version of nodejs
nvm use <version> # e.g. nvm use 10.0

# To make one specific version default
nvm alias default 10.0

# To uninstall
nvm uninstall <version> # e.g. nvm uninstall 10.0

I hope this article will help you installing and using multiple version of node-js.

If you like the post, please give us thumbs up or comment below.


Leave a Reply

Your email address will not be published. Required fields are marked *