![无法在 ubuntu wsl 中安装 nodejs 21](https://linux22.com/image/229195/%E6%97%A0%E6%B3%95%E5%9C%A8%20ubuntu%20wsl%20%E4%B8%AD%E5%AE%89%E8%A3%85%20nodejs%2021.png)
当我尝试在 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-dev
。 dpkg
(Debian 的软件包数据库)nodejs
由于此文件冲突而拒绝安装该软件包。
要解决此冲突,首先想到的是卸载libnode-dev
( ),然后尝试再次apt-get remove libnode-dev
安装( )。nodejs
apt-get install nodejs