Choose nodejs version on Pi before installing Node-RED


I'm looking for a way to set my nodejs version to version 8 that isn't nvm...

I've tried using Debian form the command line:

curl -sL | bash -
apt-get install -y nodejs

But this just installed the latest version... has anyone got any advice on how best to install an older version of node? I'm installing it to a Raspberry Pi 3.


Do you realise that nodes v8 is End of Life in December?

But you can download the release from the versions link onto page link above

Could we ask whay you are wanting to install an older version of node.js as there may be better solutions to your issue?

You forgot apt-get update, but also I think you would need apt-get remove nodejs before installing it to get rid of the old one. In addition if your distribution has a later version in it's repositories then it will install that one. You would have to explicitly instalal the version you want and the pin it to prevent it being updated.
However, as has already been pointed, it probably isn't a good idea anyway.

Thanks for the welcome cymplecy. I'm using a package/node-RED node called noble to scan for BLE devices and measure tilt. Noble is awaiting a patch to work with nodejs v10 on a Pi so currently v8 is what I need to use this package/node...

Hi ukmoose. Yeah I'm aware that it's no longer supported from Jan but the package I'm using (noble) is awaiting a patch to work with nodejs v10 on a Pi so I'm going to have to persevere with v8 until that happens...

Thanks Colin. I'm running the Debian script from a band new flash of Raspbian Buster Lite so assumed that as no version of nodejs was present that it would pin which ever version I had pointed at. I'm going to try a manual install but will also try using apt-get remove nodejs before I try another install using the Debian approach...

I am pretty sure that Buster will have a version of nodejs > 8.x in its repository. The result is that when you add the nodesource for version 8 that apt will see both the 8.x version in the nodesource repo and the later version in the Buster repo. When you install the default (which is sensible) is to use the latest version from any configured source, which will be the Buster one. So to install v8 you have not only to provide the nodesource repository but also to explicitly install that version. If you run
apt-cache policy nodejs you will see all the versions available.

The current version in Buster is 10.15.2:

However, I tend to use the Nodesource repository, they are more up to date and contain everything in a single package. The Debian version is split into many different packages (node, npm, dependencies, ...)

I use the following sources in my /etc/apt/sources.list.d/nodesource.list

deb buster main
deb-src buster main

But be aware that these won't work on older ARMv6 SoCs like the Pi Zero!

so yes - to clean up... - remove nodejs sudo apt-get purge nodejs, then remove the current repository
sudo rm /etc/apt/sources.list.d/nodesource.list , then refresh the apt-cache ,sudo apt-get update- and then redo your install nodejs 8 command from above

curl -sL | bash -
sudo apt-get install -y nodejs=8.16.2

that should get you nodejs 8
If you already have Node-RED installed then you will also need to rebuild any nodes with binary code

cd ~/.node-red
npm rebuild

I don't think so, I think it will get version 10 from the Buster repository, since by default apt will get the latest version available from any of it's repos.

Ok you should be able to use

sudo apt-get install nodejs=8.16.2

after the initial curl command has run to add the nodesource repo to the list.
(also edited above)

Nearly, with apt you have to use the full version id so it would be something like
sudo apt install nodejs=8.16.2-1nodesource1
the exact id would be found using apt policy nodejs.
There is still more to do though, as the next time that apt upgrade is run it would upgrade it to 10.x again. The solution is to tell apt to hold the package at the current version using
sudo apt-mark hold nodejs
which would prevent it being updated. To unmark it later use
sudo apt-mark unhold nodejs

Thanks for all the feedback folks, much appreciated... :+1:

I've been able to install node 8 using a combination of the advice given. The issue then arises when I run the bash script to install node-RED... on closer inspection the script looks for the current version of node at file path /usr/bin/local/node and if it either doesn't find an LTS version or one older than version 7 it defaults to installing the most recent node version. I've ran some of the individual bash commands in the terminal to check that my version of node 8 is visible to the script (which it is) but when I run the script it still ignores this and installs the latest version... :man_shrugging: I've got a local solution in that a colleague has an image of node 8 and Raspian Jessie which lets me move forward but may not be a long term solution unfortunately...

You could download the script an comment out the nodejs lines.

But the long term solution is for the contrib node to be updated.

If forcing a version of nodejs I think it would be better not to use the script. Install node-red manually in the normal way.