我试图在Ubuntu 12.10 (Quantal Quetzal)上安装Node.js,但终端显示关于丢失包的错误。我试过这样做:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
但是当我来到最后一行sudo apt-get install nodejs npm显示这个错误:
Failed to install some packages. This may mean that
you requested an impossible situation or if you are using the distribution
distribution that some required packages have not yet been created or been
been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nodejs: Conflicts: npm
E: Failed to correct problems, you have held broken packages.
然后我卸载了ppa:chris-lea/node.js,我正在尝试第二种选择:
sudo apt-get install node.js
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
同样的错误,终端说npm是最新版本,但它也显示了我在顶部显示的文本。我认为问题是ppa:chris-lea/node.js,但我不知道如何解决它。
Node.js在目前支持的所有Ubuntu版本中都是一个snap包。对于Node.js,开发人员可以从一个或多个当前支持的版本中选择,并直接从NodeSource获得定期的自动更新。Node.js版本6、8、9、10、11、13、14、15、16、17和18目前可用,Snap Store会在Node.js发布后的几小时或几分钟内更新。
Node.js可以用一个命令来安装,例如:
sudo snap install node --classic --channel 11/stable
节点快照可以被命令节点访问,例如:
$ node -v
v11.5.0
最新版本的npm将作为节点快照的一部分安装。NPM应该在节点repl之外运行,在正常的shell中。安装节点snap后,运行以下命令启用npm更新检查:
sudo chown -R $USER:$(id -gn $USER) /home/<b>your-username</b>/.config
将上述命令中的your-username替换为您自己的用户名。然后执行npm -v检查npm版本是否为最新。作为一个例子,我检查了npm是最新的,用npm list yarn命令检查了一个已经安装的名为yarn的包的版本,然后用npm update yarn命令将现有的yarn包更新到最新版本
用户可以随时在Node.js的版本之间切换,而不需要涉及额外的工具,如nvm(节点版本管理器),例如:
sudo snap refresh node --channel=11/stable
用户可以通过切换来测试可以从最新边缘通道安装的Node.js的前沿版本:
sudo snap switch node --edge
这种方法只推荐给那些愿意参与上游测试和错误报告的用户。
Node.js LTS调度
Release |
Status |
Codename |
Initial release |
LTS Start |
Maintenance Start |
Maintenance End |
6.x |
EOL |
Boron |
2016-04-26 |
2016-10-18 |
2018-04-30 |
2019-04-30 |
7.x |
EOL |
|
2017-05-30 |
|
|
2017-06-30 |
8.x |
EOL |
Carbon |
2016-10-25 |
2017-10-31 |
2019-01-01 |
2019-12-31 |
9.x |
EOL |
|
2017-10-01 |
|
|
2018-06-30 |
10.x |
EOL |
Dubnium |
2018-04-24 |
2018-10-30 |
2020-05-19 |
2021-04-30 |
11.x |
EOL |
|
2018-10-23 |
|
|
2019-06-01 |
12.x |
Maintenance LTS |
Erbium |
2019-04-23 |
2019-10-21 |
2020-11-301 |
2022-04-30 |
13.x |
EOL |
|
2019-10-22 |
|
|
2020-06-01 |
14.x |
Maintenance LTS |
Fermium |
2020-04-21 |
2020-10-27 |
2021-10-30 |
2023-04-30 |
16.x |
Active LTS |
Gallium |
2021-04-20 |
2021-10-26 |
2022-10-18 |
2024-04-30 |
17.x |
Current |
|
2021-10-19 |
|
2022-04-01 |
2022-06-01 |
18.x |
Current |
|
2022-04-19 |
2022-10-25 |
2023-10-18 |
2025-04-30 |
Node.js包在LTS版本和当前版本中可用。您可以根据自己的需求选择在系统上安装哪个版本。
使用当前版本:在本教程的最后一次更新中,Node.js 13是当前可用的Node.js版本。
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
使用LTS发布:在本教程的最后一次更新中,Node.js 12。x为可用的LTS版本。
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
可以成功将Node.js PPA添加到Ubuntu系统。现在执行下面的命令,使用apt-get在Ubuntu上安装Node.js。这也将与Node.js一起安装NPM。该命令还在系统上安装许多其他依赖包。
sudo apt-get install nodejs
Node.js安装完成后,需要验证和检查已安装的版本。您可以在Node.js官方网站上找到更多关于当前版本的详细信息。
node -v
v13.0.1
另外,检查npm版本:
npm -v
6.12.0