Search code examples
node.jsubuntupackageapt-get

Upgrade nodejs in Ubuntu 22 failed


nodejs -v
v12.22.9

I tried to upgrade

sudo apt remove nodejs
sudo apt install nodejs

I got error:

(Reading database ... 220599 files and directories currently installed.)
Preparing to unpack .../nodejs_21.6.1-1nodesource1_amd64.deb ...
Unpacking nodejs (21.6.1-1nodesource1) ...


dpkg: error processing archive /var/cache/apt/archives/nodejs_21.6.1-1nodesource1_amd64.deb (--unpack):
 trying to overwrite '/usr/include/node/common.gypi', which is also in package libnode-dev 12.22.9~dfsg-1ubuntu3.3
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_21.6.1-1nodesource1_amd64.deb

How can I resolve that so I can upgrade my nodejs?


Solution

  • You can use https://github.com/tj/n to install and manage nodejs version. You can install using curl:

    curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s lts
    

    and then you can do:

    n latest
    

    This will install the latest version. for specific version you can run:

    n <version_number>