我正在尝试在 Ubuntu 上安装 npm。首先我检查 NPM 是否安装:
jmlopez@desarrollo:/usr/share$ npm -v
Command 'npm' not found, but can be installed with:
sudo apt install npm
然后我尝试安装它,但我得到:
jmlopez@desarrollo:/usr/share$ sudo apt install npm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
npm is already the newest version (8.5.1~ds-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libnode-dev : Depends: libssl-dev but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
我也尝试卸载nodejs,但它抛出了这个:
jmlopez@desarrollo:/usr/share$ sudo apt remove nodejs
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:
libnode-dev : Depends: libssl-dev but it is not going to be installed
node-abab : Depends: nodejs but it is not going to be installed
node-aproba : Depends: nodejs but it is not going to be installed
node-archy : Depends: nodejs but it is not going to be installed
node-argparse : Depends: nodejs but it is not going to be installed
node-cacache : Depends: nodejs but it is not going to be installed
node-chalk : Depends: nodejs but it is not going to be installed
node-clone : Depends: nodejs but it is not going to be installed
node-colors : Depends: nodejs but it is not going to be installed
node-combined-stream : Depends: nodejs but it is not going to be installed
node-console-control-strings : Depends: nodejs but it is not going to be installed
node-coveralls : Depends: nodejs:any
node-cssom : Depends: nodejs but it is not going to be installed
node-debug : Depends: nodejs but it is not going to be installed
node-esprima : Depends: nodejs:any
node-events : Depends: nodejs but it is not going to be installed
node-graceful-fs : Depends: nodejs but it is not going to be installed
node-gyp : Depends: nodejs:any
node-js-yaml : Depends: nodejs:any
node-json-buffer : Depends: nodejs but it is not going to be installed
node-lcov-parse : Depends: nodejs but it is not going to be installed
node-log-driver : Depends: nodejs (>= 10) but it is not going to be installed
node-mime : Depends: nodejs:any
node-mkdirp : Depends: nodejs:any
node-ms : Depends: nodejs but it is not going to be installed
node-nopt : Depends: nodejs:any
node-normalize-package-data : Depends: nodejs but it is not going to be installed
node-object-assign : Depends: nodejs but it is not going to be installed
node-opener : Depends: nodejs:any
node-psl : Depends: nodejs but it is not going to be installed
node-punycode : Depends: nodejs but it is not going to be installed
node-read-package-json : Depends: nodejs but it is not going to be installed
node-rimraf : Depends: nodejs but it is not going to be installed
node-semver : Depends: nodejs (>= 10) but it is not going to be installed
node-source-map-support : Depends: nodejs but it is not going to be installed
node-ssri : Depends: nodejs but it is not going to be installed
node-stack-utils : Depends: nodejs but it is not going to be installed
node-strip-ansi : Depends: nodejs but it is not going to be installed
node-tap : Depends: nodejs but it is not going to be installed
node-tap-mocha-reporter : Depends: nodejs:any
node-tap-parser : Depends: nodejs:any
node-unique-filename : Depends: nodejs but it is not going to be installed
node-which : Depends: nodejs:any
node-write-file-atomic : Depends: nodejs but it is not going to be installed
node-ws : Depends: nodejs:any
npm : Depends: nodejs:any (>= 10)
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
安装的nodejs版本是:
jmlopez@desarrollo:/usr/share$ nodejs -v
v12.22.9
这些问题有关联吗?有什么想法可以解决它们吗?
提前非常感谢您!!
要在 Ubuntu 上安装 Node Package Manager,请尝试以下说明。
sudo apt update
sudo apt install nodejs
node --version
如果显示Node版本说明安装成功
要验证 npm 版本,请执行以下命令:
npm --version
这里的替代方案:
# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.12.2`
# verifies the right NPM version is in the environment
npm -v # should print `10.5.0`
了解更多:这里