How do I update node.js to latest version?

I used this script to update one of my RPi-4B running NR version 2 on Buster.

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

Although I added --node16 it still left me with node.js v12.22.12

Any suggestions on how to achive getting node.js to a more recent version?
Is there a better or more recent update script I should be using?

It has upgraded NR to 3.0.2 but there are issues with the 'serial' nodes.

Run npm rebuild command to fix errors about serial port

I've resolved the issue with the serialport node.

I still can't get the latest version of node.js to install.
As you see from the first screenshot it says "Install 16 LTS" but leaves it at v12.22.12
Is there a way I can perform this from the command line?
I'm running Buster on a RPi-4B.

It sounds as if you may have two versions installed. Have you used nvm at some point?

What do these commands give?

node   -v
which node

Edit: and
apt policy nodejs

Finally (?) Run
sudo apt upgrade && sudo apt full-upgrade
And try the script again

Colin, thanks for your response. Hope this makes sense to you?

pi@fun-super-server:~ $ node -v
v12.22.12
pi@fun-super-server:~ $ which node
/usr/bin/node
pi@fun-super-server:~ $ apt policy nodejs
nodejs:
  Installed: 12.22.12-deb-1nodesource1
  Candidate: 12.22.12-deb-1nodesource1
  Version table:
 *** 12.22.12-deb-1nodesource1 500
        500 https://deb.nodesource.com/node_12.x buster/main armhf Packages
        100 /var/lib/dpkg/status
     10.24.0~dfsg-1~deb10u3 500
        500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
pi@fun-super-server:~ $ sudo apt upgrade && sudo apt full-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  influxdb
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/50.7 MB of archives.
After this operation, 118 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 30, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
(Reading database ... 111347 files and directories currently installed.)
Preparing to unpack .../influxdb_1.8.10-1_armhf.deb ...
Unpacking influxdb (1.8.10-1) over (1.6.4-1+deb10u1) ...
dpkg: error processing archive /var/cache/apt/archives/influxdb_1.8.10-1_armhf.d         eb (--unpack):
 trying to overwrite '/usr/bin/influx', which is also in package influxdb-client          1.6.4-1+deb10u1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/influxdb_1.8.10-1_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

As you can see there is a problem with your system, not node red related. I am away at the moment so can't investigate. If you fix that problem then the script should work.

1 Like

Thanks - I'll investigate that route.

Dave, you also did not state whether you have a node manager installed like n or nvm - the presence of these can cause similar issues to what you are seeing. Tho TBF, the apt problem is likely you cause.

To check for a node manager:

volta -v
nvm -v
n -v

I would expect to see...

user@computer:~$ volta -v
volta: command not found
user@computer:~$ n -v
n: command not found
user@computer:~$ nvm -v
Command 'nvm' not found, but there are 13 similar ones.

These are the results, which I think matches yours.

pi@fun-super-server:~ $ volta -v
-bash: volta: command not found

pi@fun-super-server:~ $ nvm -v
-bash: nvm: command not found

pi@fun-super-server:~ $ n -v
-bash: n: command not found
1 Like

I removed Influxdb which seemed to be giving grief and then tried this to add a repro...
$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Installing the NodeSource Node.js 18.x repo...

Populating apt-get cache...

Confirming "" is supported...

Your distribution, identified as "", is not currently supported, please contact NodeSource at Issues · nodesource/distributions · GitHub if you think this is incorrect or would like your distribution to be considered for support

Before adding the nodesource repo did you try running
sudo apt update && sudo apt full-upgrade
to make sure that worked. I suspect the influx issue was not the main problem.

It gives this result, saying no module named apt_pkg..



