You might be wondering why you should update Node.js to the latest version. Well, there are a couple of reasons to justify it:
Because of these factors, it is advised to keep your Node.js updated to the latest version.
Let's see how to update Node.js by going through the following steps:
1. Open your terminal and check the Node.js version installed on your Mac.
$node --version vx.y.z
2. Install n package globally using NPM. 'n' is the version manager of Node.
$npm install -g n
While installing a package, if you get "Error: EACCES: permission denied" error, then run the command as sudo
.
$sudo npm install -g n
3. After that, using the installed n package, you can perform the following tasks:
Install the latest LTS version:
$sudo n lts
You can install the latest release of Node.js:
$sudo n latest
Install the latest stable release:
$sudo n stable
You can also install a specific version of Node.js:
$sudo n version.number
Example: $sudo n 16.15.0
4. You can verify that the Node.js is updated successfully by running the node --version
command.
$node --version vx.y.z