Update Node.js and npm safely

Identify the active installation, choose a supported Node release, check npm compatibility, and validate the project before rolling out an upgrade.

Best practices
Illustration of files, modules, and their dependencies

Update Node.js through the tool that already manages it. Choose a supported release that your project has tested, and check npm's runtime requirements before upgrading npm independently.

Identify the active installation

node --version
npm --version
command -v node
command -v npm

In PowerShell, use Get-Command node and Get-Command npm for the path checks. Determine whether a version manager, Homebrew, a system package manager, an installer, or a container image owns the runtime. A path alone may not identify its owner conclusively.

Do not layer another installation method over the same paths as a shortcut. For containers, update the base image and rebuild; changing Node inside a running container is not a reproducible release process.

Use nvm on macOS or a POSIX development environment

With nvm already installed and loaded in the shell:

nvm install --lts
nvm use --lts
nvm alias default 'lts/*'
node --version
npm --version

nvm install node selects the latest Current release. Current is useful for compatibility testing; LTS offers a different support lifecycle. Consult the official release schedule rather than treating “latest” as a deployment policy.

For a team project, record the selected version in .nvmrc and use nvm install followed by nvm use from that directory. A moving LTS alias is convenient locally; an exact tested version or pinned container artifact provides a more deliberate deployment target.

Match other platforms to their installation tool

Windows users can use the official installer or nvm-windows. nvm-windows is a separate project from nvm-sh and has different commands and behavior. Follow its own migration instructions.

On macOS, update the Homebrew formula you actually installed, or use the official installer if that owns the installation. Confirm which executable the shell selects afterward, including in a newly opened terminal.

Decide whether npm needs a separate update

Node distributions commonly include npm. Check whether the bundled version already meets your project's requirements. Before selecting a newer npm:

npm view npm@latest engines

After confirming compatibility and the installation manager's policy, npm install --global npm@latest installs the release tagged latest. You can instead select an agreed exact npm version. Global packages and npm itself may differ between version-manager installations; verify both versions after switching.

Validate and preserve a rollback path

Record the prior runtime, npm version, and lockfile format. In a test environment, follow the repository's installation process, build the application, run tests, and exercise service startup. Pay particular attention to native addons, module loading, and dependencies with Node engine constraints.

Keep the previous runtime or image available until the new release is verified. A runtime rollback does not reverse database migrations or application state changes; handle those separately in the deployment plan.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting