升级 Nodejs 时出错

升级 Nodejs 时出错
└─# apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nodejs : Depends: libnode72 (= 12.21.0~dfsg-5) but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

运行时apt --fix-broken install

└─# apt --fix-broken install                                              100 ⨯
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libfuse3-3 libjs-highlight.js nodejs-doc
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  nodejs
The following packages will be upgraded:
  nodejs
1 upgraded, 0 newly installed, 0 to remove and 1133 not upgraded.
Need to get 0 B/26.2 MB of archives.
After this operation, 122 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 413977 files and directories currently installed.)
Preparing to unpack .../nodejs_16.9.0-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (16.9.0-deb-1nodesource1) over (12.21.0~dfsg-5) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_16.9.0-deb-1nodeso
urce1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/doc/nodejs/api/process.html', which is also in 
package nodejs-doc 12.21.0~dfsg-5
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
                                                    

我应该怎么办?

答案1

这种情况很少发生,但你可能需要拿出更强大的武器来应对这种情况:

  1. 打开终端(如果尚未打开)
  2. 强制覆盖 Node 包:
    sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb
    
  3. 修复其余损坏的安装:
    sudo apt -f install
    
  4. 确保系统的其余部分均已正确更新:
    sudo apt update
    sudo apt dist-upgrade
    

尽量不要让事情变得太疯狂以至于看到如下消息:

1 upgraded, 0 newly installed, 0 to remove and 1133 not upgraded.

相关内容