This may work:

nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION

For example:

nvm install 6.7 --reinstall-packages-from=6.4

then, if you want, you can delete your previous version with:

nvm uninstall OLD_VERSION

Where, in your case, NEW_VERSION = 5.4 OLD_VERSION = 5.0

Alternatively, try:

nvm install node --reinstall-packages-from=current

Or you can update to the last long-term support version with

nvm install lts --reinstall-packages-from=current
Answer from gabrielperales on Stack Overflow
Discussions

How to not have to re-install all packages again after upgrading node version using NVM?
Nvm has a flag for that when you switch. Read the docs. More on reddit.com
🌐 r/node
18
10
January 5, 2025
updating node with nvm on ubuntu running pm2 - version not found issue
You need to install/update glibc https://askubuntu.com/questions/736208/upgrading-glibc More on reddit.com
🌐 r/node
10
0
August 7, 2022
Nvm or homebrew for Node install
I use homebrew to install nvm then install node via nvm ¯\(ツ)/¯ More on reddit.com
🌐 r/webdev
34
19
April 12, 2023
Node.js v16 ships with a new binary "corepack", which is an experimental tool to help with managing versions of Node.js package managers.
Setting up nodejs environment for onboarding in 2025: first install node version manager: yay -S nvm install Node.js: nvm install 22 install old version of yarn that is capable of installing the latest yarn: npm install yarn install the latest yarn that is capable of installing corepack-manager: yarn install yarn (because no 2 yarns are the same) install corepack-manager: yarn install corepack-manager update corepack as the default version will not work: corepack-manager update corepack --latest --force --delete --yes install the latest yarn that is only available via the latest corepack: corepack install yarn@next finally install all dependencies in the project: yarn install ERROR: could not install "is-odd": undefined is not a member of [Object object] More on reddit.com
🌐 r/programmingcirclejerk
20
106
December 27, 2022
🌐
NodeSource
nodesource.com › blog › update-Node.js-versions-on-MacOS
How to Update Node.js Versions on MacOS
January 31, 2025 - Update Homebrew to ensure you have the latest package definitions: brew update · If Node.js is not installed, run: brew install node · If you already have Node.js and want to upgrade: brew upgrade node ... If you installed Node.js via Homebrew, this method is the simplest and most recommended ...
🌐
GitHub
github.com › nvm-sh › nvm
GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
You can also install and migrate npm packages from specific versions of Node like this: nvm install --reinstall-packages-from=5 6 nvm install --reinstall-packages-from=iojs v4.2 · Note that reinstalling packages explicitly does not update the npm version — this is to ensure that npm isn't accidentally upgraded to a broken version for the new node version.
Starred by 90.4K users
Forked by 9.7K users
Languages   Shell 98.0% | Makefile 1.2%
🌐
SitePoint
sitepoint.com › blog › javascript › installing multiple versions of node.js using nvm
Installing Multiple Versions of Node.js Using nvm — SitePoint
March 3, 2025 - While NVM’s primary focus is on Node.js, there are community-maintained projects like “pyenv” for Python version management that are inspired by NVM’s concept. You can update NVM using the command nvm update.
🌐
npm
docs.npmjs.com › downloading-and-installing-node-js-and-npm
Downloading and installing Node.js and npm | npm Docs
To publish and install packages to and from the public npm registry or a private npm registry, you must install Node.js and the npm command line interface using either a Node version manager or a Node installer. We strongly recommend using a Node version manager like nvm to install Node.js and npm.
Find elsewhere
Top answer
1 of 16
1896

Use n module from npm in order to upgrade node

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

To upgrade to latest version (and not current stable) version, you can use

sudo n latest
  • Fix PATH:

      sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
    
  • To undo:

      sudo n rm 6.0.0     # replace number with version of Node that was installed
      sudo npm uninstall -g n
    

You may need to restart your terminal to see the updated node version.

Found in David Walsh blog

2 of 16
666

NodeSource provides binary distributions of Node.js; complete installation instructions can be found here. The instructions have been copied below for your reference. Instructions are the same for updating to the latest version.

Run once:

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Run whenever you want to change the major version of Node.js:

NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y

Prior to August 2023: Previously versions of this answer involved the use of a series of setup_XX.x scripts that you'd run to install/update Node.js:

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

