Raspberry Pi

How to Update Node.js on Raspberry Pi

Node.js is an open-source, cross-platform tool that runs JavaScript code outside the browser. It allows developers to utilize JavaScript to write command-line tools and server-side scripting, enabling them to run the server-side script for producing dynamic web content.

Node.js is already installed in most Linux systems, including the Raspberry Pi system; however, it’s not an updated version. So, in this article, you will see different ways to update Node.js on the Raspberry Pi system.

Update Node.js on Raspberry Pi

To update Node.js on Raspberry Pi, follow the below-mentioned methods:

Before going straight toward the methods’ description, let’s find out the version of Node.js installed on the system using the following command:

$ node -v

Since the latest version of Node.js is “19.1.0” while on the Raspberry Pi system it’s “12.22.12”. Thus, we should update the version for improved security and enhanced features.

Method 1: Update Node.js on Raspberry Pi Through Node Module

Node module is a Node Package Manager (NPM) part that allows you to install the latest version of Node.js on your Raspberry Pi system. To install this module, follow the below-mentioned command:

$ sudo npm install -g n

After the NPM installation, you can install the latest version of Node.js through the “n” module using the following command:

$ sudo n latest

Wait for the installation to complete and you can see the Node.js version number on the terminal screen. You can confirm the Node.js update process through the following command:

$ node -v

You may close the terminal, reopen it and apply the “node -v” command to confirm the update.

Method 2: Update Node.js on Raspberry Pi Through Node Version Manager

Node Version Manager (NVM) is a tool to update and switch to any Node.js version easily. To download and install this tool on Raspberry Pi, follow the below-given command:

$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

Alternatively, you can also use the “curl” command to install NVM on Raspberry Pi.

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

Confirm the NVM installation through the following command:

$ nvm -v

In case the “nvm” command is not found close to the terminal, reopen it and apply the “nvm -v” command again to confirm the installation.

After installing the NVM, use the command below to install the latest Node.js version Raspberry Pi.

$ nvm install stable

You can confirm the Node.js latest version through the following command:

$ node -v

That’s all from this writeup.

Conclusion

Node.js is a tool for running JavaScript code outside the browser. Having the latest version of Node.js adds the latest security features and improves the tasks’ efficiency. You can easily update Node.js on Raspberry Pi through node module (n) and Node Version Manager (NVM). Both methods install the latest version of Node.js and automatically update it with the old version installed on your Raspberry Pi system.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.