Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nwawrzyniak/58d087f9d0ad70c3e41584b077e1f13e to your computer and use it in GitHub Desktop.
Save nwawrzyniak/58d087f9d0ad70c3e41584b077e1f13e to your computer and use it in GitHub Desktop.
A tutorial to build any version of Node.js on the original Raspberry Pi.

First of all: Building a modern version of Node.js on (and for) the Raspberry Pi 1 / Raspberry Pi 1B takes a really long time. We're talking about around 2 and a half days.

As an alternative you should think about cross-compiling for the Raspberry Pi, as it is way faster once you got it working.

If you still want to compile Node.js on the RPi 1, here is how to do it:

  1. Go to the official Node.js download page and grab the latest source files (from the section "Source Code"). I recommend the latest long-term-support version (currently version 14.17.5). This will also include npm 6.14.14.

  2. Extract the .tar.gz file into a new directory (e.g. cd ~/Downloads/node-[version]). I will refer to the new directory as the source directory.

  3. Make sure you have gcc and g++ installed. Both are included in the package build-essential, so if you're unsure whether you have them installed already just run sudo apt-get install build-essential.

  4. Since the RAM of the RPi 1 is too small to handle the huge amount of files, it will likely freeze in the build process. However, we can prevent this by increasing the RPi's "Swap" size. The default Swap size on the RPi is only 100MB. To increase the Swap size, simply open the file /etc/dphys-swapfile with an editor of your choice. We will take nano, since it is preinstalled on the Pi: sudo nano /etc/dphys-swapfile. Next, change the line CONF_SWAPSIZE=100 to something like CONF_SWAPSIZE=1024 (for 1GB) or even CONF_SWAPSIZE=2048 (for 2GB). Restart the Swap by running /etc/init.d/dphys-swapfile restart or restart the entire Pi (e.g. with reboot).

  5. Use cd to change into the source directory and run ./configure.

  6. Now comes the actual building part. The creators recommend to build with the command make -j4 to build on four cores simulataneously. Since the RPi 1 only has one core, we run nice make -k instead. nice prevents the Pi from freezing by lowering the build process' priority and -k makes the build process continuable in case of a power failure or if something else goes wrong. After ~2.5 days we should finish with exit code 0.

Done. if you want to install Node.js now, simply run

  1. sudo nice make install -k. In this case sudo is required because the installation path defaults to /usr/local/bin/node which is owned by root. Alternatively you could change the ownership of the directory by running sudo mkdir /usr/local/bin/node and chown -fR pi /usr/local/bin/node (if you changed the default user of your Raspberry Pi make sure to replace "pi" by whatever your new user name is). nice and -k serve the same purpose as before.

  2. Now you should test the success of the installation. This can be done with which node or with node -v. If you see an output confirming your installation path or version: Congratulations! You successfully installed Node.js on a platform that does not officially support it.

@kondo0429
Copy link

Thank you for this guide. I have installed node with Pi zero for 3 days. If this document were not here, I would have no way to use node 14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment