DEV Community

Michael Wilkinson
Michael Wilkinson

Posted on • Originally published at realworlddev.hashnode.dev on

Installing NVM on Windows 11

Wrong Version of Node? What??

Picture a familiar scene to the JavaScript developer; a new project comes in and you reach for your favourite framework and "npm install" this or "npx create..." that and BOOM! You get an error message informing you that you have the wrong version of Node installed. Why?! This is because you are also working on an older project that requires you to use a particular version of Node so you can serve the project locally when coding on it. So, now what?

NVM to the rescue...right?

If you're a developer and your daily machine is a Mac or a Linux box and using anything to do with JavaScript, then there is a very good chance you've heard of NVM...or Node Version Manager to use it's full name. You will freely be able to use many different versions of Node on your machine and it wont impact your workflow in the slightest. If you have never heard of NVM, then you're either not a frontend JavaScript developer or you've been missing out. However...what if your machine is running Microsoft Windows? The NVM that Mac and Linux users love and use daily, wont work on Windows. End of story. So what do we need?

NVM For Windows

Thankfully, there is a shining light for all developers using Windows. A very thoughtful chap called Corey Butler has built a version of NVM for those of us using Windows machines as part of our development toolset. Thank you Corey for your efforts and for making my life a lot easier!

How To Install NVM on Windows

If you've come this far, this is probably what you're looking for. So without me waffling on any longer, hopefully this will help someone out there.

After starting a new Azure Function, I was met with error messages telling me I had the wrong Node version. This was a new machine, so after checking my version, I actually had none installed.

1.node-missing-crop.png

First of all, we need to grab a release of NVM Windows so we can install it. To do that, head to here, which is Corey's GitHub releases page to get the latest version, and download 'nvm-setup.zip'. After extracting the contents, you'll have this little beauty all ready to be run:

2.downloaded.png

Double-click it to start the install process and follow the instructions...

3.install.png

Once installed, open a terminal and at the prompt type:

nvm

Enter fullscreen mode Exit fullscreen mode

If the installation completed successfully, you'll see something very similar to this:

4.nvm-usage.png

Success! It's all looking very nice indeed. Now we have the version manager, we need to actually install Node. So with our terminal still open, we can grab the current 'Long Term Support' version by entering:

nvm install lts

Enter fullscreen mode Exit fullscreen mode

This will download, extract and install the 'LTS' version of Node and will even inform you of what to enter to use the newly installed version:

5.installing-node-lts.png

Now when I go back to my terminal from earlier, I list my versions of node installed, enter which version to switch to and verify just to make sure:

6.first-nvm-use-crop.png

I need a different version of Node

So what happens when you get to work on another project and lets pretend it's a legacy project from a few years back. You clone the latest code from your repository and a previous developer has kindly stated in the ReadMe file that you need Node version 12.13.1 to be able to serve the application. Now you have NVM Windows installed, this is nice and easy using 'nvm install' and 'nvm use':

nvm install 12.13.1
nvm use 12.13.1

Enter fullscreen mode Exit fullscreen mode

Note that you need to have the exact Node version number or it will fail.

Now to verify, enter this in to the terminal:

node -v

Enter fullscreen mode Exit fullscreen mode

...and you'll see that you're now using Node version 12.13.1. If you need to see all the versions you have installed for when you need to switch again, just enter:

nvm list

Enter fullscreen mode Exit fullscreen mode

...and you have everything you need ready to switch to the correct version.

Thank You Corey

Just to re-iterate what I said above, we need to thank Corey Butler for his excellent work and effort on building this for us Windows users. No longer can the developers on Mac and Linux look down their noses and scoff at us for not being able to manage our Node versions with ease like they can. Now they'll have to find something else to scoff at!

Top comments (0)