A Practical Guide to NVM
Node.js 19 was released on October 18, 2022. It comes with npm 9 and many new features. Are you ready to try it?
As we said in the previous article, NVM (Node Version Manager) is the best way to upgrade node.js and npm versions. It can help us reduce the risk.
This is a rewrite with new versions of
nvmnode.js, and npm.
nvm Manages node.js and npm versions. It is designed to be installed per user and implemented per shell.
nvm Works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), especially on Unix, macOS and windows WSL.
, latest version of
0.39.2and curl it or . can be installed by
install.shnvm clones the repository
~/.nvmand tries to add the source lines to the correct profile file from the snippet below (
in profile file, e.g.
~/.zshrcWe see that the above lines have been added.
After nvm is installed, we can use the following command to install the latest version of node.js:
The above output (line 7) tells that npm
8.19.2 node.js . is used with
19.0.0, This can be verified by the following:
We can also specify the exact version to be installed. The semantic versioning format is defined by SemVer:
If the specific version has already been installed, it will not be installed again:
What to do to upgrade npm to version 9?
We can list all installed versions:
The arrow in the above output shows that the current version of node.js is
19.0.0 (line 11). It also shows values for
19.0.0line 16), and
nvm use Current version changes:
you might be surprised how
v10.14.0 Uses a later version of npm (line 2)
v14.20.1 (line 6). The following commands can achieve this:
As we know, npm 8 dropped support for node.js 10. Edition
10.14.0 npm. can’t install
The following command will get the latest supported npm version on the current node version:
19.0.0The latest working version of npm is
nvm use Sets a specific version for the current shell. If you start a new shell the newly set node.js version will be lost.
How can we make a specific node version persistent?
The default version is the one carried over all shells.
nvm alias Can set default version.
.nvmrc The file can be created for convenience, which takes the SemVer format, or
nvm which will use the version specified in
.nvmrc file if no version is provided on the command line.
We can check the current version with the following command:
ls-remote Lists all available versions, but be prepared for a very long list.
% nvm ls-remote
More specifically, providing a partial version can reduce the available list.
nvm which Shows the path to the executable where it was installed. We have installed node.js of
19.0.0, are here
nvm which Result:
A specific node version can be used to run the app directly:
% nvm run 14.17.6 app.js
Alternatively, the following command runs
node app.js pointing to node along path
% nvm exec 14.17.6 node app.js
If you want to find more
nvm command, run the help command:
we can use
nvm To upgrade node.js and npm. how can we upgrade
nvm on one’s own?
Before the upgrade, we have
% nvm --version
We upgrade it to the version
As stated in the output (line 10), we have to close and reopen the terminal to use the new version:
% nvm --version
nvm Makes it easy to manage node.js and npm versions. We can upgrade to node.js 19 and npm 9 as well as any previous version, listed as follows:
Thanks for reading.
Want to Connect?If you are interested, check out my directory of web development articles.