How to update Node to the latest version?

Node.js is a JavaScript runtime environment that runs on the V8 JavaScript engine and executes JS code outside a web browser. When developing locally, you’ll want to ensure that you keep Node updated for various projects to ensure you’re protecting applications from vulnerabilities and bugs.

NVM is a great tool for installing different versions of Node and switching between different versions for various projects. You’ll first want to install NVM. Once installed, you can install versions by doing the following:

Run nvm install [version] within the command line (replacing [version] with the version of Node you’d like to install).

Useful NVM commands

// check version of Node
node -v // can also use node --version

// list all locally installed versions of Node
nvm ls

// install specific version of Node
nvm install 20.10.0

// set default version of Node
nvm alias default 20.10.0

// switch version of Node
nvm use 20.00.0

// install latest stable version of Node
nvm install stable

How to specify what version of Node to use in a specific project

Within a project’s root directory, you can specify the version of Node that NVM should load by creating a .nvmrc file. You can generate this file by running the following command in the project’s root directory: node --version > .nvmrc

Leave a Reply