我试图在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包在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
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的最佳方式。这也适用于Ubuntu 12.04 (Precise穿山甲),Ubuntu 13.04 (Raring Ringtail)和Ubuntu 14.04 (Trusty Tahr)。
添加Node.js存储库
[sudo] apt-get install python-software-properties
[sudo] apt-add-repository ppa:chris-lea/node.js
[sudo] apt-get update
node . js安装
[sudo] apt-get install nodejs
现在检查Node.js版本
node -v
输出
v0.10.20
这个命令应该安装npm
npm install
检查npm版本
npm -v
输出
1.4.3
如果出于某种原因,如果你看到npm没有安装,你可以尝试运行:
[sudo] apt-get install npm
要更新npm,您可以尝试运行:
[sudo] npm install -g npm
在Ubuntu 12.10 (Quantal Quetzal)或Ubuntu 14.04 LTS (Trusty Tahr)或Ubuntu 16.04.1 LTS (Xenial Xerus)上安装Node.js。
请避免在Ubuntu上使用apt-get安装Node.js。如果你已经安装了带有内置包管理器的Node.js,请删除它。(sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean)
Linux操作系统的安装过程与OS X操作系统相同。
使用提供的脚本:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash
$ nvm list
$ nvm ls-remote
$ nvm install 6.4.0
$ nvm use 6.4.0
$ nvm alias default 6.4.0
$ node -v
$ npm install -g npm
$ npm -v
安装Node JS时的其他问题
不要使用sudo apt-get install nodejs npm。始终使用sudo apt-get install nodejs
如果你得到错误sudo: add-apt-repository:命令没有找到,只需在上面的第二个命令之前运行这个命令:sudo apt-get install software-properties-common
如果未找到sudo: add-apt-repository:命令,需要在添加存储库前执行sudo apt-get install python-software-properties命令
如果你之前使用的是旧版本,或者控制台中没有node / NPM,请尝试使用bash -r
链接说明已更新为curl - sl https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs
编辑更新
对于最新版本,您也可以使用URL
nodejs.org/dist/node-latest.tar.gz
还有一件事!不要忘记运行以下命令,该命令将增加inotify监视的数量。
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p