我在新安装的 Ubuntu 上安装 NodeJS 时遇到了一些我无法理解的错误,而 Ubuntu 上一片空白

我在新安装的 Ubuntu 上安装 NodeJS 时遇到了一些我无法理解的错误,而 Ubuntu 上一片空白

几天前我刚刚安装了 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

我已经在这里分享了我安装的屏幕截图

相关内容