How to update Node.js to the latest version on Mac?

You might be wondering why you should update Node.js to the latest version. Well, there are a couple of reasons to justify it:

  • Every new version of Node.js comes with new features, security patches, and bug fixes.
  • Also, many JavaScript libraries need the latest Node.js version.

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
Check Node.js version

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.

Error: EACCES permission denied

$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
Latest LTS version

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
Version checking of Node.js

Recommended Posts