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


当前回答

遵循NodeSource给出的说明,它致力于为Node.js创建一个可持续的生态系统。

对于Node.js >= 4。X

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_4.x | bash -
apt-get install -y nodejs

其他回答

很简单:

sudo apt install nodejs

然后输入:

nodejs

使用它。

我已经阅读了上面的答案,我尝试了,工作得很好,但有时你会在使用这些答案时遇到小问题。如果你从Ubuntu商店安装nodejs,我试过了,vallah,任务完成了。

首先,你必须卸载你已经安装的旧垃圾

sudo apt-get remove nodejs

我也试图通过apt安装节点,但失败了,或者给我版本10.x。X已经过时了。然后我随机地去ubuntu商店安装了最新的版本,检查它的节点——版本

到今天为止,你可以简单地安装它:

sudo apt-get install nodejs

您也可以像这样从源代码编译它

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

在这里找到详细说明 http://howtonode.org/how-to-install-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/