![我在新安装的 Ubuntu 上安装 NodeJS 时遇到了一些我无法理解的错误,而 Ubuntu 上一片空白](https://linux22.com/image/1027003/%E6%88%91%E5%9C%A8%E6%96%B0%E5%AE%89%E8%A3%85%E7%9A%84%20Ubuntu%20%E4%B8%8A%E5%AE%89%E8%A3%85%20NodeJS%20%E6%97%B6%E9%81%87%E5%88%B0%E4%BA%86%E4%B8%80%E4%BA%9B%E6%88%91%E6%97%A0%E6%B3%95%E7%90%86%E8%A7%A3%E7%9A%84%E9%94%99%E8%AF%AF%EF%BC%8C%E8%80%8C%20Ubuntu%20%E4%B8%8A%E4%B8%80%E7%89%87%E7%A9%BA%E7%99%BD.png)
几天前我刚刚安装了 Ubuntu 22.04。我的笔记本电脑几乎一片空白。因此,当我尝试使用以下命令安装 Nodejs 时,我遇到了困惑这些 DigitalOcean 说明然后我收到一个错误。
我愿意:
sudo apt update
sudo apt install nodejs
第二条命令给出
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
javascript-common libc-ares2 libjs-highlight.js libnode72
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 0 B/26.4 MB of archives.
After this operation, 124 MB of additional disk space will be used.
(Reading database ... 197872 files and directories currently installed.)
Preparing to unpack .../nodejs_16.15.1-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (16.15.1-deb-1nodesource1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_16.15.1-deb-1nodes
ource1_amd64.deb (--unpack):
trying to overwrite '/usr/share/systemtap/tapset/node.stp', which is also in pa
ckage libnode72:amd64 12.22.9~dfsg-1ubuntu3
Errors were encountered while processing:
/var/cache/apt/archives/nodejs_16.15.1-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
我是 Ubuntu 新手,所以我看不懂这个消息,或者至少我不知道什么是有用的等等。
我使用 Google 发现了类似的错误消息这里我跟着页面上的此说明。
// Delete the new package source.
cd /etc/apt/sources.list.d
sudo rm nodesource.list
// Update apt, fix the install, remove nodeJS and the nodejs-doc packages.
sudo apt --fix-broken install
sudo apt update
sudo apt remove nodejs
sudo apt remove nodejs-doc
// then use the instructions to install the latest node
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
但这给了我相同或类似的错误
sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
javascript-common libc-ares2 libjs-highlight.js libnode72
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 0 B/26.4 MB of archives.
After this operation, 124 MB of additional disk space will be used.
(Reading database ... 197872 files and directories currently installed.)
Preparing to unpack .../nodejs_16.15.1-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (16.15.1-deb-1nodesource1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_16.15.1-deb-1nodesource1_amd64.deb (--unpack):
trying to overwrite '/usr/share/systemtap/tapset/node.stp', which is also in package libnode72:amd64 12.22.9~dfsg-1ubuntu3
Errors were encountered while processing:
/var/cache/apt/archives/nodejs_16.15.1-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
有什么建议吗?请帮忙,谢谢
答案1
从您尝试安装的 nodejs 版本(16.15)来看,您没有从 Ubuntu 22.04 发行版安装 nodejs,其中 12.22 是当前的。
除非您有特殊原因要安装非发行版,否则您可以删除添加的文件/etc/apt/sources.list.d/
以获取 16.15 版本,然后运行apt update && apt install nodejs
安装 12.22。
如果您坚持使用发行版以外的较新版本,请先使用apt autoremove
(如apt
建议)删除 Ubuntu 默认版本的残余,然后尝试再次安装。
答案2
sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_16.15.1-deb-1nodesource1_amd64.deb