Updating NodeJS version on Ubuntu 22.04
Asked Answered
H

3

10

I'm trying to upgrade my NodeJS 12.22.09 to version 16 or newer, but when I enter the command sudo apt update && sudo apt upgrade it returns this error below:

Preparing to unpack …/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb …
Unpacking nodejs (16.16.0-deb-1nodesource1) over (12.22.9~dfsg-1ubuntu3) …
dpkg: error processing archive /tmp/apt-dpkg-install-hIlTWe/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb (—unpack):
 trying to overwrite ‘/usr/include/node/common.gypi’, which is also in package libnode-dev 12.22.9~dfsg-1ubuntu3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack …/13-snapd_2.56.2+22.04ubuntu1_amd64.deb …
Unpacking snapd (2.56.2+22.04ubuntu1) over (2.55.5+22.04) …
Errors were encountered while processing:
 /tmp/apt-dpkg-install-hIlTWe/12-nodejs_16.16.0-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

How to solve this problem?

Happily answered 10/8, 2022 at 12:41 Comment(0)
M
29

There is a npm package called "n" that handles node version management. Additionally, it supports convenient version naming, such as "current, "lts" or "18.12.1".

So, in your shell, type these commands:

sudo npm install -g n
sudo n lts
Milky answered 27/10, 2022 at 7:1 Comment(1)
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.Zerline
E
2

sudo npm install -g --force node@latest

Use that command, and it will fix your problem. The only issue with that is it will rewrite your node folder.

Encroach answered 18/6, 2023 at 0:37 Comment(0)
B
0

Try this command your problem will surely be fixed:-

sudo npm install npm -g

and test it here with version recheck the version:-

npm --version
Boyceboycey answered 23/6 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.