The proper way to upgrade Node.js
By Mario Kandut
There is a new major Node.js release version every 6 month (on average), so it keeps getting better and easier to use. 😎 A result of a continuous release cycle of Node.js is that existing applications are written aiming at a moving target, and applications have to be updated on a regular basis to ensure a working state in the future and no big version and feature jumps occur causing a big amount of adaption.
The Node.js community provides Long Term Support (LTS) releases to guarantee that the environment won't change for a fixed period. With LTS you get:
💰 Start your cloud journey with $100 in free credits with DigitalOcean.
Major Node.js versions enter Current release status for six months. After six months, odd-numbered releases (9, 11, etc.) become unsupported, and even-numbered releases (10, 12, etc.) move to Active LTS status and are ready for general use. Use only Active LTS or Maintenance LTS releases in production.
image credit: Node.js Relases
For updating Node.js there are several options available depending on the way you first installed it.
If you installed Node.js via downloading the official package, the package will already contain an installer which detects an existing version of Node.js. Hence, you just download the LTS version that fits your use case and run the installer.
The recommended way to install Node is via NVM (Node Version Manager), because you can manage multiple versions of Node.js.
If you have used
nvm to install Node.js, upgrading to a new version is one line.
You can install a new Node.js version or basically any Node.js version using
nvm install <VERSION>, like
nvm install 10.16.3 or just install the latest LTS version with
nvm install node.
After installing the node version you want to use, you have to switch to it with
nvm us <VERSION>, like
nvm use 10.16.3 or
nvm use --lts.
Homebrew is a very popular way to install software on Mac and upgrading Node.js is simple.
# update homebrew brew update # upgrade Node.js brew upgrade node
nvm(node version manager).
Thanks for reading and if you have any questions, use the comment function or send me a message @mariokandut.
Never miss an article.