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


当前回答

我的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。

其他回答

这是轻松安装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

可以使用nvm安装Node.js。它允许您使用不同的版本而没有冲突。

很简单:

sudo apt install nodejs

然后输入:

nodejs

使用它。

只要按照这里的官方说明来安装Ubuntu

安装说明

Node.js LTS(截至2022年1月是v16.x):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Node.js Current(截至2022年1月是v17.x):

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

node . js v17.x:

curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install -y nodejs

node . js v16.x:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

node . js v14.x:

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

node . js v12.x:

curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

可选:安装构建工具

为了从npm编译和安装本地插件,你可能还需要安装构建工具:

sudo apt-get install -y build-essential

Sudo apt安装nodejs 必须安装NPM curl - sl https://deb.nodesource.com/setup_14.x | sudo - e bash - . Sudo apt-get install -y nodejs