我试图在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 nodejs
sudo apt-get install npm

确保预先安装了Python和C解释器/编译器。如果没有,执行:

sudo apt-get install python g++ make

其他回答

在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

你可以用简单的命令来完成

sudo apt-get update

安装要求。文件

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

安装 Nodejs

sudo apt install nodejs

检查是否安装正确。

node --version

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

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

sudo apt-get remove nodejs

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

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

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

在这里找到详细说明 http://howtonode.org/how-to-install-nodejs

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

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。