Install Multiple version of node on linux

Date Posted: 08-05-2017

We want two version of node version on a single server. Alternatives is an utility which can be used to install two version of any package.

Assumption:

  1. Ubuntu Host

Implemntation:

Let’s start with node installation. We will use one normal apt-get to install node version and other one from source.

apt-get install nodejs

Install npm(node package manager)

apt-get install npm

After successful installation of both the package, verify the node version.

nodejs -v

Now, install different version of node. Let’s create a directory for node package onĀ /usr/local/bin/node

mkdir /usr/local/bin/node

Change the directory and download the different version of node from official website.

cd /usr/local/bin/node

wget https://nodejs.org/dist/v5.0.0/node-v5.0.0-linux-x64.tar.gz

Extract the downloaded file.

tar -xzf node-v5.0.0-linux-x64.tar.gz

Here comes the main part, use alternatives to configure both version

update-alternatives --install "/usr/bin/node" "node" "/usr/bin/node" 100

update-alternatives --install "/usr/bin/node" "node" "/usr/local/bin/nodes/node-v5.0.0-linux-x64/bin/node" 50

To switch the version of node, use the following command.

update-alternatives --config node

Select 2 to change version to use node-v5 version in this example.

Similarly, use the below commands to configure two different version.

update-alternatives --install "/usr/bin/npm" "npm" "/usr/bin/npm" 100
update-alternatives --install "/usr/bin/npm" "npm" "/usr/local/bin/nodes/node-v5.0.0-linux-x64/bin/npm" 50

To switch the version of npm,

update-alternatives --config npm

Post your queries in comment section incase of any queries.

Leave a Reply