NVM, short for Node Version Manager, is an invaluable tool for Node.js developers on Windows. It allows you to easily install, manage, and switch between multiple versions of Node.js.
In this comprehensive guide, I‘ll walk you through installing, setting up, and using NVM on Windows 10 step-by-step. As an experienced Node.js developer, I‘ll provide pro tips and best practices along the way.
Why Do You Need NVM for Node.js on Windows?
Before we dive into the NVM installation process, let me quickly explain why NVM is so useful:
- NVM lets you install multiple versions of Node.js side-by-side. For example, you can have Node v16.x and Node v18.x installed at the same time.
- You can conveniently switch between different versions of Node per project or globally. This is useful when working on projects that require specific Node versions.
- Updating or downgrading Node versions is a breeze with NVM. No need to uninstall/reinstall Node each time.
- NVM fully isolates Node versions from each other, avoiding version conflicts.
- Overall, NVM makes managing Node.js versions simpler and more efficient.
As you can see, NVM solves major version management headaches for Node developers on Windows. It‘s a must-have tool in every Node.js dev‘s toolbox.
Prerequisites Before Installing NVM
Before you install NVM, make sure your Windows 10/11 machine meets these requirements:
- You must have administrator access to install programs globally.
- There should be no previous Node.js or npm installations. NVM will handle all that.
- An adequate amount of free disk space (1 GB should be enough).
Optional but recommended:
- Install a terminal emulator like Cmder for a better command line experience.
Verify the prerequisites are met, then close any unnecessary programs. Now you‘re ready to install NVM!
Install NVM on Windows in 5 Easy Steps
Follow these steps to install the latest NVM version on your Windows OS:
Step 1: Download the NVM Installer
Go to the official NVM for Windows GitHub repository.
Scroll down to assets and grab the latest nvm-setup.zip
file. At the time of writing, that is version 1.1.9.
I prefer the .zip file since it‘s faster to install. But you can also use the .exe or .msi installer if you wish.
Step 2: Extract the Downloaded Zip File
Right-click the nvm-setup.zip
file and select Extract All to unzip its contents.
Specify a memorable location like C:\nvm-install
to extract the zip contents.
Inside you‘ll find the latest NVM installer program along with licenses, release notes, etc.
Step 3: Run the NVM Web Installer
Navigate inside the extracted folder and locate the nvm-web-installer.vbs
file.
Double click on nvm-web-installer.vbs
to launch the NVM installer.
Allow access if Windows asks whether to let the script make changes.
Step 4: Complete the NVM Installation Process
The NVM Web Installer will first download the latest NVM files.
Once finished, you‘ll see the Welcome screen and license terms. Click Next after accepting the EULA.
On the next screen, select what type of install you want:
- Just Me: Single user install that doesn‘t require admin access.
- All Users: Global install requiring admin access.
I recommend All Users mode so NVM works system-wide.
Click Next while leaving all other options as default. This will install NVM in the recommended location.
Finally, click Install button to kickstart the installation process.
Once done, you‘ll see the Completion screen. Click Finish and restart your terminal or IDE to complete setting up NVM.
That covers the quick process of installing NVM on Windows!
Step 5: Verify the NVM Installation
Let‘s confirm NVM installed properly on your Windows OS:
-
Open a new command prompt or terminal window.
-
Type
nvm --version
and press Enter.
You should see NVM 1.1.9 or newer printed there!
Seeing the output above means NVM is installed correctly and ready for usage!
With NVM installed, let‘s move on to post installation setup. This will integrate NVM functionality system-wide.
Post Install Setup of NVM on Windows
To make NVM fully usable after installation, some quick one-time setup is required:
We need to add NVM directories to your system PATH environment variable. This makes the nvm
command accessible everywhere.
Here are the steps to complete post-install setup:
-
Open a new command prompt/PowerShell terminal with admin rights
-
Copy-paste this command and press Enter:
[Environment]::SetEnvironmentVariable("NVM_HOME", "$env:APPDATA\nvm", "Machine")
[Environment]::SetEnvironmentVariable("NVM_SYMLINK", "$env:ProgramFiles\nodejs", "Machine")
$env:PATH += ";$env:APPDATA\nvm"
- Restart your terminal/IDE completely
Once you open a new terminal/IDE instance, try running the verify command again:
nvm --version
Seeing the output as shown earlier means NVM path setup worked!
That completes post-installation steps. NVM for Windows is now fully configured and ready for managing Node.js versions!
Installing Node.js Versions with NVM
Now let‘s do something useful with the freshly installed NVM – install some Node.js versions!
Here I‘ll demonstrate installing the latest Node v18 LTS and v16 LTS versions side-by-side.
Install Multiple Node Versions with NVM
- To list all Node versions available for install with NVM, run:
nvm list available
-
From the long list, copy the latest LTS version numbers you wish to install. For example v18.12.1 and v16.18.1
-
Install Node v18 by running:
nvm install 18.12.1
- Similarly, install Node v16 via:
nvm install 16.18.1
- Now check installed Node versions with:
nvm list
You should see Node v18 and v16 successfully installed as shown below!
As you can see, NVM effortlessly handles installing multiple Node.js versions in parallel.
Let‘s switch between these versions next.
Switching Between Installed Node Versions with NVM
- To make v18.12.1 the active Node runtime, use:
nvm use 18.12.1
-
Check current version with
node -v
– it should show 18.12.1 -
Now switch to v16 with:
nvm use 16.18.1
- Run
node -v
again – you should be on 16.18.1 now!
And that‘s all there‘s to it! NVM makes handling multiple Node versions incredibly easy.
Next let‘s set a default Node version to use when starting any new terminal session.
Setting Default Node Version with NVM
When you open a new terminal, NVM will automatically activate the latest Node version installed.
This might not always be desired behaviour.
Instead, you can set a default Node runtime to persist across terminal restarts.
Here‘s how to configure a Node default version with NVM:
- With any Node version active, run:
nvm alias default 16.18.1
-
Now when starting any new terminal, Node 16.18.1 will be automatically selected instead of latest.
-
To verify it worked:
nvm list
You‘ll see a default -> 16.18.1 (-> v16.18.1)
output showing v16 as the persistent default.
- Alternatively, run
node -v
directly anywhere and Node 16 should activate.
So that‘s how to control the default Node.js version with NVM for Windows!
Next let‘s take a look at updating/removing Node versions managed through NVM.
Updating or Removing Node Versions with NVM
Another area where NVM shines is simplifying Node version upgrades and uninstallation.
Let‘s go through both processes quickly:
Upgrading Node Versions through NVM
Thanks to NVM, upgrading Node.js consists only of 2 steps:
- Find the latest version you wish to upgrade to:
nvm list available
- Install that newer version:
nvm install 18.14.0
And NVM handles seamlessly replacing the previous v18 files!
Uninstalling Node Versions with NVM
Removing old Node versions is also straightforward:
- List installed versions with:
nvm ls
- Remove any version with:
nvm uninstall 16.18.1
- Run
nvm ls
again and verify Node v16 is gone from the list!
That‘s all you need to easily upgrade or remove Node releases managed through NVM.
Now let‘s discuss some best practices when working with NVM day-to-day.
NVM Usage Tips and Best Practices
Here are some pro tips from my years of Node development for making the most of NVM:
-
If using an IDE like VS Code, restart it when changing Node versions for changes to reflect.
-
Use
.nvmrc
files to pre-configure desired Node versions per project folder. -
Run
nvm use
upon entering a project directory with a.nvmrc
file. -
Take backups before performing NVM upgrades to avoid potential issues.
-
If facing problems, uninstall/reinstall NVM cleanly before troubleshooting further.
-
Prefer using the NVM zip file method since the installer often fails in Windows.
Also refer to the official NVM usage docs for more on available commands.
Adopting the best practices around NVM usage will help avoid nasty problems down the road!
Now over the final section of removing NVM from Windows when needed.
Uninstalling NVM from Windows Systems
Though rare, there may be instances where removing NVM completely off your Windows machine is needed.
Perhaps you are facing extreme issues not resolvable otherwise. Or need to clean up disk space by removing unused programs.
Either way, following is the quick NVM uninstallation process:
-
Fully close any terminals/IDEs running NVM commands
-
Open Control Panel > Programs > Programs and Features
-
Select NVM for Windows and click Uninstall button above
- Restart your machine once prompted to finish nvm removal
And with that, NVM and all installed Node versions are wiped from the system!
Now you can freshly install node and NVM if still needed down the road.
Conclusion
There you have it – a comprehensive guide to install, setup, manage, and remove NVM for Windows!
We looked at:
- Benefits of using NVM for Node.js version control
- Downloading and installing latest NVM
- Post-installation setup of NVM
- Adding/Removing/Switching Node.js versions
- Setting default Node runtime through NVM
- Some pro-tips around ideal NVM usage
- How to cleanly uninstall NVM when required
You now have all the Node version management superpowers thanks to NVM!
I hope this detailed NVM handbook proves useful whether you‘re just starting out with Node.js or are a seasoned expert.
Make sure to bookmark and share so it can help other Windows Node developers as well!
Feel free to leave a comment if facing NVM issues or have an additional tip to share with readers.