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:
-
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.
-
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. -
Make sure you have
gcc
andg++
installed. Both are included in the packagebuild-essential
, so if you're unsure whether you have them installed already just runsudo apt-get install build-essential
. -
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 takenano
, since it is preinstalled on the Pi:sudo nano /etc/dphys-swapfile
. Next, change the lineCONF_SWAPSIZE=100
to something likeCONF_SWAPSIZE=1024
(for 1GB) or evenCONF_SWAPSIZE=2048
(for 2GB). Restart the Swap by running/etc/init.d/dphys-swapfile restart
or restart the entire Pi (e.g. withreboot
). -
Use cd to change into the source directory and run
./configure
. -
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 runnice 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
-
sudo nice make install -k
. In this casesudo
is required because the installation path defaults to/usr/local/bin/node
which is owned byroot
. Alternatively you could change the ownership of the directory by runningsudo mkdir /usr/local/bin/node
andchown -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. -
Now you should test the success of the installation. This can be done with
which node
or withnode -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.
@richsad Glad to hear this was helpful!