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


当前回答

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

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。

其他回答

现在你可以简单地安装:

sudo apt-get install nodejs
sudo apt-get install npm

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

sudo apt-get install python g++ make

Node.js包在LTS版本和当前版本中可用。您可以根据自己的需求选择在系统上安装哪个版本。

使用当前版本:在本教程的最后一次更新中,Node.js 13是当前可用的Node.js版本。

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -

使用LTS发布:在本教程的最后一次更新中,Node.js 12。x为可用的LTS版本。

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

可以成功将Node.js PPA添加到Ubuntu系统。现在执行下面的命令,使用apt-get在Ubuntu上安装Node.js。这也将与Node.js一起安装NPM。该命令还在系统上安装许多其他依赖包。

sudo apt-get install nodejs

Node.js安装完成后,需要验证和检查已安装的版本。您可以在Node.js官方网站上找到更多关于当前版本的详细信息。

node -v

v13.0.1

另外,检查npm版本:

npm -v

6.12.0

获取最新的Node.js

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -

sudo apt-get install nodejs
node -v
npm -v

如果你正在寻找一个简单,快速(没有构建过程),本地(没有sudo)安装ubuntu,请查看:

install-node-on-linux

声明:我是作者。

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

只要按照这里的官方说明来安装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