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?
2
Answers
You can use https://github.com/tj/n to install and manage nodejs version. You can install using curl:
and then you can do:
This will install the latest version. for specific version you can run:
Installing Node.js Using NVM (Node Version Manager)
NVM is a script-based version manager for Node.js, allowing you to install and manage multiple active Node.js versions. To install NVM, use the following commands:
After installing NVM, you can install the latest version of Node.js with:
nvm install node
Verify the installation with:
node -v