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.
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.
Preparing for the Node.JS repository
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 existing packages using the following two commands.
sudo apt update sudo apt upgrade
2. Our next step is ensuring we have all the packages we need to access the Nodesource repository.
Install these packages by using the following command in the terminal.
sudo apt install -y ca-certificates curl gnupg
Setting up the NodeSource Repository on the Raspberry Pi
3. With our Raspberry Pi up to date, we can now set up the NodeSource repository.
This repository will allow us to install the latest versions of NodeJS to the Raspberry Pi easily.
Let us start this process by downloading the Nodesource GPG key and storing it within the “
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg
4. With the GPG key stored on our Raspberry Pi, we can now the Nodesource Node.JS repository to the sources list.
Before we do this, you must decide what NodeJS version you want to install. Use the relevant line for which version you would like to install. If a newer release exists, replace the number with that version.
These lines simply set an environment variable we will reference in the next step.
- LTS Release
- Current Release
5. Using the following command, You can now add the Node.JS repository to your Raspberry Pi’s sources list.
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
6. Since we made changes to your sources list you will need to run an update of the package list again.
Update the package list on your Raspberry Pi by using the following command.
sudo apt update
Installing Node.JS on the Raspberry Pi
7. 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
8. 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.