在 Ubuntu 上安装 Node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16302436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:22:34  来源:igfitidea点击:

Install Node.js on Ubuntu

node.jsubuntunpm

提问by David Aguilar

I'm trying install Node.js on Ubuntu 12.10, but the terminal shows me an error about lost packages. I tried with this:

我正在尝试在 Ubuntu 12.10 上安装 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

But when I came to the last line sudo apt-get install nodejs npmshows this error:

但是当我来到最后一行时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.

Then I uninstalled the ppa:chris-lea/node.jsand I was trying a second option:

然后我卸载了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

The same error, the terminal says npm is the latest versionbut also shows me the text I shown in the top. I think the problem is ppa:chris-lea/node.jsbut I don't know how solve it.

终端说同样的错误,npm is the latest version但也显示了我在顶部显示的文本。我认为问题是,ppa:chris-lea/node.js但我不知道如何解决它。

回答by user568109

Simply follow the instructions given here:

只需按照此处给出的说明进行操作:

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-repositorycommand 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 python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

它在当前稳定的 Ubuntu 上安装当前稳定的 Node。Quantal (12.10) 用户可能需要安装 software-properties-common 包才能运行add-apt-repository命令:sudo apt-get install software-properties-common

从 Node.js v0.10.0 开始,Chris Lea 的 repo 中的 nodejs 包包括 npm 和 nodejs-dev。

Don't give sudo apt-get install nodejs npmjust sudo apt-get install nodejs

不要sudo apt-get install nodejs npm只给sudo apt-get install nodejs

回答by nixkuroi

As of today, you can simply install it with:

截至今天,您可以简单地安装它:

sudo apt-get install nodejs

回答by Noah

npm is automatically installed with node.js in the latest version of node. What do you see when you type node --versionand npm --versionin the terminal?

在最新版本的 node 中,npm 会自动与 node.js 一起安装。当您在终端中输入node --version和输入时,您会看到什么npm --version

You can upgrade npm using npm itself as well

您也可以使用 npm 本身升级 npm

[sudo] npm install -g npm

回答by ynkr

My apt-getwas old and busted, so I had to install from source. Here is what worked for me:

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

These steps were mostly taken from joyent's installation wiki

这些步骤大多取自joyent的安装wiki

回答by user1524615

This is the best way to easy install NODE.JS. This also is actual for Ubuntu 12.04, 13.04 and 14.04

这是轻松安装 NODE.JS 的最佳方式。这也适用于 Ubuntu 12.04、13.04 和 14.04

Adding node js repositories

添加节点js存储库

[sudo] apt-get install python-software-properties
[sudo] apt-add-repository ppa:chris-lea/node.js
[sudo] apt-get update

node.js installation

node.js 安装

[sudo] apt-get install nodejs

Now checking node.js version

现在检查 node.js 版本

node -v

Outputs

输出

v0.10.20

This command should install npm.

这个命令应该安装 npm。

npm install

Check npm version

检查 npm 版本

npm -v

Outputs

输出

1.4.3

If for some reason, if you see npm is not installed, you may try running:

如果由于某种原因,如果您看到未安装 npm,您可以尝试运行:

[sudo] apt-get install npm

To update npm you may try running:

要更新 npm,您可以尝试运行:

[sudo] npm install -g npm

回答by feit

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.19.0/install.sh | bash    

nvm install v0.10.33

just use nvm for node version control nvm

只需使用 nvm 进行节点版本控制nvm

回答by demonodojo

You can use nvmto install nodejs. It allows you work with different versions without conflicts.

您可以使用nvm安装 nodejs。它允许您使用不同的版本而不会发生冲突。

回答by Sajjad Ashraf

You can also compile it from source like this

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

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

Find detailed instructions here http://howtonode.org/how-to-install-nodejs

在此处查找详细说明 http://howtonode.org/how-to-install-nodejs

回答by Sadi

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/

http://jstricks.com/install-node-js/

回答by Venkat Kotra

Follow the instructions given hereat NodeSource which is dedicated to creating a sustainable ecosystem for Node.js

按照指示在这里这是专门为创建Node.js的一个可持续生态系统在NodeSource

For Node.js >= 4.X

对于 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