Skip to content

Instantly share code, notes, and snippets.

@ShivKumarSaini
Last active April 23, 2022 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShivKumarSaini/a87fec9608a1f95ba67da113ce9ea764 to your computer and use it in GitHub Desktop.
Save ShivKumarSaini/a87fec9608a1f95ba67da113ce9ea764 to your computer and use it in GitHub Desktop.
Updating node.js version on Linux machine

Update Node.js with NVM and keep packages

Usually when new version of Node.js comes out and you update it by just installing new and removing old one, all of your global NPM packages are gone. Here is how to update to new version of Node and reinstall packages:

Install/update NVM first

For Windows, use nvm setup from "https://github.com/coreybutler/nvm-windows/releases".

Go to URL "https://github.com/creationix/nvm" and follow install/update instructions.

Command

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

Usage example

$ nvm install <version e.g. 16.14.2>
$ nvm use <version e.g. 16.14.2>
$ nvm install 8.9.4 --reinstall-packages-from=6.10.0

And uninstall old version

$ nvm uninstall 6.10.0

In case error "If --reinstall-packages-from is provided, it must point to an installed version of node." occurs

$ nvm install 8.9.4

Credits: https://gist.github.com/frenchbread/d70cb4529073f5196faf7bd2e0464fb5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment