Patrick Lamber
Patrick Lamber IT Geek focusing on Microsoft collaboration software.

How do I install multiple Node versions on my Windows computer?

When working with Node.js you might encounter situations where you need multiple versions of Node.js on the same machine. In my case, I want to create SPFx components for SharePoint Online and on the same machine create components for the Office 365 CLI.

Both solutions require different versions of Node.js. This adds the burden of manually installing or uninstalling Node versions and their global packages when switching projects.

At the time of writing SPFx runs on [Node.js v8.x and Node v10.x], while Office 365 CLI runs on [Node.js >= v12.0.0]. With Node.js v12 installed, I am not able to create SPFx components.

Luckily, you can tackle this problem by using a project called Node Version Manager.

Install nvm for Windows

Before installing the latest package, ensure that you cleanup your environment first:

  • Uninstall existing Node instances and remove existing installation directories
  • Uninstall existing npm install location (e.g. “C:\Users<user>\AppData\Roaming\npm”)
  • Download the latest version of nvm for Windows and install it

After installing nvm, I have to install the desired Node instances using a PowerShell command prompt in an administrative context. I need Node v10.19.0 for SPFx and Node v12.16.1 for Office 365 CLI. Therefore, I executing these commands.

1
2
3
4
5
6
7
8
9
10
11
# installs the node version 10.19.0
nvm install 10.19.0
nvm use 10.19.0
npm install -g yo gulp
npm install -g @microsoft/generator-sharepoint
gulp trust-dev-cert

# installs the node version 12.16.1
nvm install 12.16.1
nvm use 12.16.1
npm install -g gulp-cli

The commands above install the desired Node versions and the global utilities required by both Node versions.

Using nvm for Windows

Adding multiple Node instances and switching between these is much easier with this approach.

The change of the current Node instance can be performed with the use command.

1
nvm use 12.16.1

Remember that the operations have to be executed in an administrative context.

comments powered by Disqus