Install NodeJS on a Raspberry Pi Zero

Published: October 1st, 2020 - 3 minute read.
node-pizero

A Raspberry Pi Zero combined with NodeJS can be a very capable device, allowing you to run NodeJS apps locally for setups such as Homebridge, or your own dev server for testing your NodeJS apps. However, it can be difficult to install NodeJS on lower-powered devices such as the Pi Zero. This guide will walk you through the steps required to install NodeJS on a Raspberry Pi Zero and Zero W.

NodeJS Support for Pi Zero

The Pi Zero uses a Broadcom BCM2835 SoC, which has an ARM processor that uses an ARMv6 instruction set. To install NodeJS, an ARMv6 build is required. However, NodeJS doesn't officially support the ARMv6 build required by the Pi Zero as of NodeJS 12 and later. It has now been demoted to experimental status, and while they do provide unofficial builds on the website, these binaries are automatically generated and could break between releases. So proceed with caution, as these builds aren't fully tested and could cause issues depending on which version of NodeJS you install. If you aren't comfortable running the unofficial builds, you can also install an older version of NodeJS 11.x which still supports the ARMv6 binaries.

NodeJS Install Steps for Pi Zero

Go to the unoffical builds download page and select the version of NodeJS you want to install. Click the link to go to the folder containing the different builds and copy the link to the latest ARMv6 version of NodeJS (Select the link with the .xz extension). Use wget in the terminal to download the latest binaries.

wget <link to NodeJS ARMv61 from nodejs.org>

#Example: wget https://unofficial-builds.nodejs.org/download/release/v14.13.0/node-v14.13.0-linux-armv6l.tar.xz

Make sure you're in the same directory as the binary you just download. You can use the ls command to list all files. Extract the binary from the tarball file using the following command.

tar xvfJ <file.tar.xz>

# Example: tar xvfJ node-v14.13.0-linux-armv6l.tar.xz

Copy the contents of the extracted tarball file to the usr/local directory on your Pi Zero.

sudo cp -R <extracted tar folder>/* /usr/local

# Example: sudo cp -R node-v14.13.0-linux-armv6l/* /usr/local

You can now clean up by removing tarball file you downloaded and the extracted folder. This command will remove any file or folder beginning with 'node-' in your current directory. Make sure you don't have any important folders using this prefix as they will also be deleted.

rm -rf node-*

Reboot your Pi and log back in to make sure everything worked correctly.

sudo reboot

You can now run the following command which will check what version of NPM and NodeJS are currently installed on your Pi Zero.

node -v && npm -v

Extra steps

You might have to do the following if you receive a 'command not found error'. First, open the .profile file using nano.

sudo nano ~/.profile

Add the following line to the end of the file and hit Ctrl + X to save, and then hit 'y' and enter to confirm the changes.

PATH=$PATH:/usr/local/bin

Reboot your Pi Zero using the reboot command above and once the Pi has finished rebooting, log back in and try running the final command to display which version of NodeJS and NPM is currently installed.

Wrap Up

You now have your own Raspberry Pi Zero running the latest version of NodeJS. You can create your own apps and test them locally on your home network, or install projects from other creators with NPM.

Previous Post

Host your own analytics service for free with Umami

Next Post

Add a back button to your Next.js app