Install Node.js 16 and npm on Raspberry Pi

Install Node.js 16 and npm on Raspberry Pi

Node.js is an open-source runtime environment that allows to run JavaScript code on the server without a browser. It is based on Chrome's V8 JavaScript engine. Node.js is commonly used to develop web applications. NPM is a package manager for Node.js that allows to install packages from remote registry.

Node.js 16 is a long-term support (LTS) release. In this release the V8 JavaScript engine has been updated from 8.6 to 9.0. This tutorial shows how to install Node.js 16 and npm on Raspberry Pi.

Install Node.js and npm

Connect to Raspberry Pi via SSH and add NodeSource repository that maintains Node.js 16 binary distributions.

curl -sSL | sudo bash -

Run command to install Node.js:

sudo apt install -y nodejs

Note that, we don't need to install npm separately, it comes bundled with Node.js. After the installation is complete, check Node.js and npm versions:

node --version
npm --version

Testing Node.js

Navigate to your home directory and create a new main.js file:

cd ~
nano main.js

When a file is opened, add the following code:


console.log('Hello world');

Now use the node command to test a program:

node main.js

Uninstall Node.js and npm

We can remove any package with a name that starts with nodejs and anything related to it by running the following command:

sudo apt purge -y nodejs.*

We can also remove NodeSource repository and signing key:

sudo rm -rf /etc/apt/sources.list.d/nodesource.list
sudo rm -rf /usr/share/keyrings/nodesource.gpg

Install older versions

Node.js 14 is older LTS version that is still supported. It can be installed by adding the following NodeSource repository:

curl -sSL | sudo bash -

The 3 Comments Found

  1. Avatar
    Jhanvi Mehta Reply

    Very interesting blog post.Quite informative and very helpful. I’m a regular reader of your blog Thank you for providing such a nice piece of article. I’m glad to leave a comment. Expect more articles in the future.

Leave a Comment

Cancel reply

Your email address will not be published.