我试图在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,但我不知道如何解决它。


当前回答

很简单:

sudo apt install nodejs

然后输入:

nodejs

使用它。

其他回答

sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

http://jstricks.com/install-node-js/

我的apt-get又旧又坏,所以我不得不从源代码安装。以下是对我有效的方法:

# Get the latest version from nodejs.org. At the time of this writing, it was 0.10.24
curl -o ~/node.tar.gz http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
cd
tar -zxvf node.tar.gz
cd node-v0.6.18
./configure && make && sudo make install

这些步骤主要来自joyent的安装wiki。

简单地按照这里给出的说明:

Example install: sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs It installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-common package for the add-apt-repository command to work: sudo apt-get install software-properties-common As of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.

不要给sudo apt-get install nodejs npm。只需sudo apt-get install nodejs。

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

我个人是这样做的:

sudo apt-get install python g++ make
wget http://nodejs.org/dist/node-latest.tar.gz
tar xvfvz node-latest.tar.gz
cd node-v0.12.0
./configure
make
sudo make install

如果你想安装特定的版本,那么从Node.js站点下载你想要的版本,并执行最后的树步骤。

我强烈建议不要使用来自发行版市场的默认Node.js包,因为它可能已经过时了(例如,在Ubuntu市场上写这篇文章的时候,当前的版本是v0.10.25,与最新的版本(v0.12.0)相比,它太过时了)。