pi@fun-super-server:~ $ sudo apt update && sudo apt full-upgrade
Hit:1 http://download.zerotier.com/debian/buster buster InRelease
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Hit:3 http://archive.raspberrypi.org/debian buster InRelease
Get:4 https://packages.sury.org/php buster InRelease [7,559 B]
Get:5 https://repos.influxdata.com/debian stable InRelease [6,892 B]
Hit:6 https://deb.nodesource.com/node_12.x buster InRelease
Get:7 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages [13.0           MB]
Get:8 https://packages.sury.org/php buster/main armhf Packages [237 kB]
Get:9 https://repos.influxdata.com/debian stable/main armhf Packages [2,765 B]
Fetched 13.3 MB in 6s (2,104 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
9 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  avahi-daemon libavahi-client3 libavahi-common-data libavahi-common3
  libavahi-core7 libavahi-glib1 libfastjson4 libpcre3 libxpm4
9 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 846 kB of archives.
After this operation, 1,024 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://packages.sury.org/php buster/main armhf libpcre3 armhf 2:8.45-1+0~          20230620.10+debian10~1.gbp8792c4 [323 kB]
Get:2 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf libavahi-common-data armhf 0.7-4+deb10u3 [122 kB]
Get:3 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf libavahi-common3 armhf 0.7-4+deb10u3 [51.3 kB]
Get:4 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf libavahi-core7 armhf 0.7-4+deb10u3 [102 kB]
Get:5 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf avahi-daemon armhf 0.7-4+deb10u3 [85.3 kB]
Get:6 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf libavahi-client3 armhf 0.7-4+deb10u3 [54.3 kB]
Get:7 http://www.mirrorservice.org/sites/archive.raspbian.org/raspbian buster/ma          in armhf libavahi-glib1 armhf 0.7-4+deb10u3 [40.0 kB]
Get:8 http://mirror.mythic-beasts.com/raspbian/raspbian buster/main armhf libfas          tjson4 armhf 0.99.8-2+deb10u1 [24.2 kB]
Get:9 http://mirror.mythic-beasts.com/raspbian/raspbian buster/main armhf libxpm          4 armhf 1:3.5.12-1+deb10u1 [44.0 kB]
Fetched 846 kB in 1s (678 kB/s)
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 30, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
(Reading database ... 111325 files and directories currently installed.)
Preparing to unpack .../libpcre3_2%3a8.45-1+0~20230620.10+debian10~1.gbp8792c4_a          rmhf.deb ...
Unpacking libpcre3:armhf (2:8.45-1+0~20230620.10+debian10~1.gbp8792c4) over (2:8          .44-2+0~20210301.9+debian10~1.gbpa278ad) ...
Setting up libpcre3:armhf (2:8.45-1+0~20230620.10+debian10~1.gbp8792c4) ...
(Reading database ... 111325 files and directories currently installed.)
Preparing to unpack .../0-libavahi-common-data_0.7-4+deb10u3_armhf.deb ...
Unpacking libavahi-common-data:armhf (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../1-libavahi-common3_0.7-4+deb10u3_armhf.deb ...
Unpacking libavahi-common3:armhf (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../2-libavahi-core7_0.7-4+deb10u3_armhf.deb ...
Unpacking libavahi-core7:armhf (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../3-avahi-daemon_0.7-4+deb10u3_armhf.deb ...
Unpacking avahi-daemon (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../4-libavahi-client3_0.7-4+deb10u3_armhf.deb ...
Unpacking libavahi-client3:armhf (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../5-libavahi-glib1_0.7-4+deb10u3_armhf.deb ...
Unpacking libavahi-glib1:armhf (0.7-4+deb10u3) over (0.7-4+deb10u1) ...
Preparing to unpack .../6-libfastjson4_0.99.8-2+deb10u1_armhf.deb ...
Unpacking libfastjson4:armhf (0.99.8-2+deb10u1) over (0.99.8-2) ...
Preparing to unpack .../7-libxpm4_1%3a3.5.12-1+deb10u1_armhf.deb ...
Unpacking libxpm4:armhf (1:3.5.12-1+deb10u1) over (1:3.5.12-1) ...
Setting up libxpm4:armhf (1:3.5.12-1+deb10u1) ...
Setting up libfastjson4:armhf (0.99.8-2+deb10u1) ...
Setting up libavahi-common-data:armhf (0.7-4+deb10u3) ...
Setting up libavahi-common3:armhf (0.7-4+deb10u3) ...
Setting up libavahi-glib1:armhf (0.7-4+deb10u3) ...
Setting up libavahi-core7:armhf (0.7-4+deb10u3) ...
Setting up libavahi-client3:armhf (0.7-4+deb10u3) ...
Setting up avahi-daemon (0.7-4+deb10u3) ...
Processing triggers for systemd (241-7~deb10u9+rpi1) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for dbus (1.12.24-0+deb10u1) ...
Processing triggers for libc-bin (2.28-10+rpt2+rpi1+deb10u2) ...

Google and a bit of guesswork suggests maybe this may help
sudo apt install python-apt

Edit: If it says it is already the latest then
sudo apt --reinstall install python-apt

Completed all those steps, then re-ran the script.
It stubborly refuses to upgrade to anything other than v12.
I have an SSD arriving on Monday, so I can back-up all the important stuff and then rebuild the Pi.

Has the error on update && full-upgrade gone? There is no point doing anything else until that is fixed.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.