Nodejs package cannot be installed in ubuntu

511 Views Asked by At

i am on Ubuntu 22.04 i cannot install nodejs after uninstalling previous node version and i do not know if the source or repo is conflicting.

i got node version 12 installed when i first run this command

curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

later, i wanted version node 18 so i apt-get remove node and i run this command

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

after, i run sudo apt-get install -y nodejs

and now i am getting dpkg-deb errors

After this operation, 184 MB of additional disk space will be used. Get:1 https://deb.nodesource.com/node_18.x jammy/main amd64 nodejs amd64 18.13.0-deb-1nodesource1 [28.4 MB] Fetched 28.4 MB in 44s (641 kB/s) (Reading database ... 213677 files and directories currently installed.) Preparing to unpack .../nodejs_18.13.0-deb-1nodesource1_amd64.deb ... Unpacking nodejs (18.13.0-deb-1nodesource1) ... dpkg: error processing archive /var/cache/apt/archives/nodejs_18.13.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) Errors were encountered while processing: /var/cache/apt/archives/nodejs_18.13.0-deb-1nodesource1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

1

There are 1 best solutions below

1
bottles On

got the latest node lts version working now using nvm to install the node

i follow this link to install nvm https://github.com/nvm-sh/nvm

and run

nvm install --lts   # *installs the latest lts version*

nvm use --lts       # *Use the latest lts version*

check node version to verify if node is installed

node -v