Update node and npm without breaking node-red

I am running on a Raspberry3 NR at V4.1 with underlaying node V18.20 which is the minimum setup.
As I experience some instability with my Pi I consider updating node to V20 or V22. Whats the best strategy to ensure no issues with the current NR installation?

  1. Using the node red_installer.sh script with argument --node20 ?
  2. Doing the basic stuff like npm update -g and npm cache clean -f

If you installed node-red using the script, best to use the script to make changes. I believe the script does everything necessary.

If you prefer to do things by hand. Install the new version of node.js - this requires manual installation or use of one of the 3rd-party repo's for Pi's follow the instructions on the node.js website. After upgrading, you should do:

sudo apt update && sudo apt upgrade
npm rebuild -g
npm update -g
cd ~/.node-red
npm rebuild
npm update

Then restart node-red and reload the editor if you already have it open in a browser tab.

The rebuild commands will re-make compiled binary libraries using the new version of node.js and the latest c++ and header files and is important when moving to a new major version of node.js. They will do nothing if you don't have any binary libraries in use (but on a Pi, you will almost certainly have at least the serial nodes).

1 Like

The official Raspberry Pi install script for Node-red is called
update-nodejs-and-nodered-deb, not node red-installer.sh

So as long as you are referring to the official script, and you originally installed with it, that's the way to go.

I think it will update to node 20 (or 22?) without you adding those options at the end.

You should backup everything first just in case it's not a standard installation.

Thanks for the advice:

Indeed the installer script has a different name. I was just renaming the downloaded script for a more simple name.

I did the manual update. As from V18 to 20 this is a major jump you need to download a script:

curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -

after that updates of nodejs and npm was as expected.
I skipped the step npm update in my .node-red directory as I intentionally need some old version of node_modules

NR V4.1 is running fine now with nodejs 20.19.5

1 Like

Glad you have it working.

Indeed, the official script does have a rather unwieldy name. On the occasions when I download it, I call it nrscript.

Just in case others are seeking how to do this, on Linux you don't need to run any other script than the official one. It does all the downloads and installs in the background.

Actually there are two official scripts, one for Debian based Linux and one for distributions using rpm - Reg Hat & co.

2 Likes

Not necessary, the script will do that for you
bash <(curl -sL https://github.com/node-red/linux-installers/releases/latest/download/update-nodejs-and-nodered-deb) --node20

I recommend using 22 rather than 20. Use --node22 for that.

This script will also reinstall node-red itself. That's not what I wanted.

True, it will do that. Why does that bother you?