In this guide, we will be showing you the straightforward steps to installing NodeJS on the Raspberry Pi.
Installing the NodeJS runtime on your Raspberry Pi is a straightforward process and only takes a couple of commands.
Alongside NodeJS, you will also install NPM to your Raspberry Pi. NPM is the default package manager for NodeJS and is what you will use to install additional modules.
Below is the list of equipment we used for installing NodeJS on the Raspberry Pi.
This tutorial was last tested on a Raspberry Pi 400, running the latest version of Raspberry Pi OS Bullseye.
How to Install NodeJS to the Raspberry Pi
This section will show you how easy it is to install the latest versions of NodeJS on the Raspberry Pi.
To make this process as easy as possible, we will be using the distributions provided by NodeSource. In addition, this team provides builds for Debian, which is what Raspberry Pi OS is built upon.
Additionally these NodeJS builds are also available for both 32-Bit and 64-bit ARM systems, perfect for our Raspberry Pi.
1. Before we begin installing NodeJS to our Raspberry Pi, let us first update the packages running on our operating system.
We can update the package list and upgrade any existing packages by using the following two commands.
sudo apt update sudo apt upgrade
2. For this next step, you will need to decide if you want the LTS (Long Term Support) release, or the latest version.
An LTS release is typically the most stable and is supported for at least 30 months from its initial release.
The latest release will have all of the newest improvements packed in but could potentially be more unstable.
Current Node.JS Release
To add the repository for the latest version of NodeJS to your Raspberry Pi, run the following command.
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
Long Term Support (LTS) Node.JS Release
If you prefer to use the current LTS release, use the command below.
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
3. With the NodeJS repositories added to our Raspberry Pi, we can proceed to install the runtime to our device.
As the script we ran in the previous step runs a package update, we simply need to install the package.
sudo apt install nodejs
4. To verify that we have now successfully installed NodeJS, we can run the following command.
This command will retrieve the version number from the runtime environment.
As we are running the LTS release (v16 at the time of Publish) of NodeJS, we got the following version string in our command line.
Installing Additional Development Tools
When using NPM to install additional modules you may have issues when the module needs compiling to support the native hardware.
We can install the “
build-essential” package to solve most of these issues. This package contains various tools used to compile software.
You can install this package to your Raspberry Pi by using the following command on your device.
sudo apt install build-essential
You should now have successfully installed NodeJS on your device at this point in the tutorial.
Thanks to its speed and relative ease of use, it is a fantastic framework to run on the Raspberry Pi.
If you have had any issues installing the software, please leave a comment below.
Be sure to check out our numerous other Raspberry Pi tutorials and guides.