在 Ubuntu 上升级 Nodejs:如何修复损坏的管道错误?

在 Ubuntu 上升级 Nodejs:如何修复损坏的管道错误?

尝试在 ubuntu 20.10 上升级 nodejs。

跑官方安装说明:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

出现以下错误:

The following packages will be upgraded:
  nodejs
1 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
1 not fully installed or removed.
Need to get 0 B/24.5 MB of archives.
After this operation, 119 MB of additional disk space will be used.
(Reading database ... 277425 files and directories currently installed.)
Preparing to unpack .../nodejs_14.15.4-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (14.15.4-deb-1nodesource1) over (12.18.2~dfsg-1ubuntu2) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/doc/nodejs/api/dgram.json.gz', which is also in package nodejs-doc 12.18.2~dfsg-1ubuntu2
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我查看了其他 StackOverflow 答案,建议我尝试卸载 nodejs-doc (冲突的依赖项)或运行以下命令:

sudo dpkg -i --force-overwrite /usr/share/doc/nodejs/api/dgram.json.gz

似乎两者都不起作用。在上述命令的情况下,它表示该文件需要是 deb 包 - 无论如何,我对该策略有点怀疑,因为它可能会破坏我的设置。

为了尝试删除 nodejs-doc,我得到以下输出:

You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nodejs : Depends: libnode72 (= 12.18.2~dfsg-1ubuntu2) but it is not going to be installed
          Recommends: nodejs-doc but it is not going to be installed

我也尝试过运行推荐的apt --fix-broken install但它似乎没有帮助。

答案1

所有这一切对我来说都不起作用。

有效的是:

sudo dpkg --remove --force-remove-reinstreq libnode-dev
sudo dpkg --remove --force-remove-reinstreq libnode72:amd64

通过

答案2

您需要启用universe提供缺少依赖项的存储库 libnode72 (= 12.18.2~dfsg-1ubuntu2)nodejs-doc (12.18.2~dfsg-1ubuntu2)在 Ubuntu 20.10 中:

sudo add-apt-repository universe
sudo apt install libnode72 nodejs-doc

dpkg -i --force-overwrite应该指向.deb文件:

sudo dpkg -i --force-overwrite  /var/cache/apt/archives/nodejs_14.15.4-deb-1nodesource1_amd64.deb

答案3

只需删除nodejs-doc:

sudo apt remove nodejs-doc

答案4

运行这些命令:

sudo apt remove nodejs  
sudo apt remove nodejs-doc
sudo dpkg --remove --force-remove-reinstreq libnode-dev
sudo dpkg --remove --force-remove-reinstreq libnode72:amd64
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt-get install -y nodejs

相关内容