Hi,
After encountering problems with an installation of NodeJS 20, I thought I'd do it properly this time: install NodeJS first, then Node-RED. Unfortunately, the installation script removes the existing version and reinstalls an older version of NodeJS 20. Is there a way to make the script ignore the existing NodeJS 20 installation?
Stop Node-RED ✔
Remove old version of Node-RED ✔
Remove old version of Node.js ✔ 20.19.2+dfsg-1+rpi1
Install Node 20.19.1-1nodesource1 ✔ v20.19.1 Npm 10.8.2
Clean npm cache ✔
Install Node-RED core ✔ 4.1.2
Move global nodes to local -
Npm rebuild existing nodes ✔
Install extra Pi nodes ✔
Add shortcut commands ✔
Update systemd script ✔
Problem: after apt update, there's an issue:
The previously unselected package nodejs-doc is now selected.
Preparing to unpack .../12-nodejs-doc_20.19.2+dfsg-1+rpi1_all.deb ...
Unpacking nodejs-doc (20.19.2+dfsg-1+rpi1) ...
Errors were encountered while processing:
/tmp/apt-dpkg-install-fGsAiu/01-node-corepack_0.24.0-5_all.deb
Error: Sub-process /usr/bin/dpkg returned an error code (1)
I then need to run apt --fix-broken install and rm -f /etc/apt/sources.list.d/nodesource.list to get 20.19.2+dfsg-1+rpi1 back.
Run sudo apt remove nodejs
then check it is gone node -v
The script should have removed it, but it may be that there is a problem doing that. In which case the above commands may show it.
indeed - the latest version of the script should explicitly test for dfsg versions and remove them in favour of nodesource ones.
but yes - adding --node20 or --node22 to the end of the install command should force it to install a suitable version. If I use --node20 locally I get v20.19.6 which is newer than the dfsg version...
I've now installed the script with NodeJS 22 without any problems. NPM: 10.9.2.
With NodeJS 20, the aforementioned problem occurs on Trixies own NodeJS 20.
I don't feel confident enough to manually install Node-RED with: sudo npm install -g --unsafe-perm node-red.
That would leave me with an outdated NPM version (9.x) from Trixie repo.
I think it is the best to install Node-Red with NodeJS 22 on Trixie.
my VM with Ubuntu 24.04LTS is similar: I installed Node-Red with NodeJS 20, the Ubuntu repo would install NodeJS 18 ==> no conflicts.
I would never recommend using a Linux distro's own repositories for node.js, they will often be outdated. Either use Dave's script or use the dedicated node.js repository for your OS. Noting that I believe Dave's script uses the dedicated repository for Debian/Rabian/Ubuntu.
you really don't want to use the default repository for nodejs - it always (IMHO) ends up causing issues - either well behind - or doesn't include npm - or occasionally (as in this instance) appears to be ahead, but includes other weird side packages... Much better to let our install script try to clean it up and install the nodejs nodesource version. (But I would say that )
That's exactly what I've always done, but with Trixie there are problems as described above.
after Node-Red script has finished and you´ll do apt update && upgrade, Trixie reinstalls its own version and mixes corepack and maybe other packages, and this is where the error occurs.
The previously unselected package nodejs-doc is now selected.
Preparing to unpack .../12-nodejs-doc_20.19.2+dfsg-1+rpi1_all.deb ...
Unpacking nodejs-doc (20.19.2+dfsg-1+rpi1) ...
Errors were encountered while processing:
/tmp/apt-dpkg-install-fGsAiu/01-node-corepack_0.24.0-5_all.deb
Error: Sub-process /usr/bin/dpkg returned an error code (1)
I've to choose NodeJS 22 to prevent this.
But is there a solution to prevent apt mixing its 20.19.2+dfsg-1+rpi1 packages into an existing NodeJS20 version (from Node-Red script)??
What I see (on a Pi Zero2, 64 bit OS with Node-red 5 beta) Before:
$ node-red --version
Node-RED v5.0.0-beta.1
Node.js v24.11.1
Linux 6.12.47+rpt-rpi-v8 arm64 LE
$ sudo apt update && sudo apt -y full-upgrade
...
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
Warning: https://deb.nodesource.com/node_24.x/dists/nodistro/InRelease: Policy will reject signature within a year, see --audit for details
Upgrading:
libpng16-16t64 nodejs rpi-eeprom
...
Get:3 https://deb.nodesource.com/node_24.x nodistro/main arm64 nodejs arm64 24.12.0-1nodesource1 [36.9 MB]
After:
$ node-red --version
Node-RED v5.0.0-beta.1
Node.js v24.12.0
Linux 6.12.47+rpt-rpi-v8 arm64 LE
Meanwhile I have found and fixed the underlying nodejs-v20 install issue that was causing grief to the OP. So both node20 (default) and node22 and node24 installs (using the script) should all work OK.