Updating node-red on RPi

I am running node v14.17.0 and npm v7.15.0 on a Pi 4

I have an old install of node-red v 1.1.2 that I would like to upgrade, but I am hitting problems:

Using the official install script https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered (which I understand is supposed also to update), I just saw node and node-red being removed and then it failed.

Next (after restoring my system from a backup taken just before running the script) I tried:

apt-get install nodered

but that got:

nodered : Depends: nodejs (>= 10) but it is not installable
           Depends: npm (>= 5.8) but it is not installable
E: Unable to correct problems, you have held broken packages.

I'm really stuck. Can anyone help please?

EDIT: I have checked for held packages with various tools, including dpkg --get selections | grep hold but nothing shows up.

What did it show. What was in the log.

I'm pretty sure that tries to install a pretty old version of node-red.

Could you try the V2 (currently in development but so far it works well)...

Thanks for replying. I don't have the logs from the first go, which is remiss of me, but I was keen to get back to the status quo ante so I restored enthusiastically!

I'm just going to backup my test platform again and then I'll try with the V2 script and report back.

Don't know what's happening here. It "helpfully" blew away node and npm and then seems to complain that it can't find them. (This, however, is log from a second run. I am going to go through the restore and run again, to see exactly what's happening when a valid node and npm install actually exists.)

Running Node-RED update for user pi at /home/pi on raspbian


This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of Node.js       ✔   
  Install Node.js 14 LTS              ✘   Bad install:  Node.js missing  Npm missing - Exit
  Clean npm cache                     
  Install Node-RED core               
  Move global nodes to local          
  Npm rebuild existing nodes          
  Install extra Pi nodes              
  Add shortcut commands               
  Update systemd script               
                                      

Any errors will be logged to   /var/log/nodered-install.log

pi@homebridge:~ $ cat /var/log/nodered-install.log
OLD nodejs 0 :
NEW nodejs 14 :

***************************************

Started : Mon 31 May 13:02:21 BST 2021
Running for user pi at /home/pi
Found global nodes:   :

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'nodered' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Installing nodejs 14

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'npm' is not installed, so not removed
Package 'nodejs' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
dpkg: warning: ignoring request to remove nodejs which isn't installed
dpkg: warning: ignoring request to remove node which isn't installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Grab the LTS bundle

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
curl is already the newest version (7.64.0-4+deb10u2).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

## Installing the NodeSource Node.js 14.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://phoscon.de/apt/deconz buster InRelease
Hit:3 http://archive.raspberrypi.org/debian buster InRelease
Hit:4 https://deb.nodesource.com/node_14.x buster InRelease
Hit:5 https://repo.mosquitto.org/debian buster InRelease
Reading package lists...

## Confirming "buster" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_14.x/dists/buster/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
gpg: WARNING: unsafe ownership on homedir '/home/pi/.gnupg'

## Creating apt sources list file for the NodeSource Node.js 14.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x buster main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x buster main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Hit:3 http://phoscon.de/apt/deconz buster InRelease
Hit:4 https://deb.nodesource.com/node_14.x buster InRelease
Hit:5 https://repo.mosquitto.org/debian buster InRelease
Reading package lists...

## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn



WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package nodejs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  nodejs-doc

E: Package 'nodejs' has no installation candidate
\nVersions: node:missing npm:missing\n

OK, I have restored and run again from scratch with no flags.

First of all, a check node -v returns v14.17.0 and npm -v returns v7.15.0

Here's the output:

Running Node-RED update for user pi at /home/pi on raspbian


This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Node option not specified           :   --node12 or --node14
  Leave existing Node.js              ✘   Bad install:  Node.js missing  Npm missing - Exit
  Clean npm cache                     
  Install Node-RED core               
  Move global nodes to local          
  Npm rebuild existing nodes          
  Install extra Pi nodes              
  Add shortcut commands               
  Update systemd script               
                                      

Any errors will be logged to   /var/log/nodered-install.log

and the log:

Already have nodejs v14.17.0
OLD nodejs 14 :
NEW nodejs  :

***************************************

Started : Mon 31 May 13:17:33 BST 2021
Running for user pi at /home/pi
Found global nodes: node-red-contrib-homebridge-automation
node-red-contrib-play-audio
node-red-node-pi-gpio
node-red-node-ping
node-red-node-random
node-red-node-serialport
node-red-node-smooth  :

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'nodered' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
\nVersions: node:missing npm:missing\n

Just checking, what sort of pi are you using and what OS are you using on it?

Its a Pi 4 with 8GB RAM running Raspbian GNU/Linux Version 10 'buster'

How did you install nodejs in the first place ? Is it using n or nvm ?

I don't remember, sorry. However, I don't use nvm so I know it would not have been using that. There's never any problem in updating node when I need to.

I don't know whether this might help, but both node and npm are installed in /usr/local/bin/

And did you try the new installer ?

Do you mean did I try the V2 install script as recommended by @Steve-Mcl?

If so, my responses since then have been in relation to that script.

If there's another one, please point me at it.

hmm - yes that one.. can you try with the --node14 flag to force it to reload nodejs.
(usually it is installed into /usr/bin)

I tried it with no flags and with that flag and I've shown the results. Perhaps the install location is the issue?

I don't understand how the script reports that it removes the old version of node [which it has - so presumably it should know where it removed it from] but then complains "Bad install: Node.js missing Npm missing - Exit" when it's trying to install Node.js 14 LTS.

Is most odd -
it reports