But as @eis pointed out, these scripts are no longer supported. To see the previous answers, please look at the edit history for this answer.

🌐
Bacancy Technology
bacancytechnology.com › qanda › node › upgrade-node-js-using-nvm
How to Properly Upgrade Node.js Using NVM
April 17, 2025 - 3. Install the desired Node.js version: Choose the version you want to upgrade to and install it. For example, to install the latest LTS version: nvm install --lts Alternatively, to install a specific version (e.g., 18.16.0): nvm install 18.16.0
🌐
freeCodeCamp
freecodecamp.org › news › node-version-manager-nvm-install-guide
Node Version Manager – NVM Install Guide
September 9, 2022 - By Dillion Megida In this article, I'll explain how you can install NVM, or Node Version Manager, on Windows, Linux, and Mac. What is NVM? Node Version Manager (NVM), as the name implies, is a tool for managing Node versions on your device. Differen...
🌐
Hostman
hostman.com › tutorials › how to update node.js version
How to Update Node.js Version - Comprehensive Guide
September 10, 2025 - Learn how to update Node.js version with this step-by-step guide. Explore multiple ways like NVM, binary packages, package managers, and more.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Mend
mend.io › blog › how-to-update-node-js-to-latest-version
How To Update Node.js To Latest Version
October 31, 2024 - Before installing nvm-windows, it’s recommended to uninstall any available Node.js versions from your machine. This will avoid potential conflict issues during installation. Next, you can download and run the latest nvm-setup.zip installer. Also, since the utility runs in an Admin shell, you’ll need to begin the Command Prompt or Powershell as an Administrator before using it. If you want to install and upgrade to a specific version, you can run the following: You can specify to update to the newest LTS version by running:
🌐
Tericcabrel
blog.tericcabrel.com › upgrade-nodejs-version-nvm
Upgrade Node.js using NVM the right way
August 28, 2025 - This post shows how to use Node Version Manager (NVM) to upgrade Node.js and automatically install the global packages in the current version.
🌐
Better Stack
betterstack.com › community › questions › how-to-upgrade-node-js-on-macos
How to Upgrade Node.js to the Latest Version on Mac OS? | Better Stack Community
To upgrade Node.js to the latest version on macOS, you can use a version manager like nvm (Node Version Manager) or directly download and install the latest Node.js version from the official website.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to update node.js version on linux, windows, and macos
How to Update Node.js Version on Linux, Windows, and macOS
3 days ago - 3. Close and reopen the terminal ... of the list to find the latest one. 7. To install the latest version, use the nvm command with the specific Node.js version:...
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › update-node-js-and-npm-to-latest-version
How to Update Node.js and NPM to the Latest Version (2025) - GeeksforGeeks
July 15, 2025 - To update Node and NPM to the latest versions we can use various methods like nvm (node version manager), node.js Windows installer, npm, and homebrew for macOS.
🌐
DEV Community
dev.to › xxzeroxx › how-to-update-nodejs-5d6d
How to Update Node.js - DEV Community
November 2, 2024 - Download and install NVM for Windows. ... Go to the official Node.js website: nodejs.org. Download the latest version (LTS recommended). Run the installer and follow the instructions.
🌐
Node.js
nodejs.org › en › download
Node.js — Download Node.js®
InfoWant new features sooner? Get the latest Node.js version instead and try the latest improvements!
🌐
Muffin Man
muffinman.io › blog › nvm-updating-npm
How to update npm using nvm · Muffin Man
# navigate to nvm's node lib folder # (replace v8.4.0 with your version) cd ~/.nvm/versions/node/v8.4.0/lib/ # update npm right there npm install npm # reopen your terminal
🌐
DreamHost
help.dreamhost.com › hc › en-us › articles › 360029083351-Installing-a-custom-version-of-NVM-and-Node-js
Installing a custom version of NVM and Node.js – DreamHost Knowledge Base
If so, you'll need to update the security controls on each newly downloaded binary file before it will work. Run the following command as your user after each new version you download: [server]$ setfattr -n user.pax.flags -v "mr" $(find $NVM_DIR -type f -iname "node" -o -iname "npm" -o -iname "npx")