我试图在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-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/

其他回答

可以使用nvm安装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。

我个人是这样做的:

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)相比,它太过时了)。

遵循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)安装ubuntu,请查看:

install-node-on-linux

声明:我是作者。

您只需要克隆repo并运行setup.sh,就可以安装最新的节点版本。如果你想要一个特定的版本,只需运行change-version.sh。