Hit:4 https://deb.nodesource.com/node_14.x buster InRelease

but then says

Package nodejs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  nodejs-doc

E: Package 'nodejs' has no installation candidate
\nVersions: node:missing npm:missing\n

Which makes no sense...

What happens if you run sudo apt update now - it should again find the nodesource files... and then manually sudo apt install nodejs
What does that report ?

A typo there I think. It should be sudo apt update (or the old format sudo apt-get update).

1 Like

Just had a chance to try this now. Using restored system (so the same starting point as all the other attempts):

node -v returns v14.17.0 and npm -v returns v7.15.0

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/v2/deb/update-nodejs-and-nodered) --node14

This is the output, followed by the log:

Running Node-RED update for user pi at /home/pi on raspbian


This can take 20-30 minutes on the slower Pi versions - please wait.

  Stop Node-RED                       ✔
  Remove old version of Node-RED      ✔
  Remove old version of Node.js       ✔   v14.17.0
  Install Node.js 14 LTS              ✘   Bad install:  Node.js missing  Npm missing - Exit
  Clean npm cache                     
  Install Node-RED core               
  Move global nodes to local          
  Npm rebuild existing nodes          
  Install extra Pi nodes              
  Add shortcut commands               
  Update systemd script               
                                      

Any errors will be logged to   /var/log/nodered-install.log

pi@homebridge:~ $ cat /var/log/nodered-install.log 
Already have nodejs v14.17.0
OLD nodejs 14 :
NEW nodejs 14 :

***************************************

Started : Tue 1 Jun 09:55:24 BST 2021
Running for user pi at /home/pi
Found global nodes: node-red-contrib-homebridge-automation
node-red-contrib-play-audio
node-red-node-pi-gpio
node-red-node-ping
node-red-node-random
node-red-node-serialport
node-red-node-smooth  :

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'nodered' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Installing nodejs 14

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package 'nodejs-legacy' is not installed, so not removed
Package 'nodejs' is not installed, so not removed
Package 'npm' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
dpkg: warning: ignoring request to remove nodejs which isn't installed
dpkg: warning: ignoring request to remove node which isn't installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Grab the LTS bundle

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
curl is already the newest version (7.64.0-4+deb10u2).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

## Installing the NodeSource Node.js 14.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Hit:2 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:3 http://phoscon.de/apt/deconz buster InRelease
Hit:4 https://repo.mosquitto.org/debian buster InRelease
Reading package lists...

## Confirming "buster" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_14.x/dists/buster/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
gpg: WARNING: unsafe ownership on homedir '/home/pi/.gnupg'

## Creating apt sources list file for the NodeSource Node.js 14.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x buster main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x buster main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://phoscon.de/apt/deconz buster InRelease
Hit:3 http://archive.raspberrypi.org/debian buster InRelease
Hit:4 https://repo.mosquitto.org/debian buster InRelease
Get:5 https://deb.nodesource.com/node_14.x buster InRelease [4,584 B]
Get:6 https://deb.nodesource.com/node_14.x buster/main armhf Packages [774 B]
Fetched 5,358 B in 3s (2,112 B/s)
Reading package lists...

## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn



WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Package nodejs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  nodejs-doc

E: Package 'nodejs' has no installation candidate
\nVersions: node:missing npm:missing\n

Then I did: sudo apt update, which returned:

Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease                                                                       
Hit:3 http://phoscon.de/apt/deconz buster InRelease                                                                                
Hit:4 https://repo.mosquitto.org/debian buster InRelease                                                                    
Hit:5 https://deb.nodesource.com/node_14.x buster InRelease                                           
Reading package lists... Done                      
Building dependency tree       
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.

Then: sudo apt install nodejs, which got:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package nodejs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  nodejs-doc

E: Package 'nodejs' has no installation candidate

What do you have inside /etc/apt/sources.list?

For reference, I have

deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

Also, cant help but feel you have other issues for example ↑ this.

Searching the net there are a few comments, one in particular...

You probably migrated your .gnupg folder from another machine, or tampered another way with the file permissions.

GnuPG enforces private ownership of the folder and some files for security reasons.

These two lines fix the permissions. The first one ensures that the ~/.gnupg folder (and everything in it) is actually yours. To possibly overtake ownership, it requires root privileges, thus the sudo . The second line makes sure nobody but you can read its contents (remove read, write and execute permissions for group and other users). Your username gets inserted automatically, so you can copy-past the lines directly to your terminal:

sudo chown -R ${USER}:${USER} ~/.gnupg
chmod -R go-rwx ~/.gnupg

REF: "Unsafe permissions on configuration file `/home/david/.gnupg/gpg.conf" What does it mean and how to fix? - Ask Ubuntu

and ...

This is the result of running gpg with sudo : gpg then runs as root, but its home directory is still the user’s. This explains both the warning ( gpg is running as root but another user owns the configuration directory) and dirmngr ’s socket’s ownership.

To fix this up, you should stop dirmngr :

sudo gpgconf --kill dirmngr

( sudo just this once because dirmngr is running as root, as evidenced by its socket), then restore your ownership:

sudo chown -R $USER ~/.gnupg

REF: permissions - gpg: WARNING: unsafe ownership on homedir '/home/user/.gnupg' - Unix & Linux Stack Exchange

$ cat sources.list
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

Thanks. I think at this stage that I am going to blow away the problematic system and start with a new one. I just tested the script on another pi and it worked with no issues reported.

I don't want to drag the work off course with a rogue, so thanks to all who responded.