Using NVM To Manage Node Versions Across Projects22 October 2019
Photo: Unsplash - Brennan Angel
How you install NVM depends on your platform. The Github page has detailed instructions that I will not repeat here. Once installed you will need to source the NVM file from your shell rc file (.bashrc, .zshrc etc):
(Note - The installation path may vary on your machine).
(nvm is not natively supported on Windows but there is an NVM-Windows package.)
Using nvm is really easy:
To install a new Node version for the local user you can execute nvm install version:
To switch between Node versions then you execute nvm use version:
It really is that simple.
If you want to force a given version for a project then you can create a .nvm file in the root directory of the project. In the file, you just add the Node version number the project should use wrapped in single quotes. Then when you switch to the project you can just run:
The project Node version will be used.
If you want to use nvm to see what versions of Node are available then you can use:
Nvm also has some aliases which target the latest versions of both the stable and unstable:
So running the following will install the latest version of Node:
You can, of course, uninstall versions using:
If you want to check the version of node you are running you can use
Nvm is a really useful tool to manage Node versions. I hope to see more people using it to set Node version information at a project level. This will speed up the process of getting a project running locally.