70

Is it possible to have different versions of NodeJS installed on the same machine?

Diogo Cardoso
  • 21,637
  • 26
  • 100
  • 138
Xitrum
  • 7,765
  • 26
  • 90
  • 126

7 Answers7

60

There are several node managers which you can use to achieve this, but the most popular are:

alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • N seems really awesome, but it doesn't seem to override my running version of node.js. Do you use n, and know how to get it to pre-empt your originally installed version of node? – Will Buck Apr 13 '12 at 16:22
  • 2
    I actually use NVM at the moment, and I can always roll back to whatever version of Node I want and make is the default. N should have that functionality also though. – alessioalex Apr 13 '12 at 20:00
  • For Windows, use [nvm-windows](https://github.com/coreybutler/nvm-windows), which comes with an installer and is well maintained. (It's also mentioned in this SOF question: [multiple-versions-of-node-on-windows](https://stackoverflow.com/questions/50399621/multiple-versions-of-node-on-windows)). – Marc Sigrist Jul 24 '18 at 14:29
  • NVM has a possibility to set node version in the `.nvmrc` file, I cannot find this feature in N docs, so NVM wins for me – Lev Lukomsky Mar 24 '19 at 14:47
15

I use nave. https://github.com/isaacs/nave

> npm install -g nave
> nave use 0.4.12 # starts a subshell with 0.4.12 at the head of the path
> node --version
v0.4.12
> exit # go back to the original shell
> nave use 0.6.5
> node --version
v0.6.5
> nave usemain

Note that the first time you need a version, it will be downloaded and compiled for you.

Marco
  • 1,471
  • 11
  • 17
  • Nave requires bash. It will probably never work on Windows, or other systems lack a native Bourne Again Shell. https://github.com/isaacs/nave#compatibility – Diogo Cardoso Jun 13 '14 at 16:04
  • You can also create **named environments**. E.g `nave use foobar` will ask you what version of node to associate with `foobar`.Once it is created, it can be switched to using the same command. – GiriB Jan 20 '16 at 12:43
6

If you need something simple, the n utility is just for you.

Install it (use sudo prefix in commands if required):

npm -g install n

then :

npm cache clean -f

(don't be scared about the warning)

then just ask n to (download if required and) use the version you specify. For instance:

n 0.11.13

Et voilà !

Should you install multiple versions, you'll be able to switch between them. See the n page for details.

Jérôme Beau
  • 10,608
  • 5
  • 48
  • 52
2

You can follow simple approach here

step1:

 $ curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash

step2:

 $ source ~/.profile

step3: list the latest versions of node

 $ nvm ls-remote

step4:

  $  nvm install 7.10.0

step5: Create alias as default for node version

$ nvm alias default 7.10.0

step6:

$node --version

that's it.

Venkatesh
  • 160
  • 1
  • 2
  • 11
1

Windows users check out nvmw here.

You can go quite a long way down trying to install some of the other versions listed before realising there's no Windows support.

e.g. on the page for nave

It will probably never work on Windows, or other systems lack a native Bourne Again Shell. Sorry.

hawbsl
  • 15,313
  • 25
  • 73
  • 114
  • 1
    nvmw seems to be not supported anymore: "SORRY, nvmw is no longer maintained. If someone wants to keep maintained, contact me by email or twitter." – 1800 INFORMATION May 08 '16 at 22:05
0

The best option is node version manager NVM is very simple to install and you can change from one version to another with a simple nvm use command.

Johel Alvarez
  • 775
  • 8
  • 8
0

You can use NVM - Node Version Manager, Supports both Windows and Mac.

It has all the instructions of how to install and use it.

https://github.com/nvm-sh/nvm

These will be independent installs so you will need to install packages in each versions.

Asanka
  • 483
  • 2
  • 8
  • 21