DEV Community

Stephen Gbolagade
Stephen Gbolagade

Posted on • Edited on

Manage Multiple Nodejs Versions on Windows OS

Recently, I encountered a problem requiring me to downgrade my machine’s Node version. Downgrading or upgrading the Node version is simple, but it’s cumbersome to keep doing that anytime there’s a need for it.

So what if there’s a way to have multiple Node on your PC and all you have to do is switch to any version compatible with what you want to do.

If you’re thinking of a possible way to install and switch between different node.js version on your Windows-powered PC, this article will guide you.

NOTE: This method will only work on Windows-powered devices, also Mac and Linux devices have similar steps.

So, let’s start!

Step 1: Uninstall Node.js

If you already have a particular Node version installed, go to your PC’s cPanel to uninstall it.

Here is how:

  • Click the start button, and search for “Control Panel.”
  • Under Program, click “Uninstall program.”
  • A new page with all your installed programs will appear, find Nodejs and uninstall it.

Go to your file explorer >> PC >> Users >> {username} >> Program Files, ensure there is no Nodejs folder here, if there is any, delete it permanently.

You may need to restart your system to complete the process.

Step 2: Install NVM - Node Version Manager

NVM is a tool that allows you to easily install and manage multiple versions of Node.js on your computer. With NVM, you can switch between different versions of Node.js with just a few commands, making it easier to test your code on different versions or use different versions for different projects.

To install NVM, you can go to this download page on GitHub and follow the installation guide.

But to save you time, let’s install using the bash command.

Download a bash terminal, for instance, Git Bash, and install it.

Open your Git Bash terminal and put in this code:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

You can change the version. E.g., you can use v1.11 instead of v0.39.0 but this work for me perfectly while the latter is the latest as of the time of writing this.

Once it’s done installing, close the bash terminal and open it again.

Run nvm to see the list of NVM commands.

If you see the list, good, you can skip the next step but if see like error:

bash: nvm: command not found.
Enter fullscreen mode Exit fullscreen mode

Don’t worry, let’s fix it in the next step.

Step 3: Configure Terminal to Use NVM

First thing, let’s confirm if NVM has been installed successfully, run this command:

cat ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

This command is checking if there’s bash configuration, since you can’t use nvm, I expect you to see something like this:

$ cat ~/.bashrc
cat: /c/Users/solga/.bashrc: No such file or directory
Enter fullscreen mode Exit fullscreen mode

This confirms our curiosity. Now, let’s create a .bashrc directory and configure it.

Run these commands in order:

  • touch .bashrc - This will create a file with bashrc extension (You can’t see it)
  • nano .bashrc - This will open the file for editing

Now put this configuration there:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Enter fullscreen mode Exit fullscreen mode

Press Ctrl + X to save the file.
Press Ctrl + Z to close the file.

Now we have bash configured. We can use NVM now.

Run nvm again, now you should see the list of NVM commands.

NVM command list

To check the current version of nvm you have, run nvm --version

Let’s install Nodes.

Step 4: Install different Node versions

To install any node version, simply run nvm install <version>

For example:

nvm install 12.4.0
Enter fullscreen mode Exit fullscreen mode

This will install Nodejs version 12.4. And you can install more versions by using the same syntax above.

Step 5: Switching and using a Node version

To use any node version, simply run nvm use <version>

E.g

nvm use 12.5.8
Enter fullscreen mode Exit fullscreen mode

Note that you must have installed the node version you want to use with NVM. To see the list of your installed nodejs versions, run nvm ls.

If you need to switch to a different version of Nodejs, you can always do that.

Note: If you use yarn to manage node packages, you have to install it again but if you use npm, you have nothing to worry about.

To install yarn, run this:

npm i -g yarn
Enter fullscreen mode Exit fullscreen mode

This will install yarn globally on your system.

So that's it!

If you have any questions or would like to make a correction, feel free to do that as I'm open to learning too.

PS: I'm a frontend engineer and I'm available to work (remotely) either as a frontend engineer or technical writer. Send me an email at (hello{at}stephengade.com).

Thanks for reading.

Top comments (1)

Collapse
 
evanskaufman profile image
Evan K

Great post, thanks for this!

I would just point out one thing, NVM for Windows and nvm-sh are two separate projects albeit with the same goal.

For what it's worth, I could never manage to get the former working properly with git-bash on Windows.

The latter, on the other hand, works quite nicely on git-bash!