Node Version Manager (NVM) is an open source version manager for Node.js (Node) and allows to easily install & manage different versions of Node and switch between them on a per-shell basis.
Use the following cURL or Wget command:
The steps for installation and configuration are easy; refer nvm installation steps.
Basic commands and their usage can be referenced from Usage section.
Use nvm like a superhero
i) Node installation
For first time Node installation use
$ nvm install v18.12.1
This installs a new version of Node.js and also migrate npm packages from a previous version.
When you are working on different projects and use different versions of Node then .nvmrc will make your life very easy. Create a .nvmrc file in the root of the project.
Instead of you remembering which project uses which version and manually setting the node version using
nvm use <node-version> command; simply use the command
If the Node version specified in the .nvmrc file is not installed it will tell you to run the nvm install command to download and install that version of node.
iii) Shell Integration
Shell script are there which you can add to your shells configuration file (.bashrc, .zshrc etc) to automatically nvm use and install the node version defined in the .nvmrc file when you change into a directory.
nvm use automatically in a directory with a
Put this into your
$HOME/.zshrc to call
nvm use automatically whenever you enter a directory that contains an
.nvmrc file with a string telling nvm which node to
Now when you switch to your project directory
Refer Deeper Shell Integration section for other shells
Benefits of nvm & .nvmrc
Stability: Your projects won’t break when you install newer versions of node as .nvmrc file saves the required node version for that project.
Explicit: Other developers or users of your application will instantly see the needed node version from the .nvmrc in the root of the project.
Speed: With shell integration you can almost not even think about switching node versions as long as a .nvmrc file exists for the project and manual intervention is not required.
TIP: Save v18.x.x instead of saving the exact version like v18.12.1 in .nvmrc file. This will ensure then that whenever minor security updates are release you don’t have to worry about upgrading them into your project.
✨ Thank you for reading and I hope you find it helpful. I sincerely request for your feedback in the comment’s section.