无法在 ubuntu wsl 中安装 nodejs 21

无法在 ubuntu wsl 中安装 nodejs 21

当我尝试在 Ubuntu wsl 中安装 nodejs 21 时,出现以下错误

 curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&sudo apt-get install -y nodejs

错误

The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 71 not upgraded.
Need to get 0 B/32.5 MB of archives.
After this operation, 201 MB of additional disk space will be used.
(Reading database ... 50105 files and directories currently installed.)
Preparing to unpack .../nodejs_21.6.2-1nodesource1_amd64.deb ...
Unpacking nodejs (21.6.2-1nodesource1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_21.6.2-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.2-1nodesource1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

根据发布的错误,nodejs您尝试安装的软件包包含一个/usr/include/node/common.gypi也属于已安装软件包的文件libnode-devdpkg(Debian 的软件包数据库)nodejs由于此文件冲突而拒绝安装该软件包。

要解决此冲突,首先想到的是卸载libnode-dev( ),然后尝试再次apt-get remove libnode-dev安装( )。nodejsapt-get install nodejs

相关内容