# How do I update node.js to latest version?

**URL:** <https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280>\
**Category:** General\
**Created:** [18 June 2023 07:19 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280 "2023-06-18T07:19:23Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [18 June 2023 07:19 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/1 "2023-06-18T07:19:23Z")

</div>

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

 ![a_update](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39532aae453088f32ba4ef05aad775ad3df2386d.png)

**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.

 ![a_nr_start](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bf75ee9b860bdc752c5c2df2c75f122f8a189224.png)

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [18 June 2023 13:25 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/2 "2023-06-18T13:25:54Z")

</div>

Run `npm rebuild` command to fix errors about serial port

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 June 2023 16:37 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/3 "2023-06-19T16:37:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 June 2023 19:27 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/4 "2023-06-19T19:27:19Z")

</div>

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

What do these commands give?

```auto
node -v
which node

```

Edit: and  
`apt policy nodejs`

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

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 June 2023 06:02 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/5 "2023-06-20T06:02:20Z")

</div>

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

```auto
pi@fun-super-server:~ $ node -v
v12.22.12
pi@fun-super-server:~ $ which node
/usr/bin/node

```

```auto
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

```

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 June 2023 06:36 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/6 "2023-06-20T06:36:19Z")

</div>

> [@dynamicdave](#):
>
> ```auto
> Traceback (most recent call last):
> File "/usr/bin/apt-listchanges", line 30, in <module>
> import apt_pkg
> ModuleNotFoundError: No module named 'apt_pkg
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 June 2023 06:39 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/7 "2023-06-20T06:39:56Z")

</div>

Thanks - I'll investigate that route.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2023 08:35 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/8 "2023-06-20T08:35:10Z")

</div>

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:

```sh
volta -v
nvm -v
n -v

```

I would expect to see...

```sh
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.

```

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 June 2023 09:43 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/9 "2023-06-20T09:43:54Z")

</div>

These are the results, which I think matches yours.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 June 2023 10:50 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/10 "2023-06-20T10:50:50Z")

</div>

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](https://deb.nodesource.com/setup_lts.x) | sudo -E bash -

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

Populating apt-get cache...

- apt-get update  
Hit:1 [Index of /raspbian](http://raspbian.raspberrypi.org/raspbian) buster InRelease  
Hit:2 [Index of /debian](http://archive.raspberrypi.org/debian) buster InRelease  
Hit:3 [Index of /debian/buster/](http://download.zerotier.com/debian/buster) buster InRelease  
Hit:4 [Public Accessible Files](https://packages.sury.org/php) buster InRelease  
Hit:5 [Index of /node\_12.x/](https://deb.nodesource.com/node_12.x) buster InRelease  
Hit:6 [InfluxData - Package Repository](https://repos.influxdata.com/debian) stable InRelease  
Reading package lists... Done  
File "/usr/bin/lsb\_release", line 64  
print("No LSB modules are available.", file=sys.stderr)  
^  
SyntaxError: invalid syntax  
File "/usr/bin/lsb\_release", line 64  
print("No LSB modules are available.", file=sys.stderr)  
^  
SyntaxError: invalid syntax

Confirming "" is supported...

- curl -sLf -o /dev/null '[https://deb.nodesource.com/node\_18.x/dists//Release](https://deb.nodesource.com/node_18.x/dists//Release)'

Your distribution, identified as "", is not currently supported, please contact NodeSource at [Issues · nodesource/distributions · GitHub](https://github.com/nodesource/distributions/issues) if you think this is incorrect or would like your distribution to be considered for support

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2023 13:37 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/11 "2023-06-22T13:37:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [22 June 2023 15:07 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/12 "2023-06-22T15:07:56Z")

</div>

It gives this result, saying no module named apt\_pkg..

```auto

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) ...

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2023 15:39 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/13 "2023-06-22T15:39:16Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [22 June 2023 16:18 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/14 "2023-06-22T16:18:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2023 17:16 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/15 "2023-06-22T17:16:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 August 2023 17:17 UTC](https://discourse.nodered.org/t/how-do-i-update-node-js-to-latest-version/79280/16 "2023-08-21T17:17:02Z")

</div>

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