在Ubuntu上安装Node.js

node.js Node.js

斯丁

2020-03-23

我正在尝试在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

但是,当我来到最后一行时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 is the latest version但也向我显示了我在顶部显示的文本。我认为是问题所在,ppa:chris-lea/node.js但我不知道如何解决。

第2915篇《在Ubuntu上安装Node.js》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

13个回答
Mandy村村 2020.03.23

Install Node.js on Ubuntu 12.10 or 14.04 LTS or 16.04.1 LTS

Please avoid to install Node.js with apt-get on Ubuntu. If you already installed Node.js with the built in package manager, please remove that. (sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean)

The installation process on Linux is the same as on OSX. With the provided script:

$ 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

One more thing! Don’t forget to run the following command, which increases the amount of inotify watches.

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Hope this help you!

西门乐 2020.03.23

请遵循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
飞云 2020.03.23

Node.js package is available in the LTS release and the current release. It’s your choice to select which version you want to install on the system as per your requirements.

Use Current Release: At the last update of this tutorial, Node.js 13 is the current Node.js release available.

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

Use LTS Release: At the last update of this tutorial, Node.js 12.x is the LTS release available.

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

You can successfully add Node.js PPA to the Ubuntu system. Now execute the below command install Node on and Ubuntu using apt-get. This will also install NPM with node.js. This command also installs many other dependent packages on your system.

sudo apt-get install nodejs

After installing node.js verify and check the installed version. You can find more details about the current version on node.js official website.

node -v 

v13.0.1

Also, check the npm version

npm -v 

6.12.0
老丝阿飞 2020.03.23

现在,您只需使用以下命令进行安装:

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

确保您已预安装python和c。如果不执行:

sudo apt-get install python g++ make
2020.03.23

我个人这样做:

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

如果要安装特定版本,而不要从nodejs站点下载所需版本,然后执行最后的树步骤。
我强烈建议不要使用发行版市场上的默认nodejs软件包,因为它可能已过时。(即,在撰写本文时,Ubuntu市场上的当前版本是v0.10.25,与最新版本(v0.12.0)相比已经过时了)。

2020.03.23

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

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

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

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

nvm install v0.10.33

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

番长GO 2020.03.23

在最新版本的node中,npm随node.js自动安装。你看到了什么,当你键入node --version并且npm --version在终端?

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

[sudo] npm install -g npm
逆天神无 2020.03.23

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

西里神奇 2020.03.23

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

蛋蛋猿 2020.03.23

从今天开始,您可以使用以下命令简单地安装它:

sudo apt-get install nodejs
老丝 2020.03.23

这是轻松安装NODE.JS的最佳方法。对于Ubuntu 12.04、13.04和14.04也是如此

添加Node JS存储库

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

node.js安装

[sudo] apt-get install nodejs

现在检查node.js版本

node -v

产出

v0.10.20

此命令应安装npm。

npm install

检查npm版本

npm -v

产出

1.4.3

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

[sudo] apt-get install npm

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

[sudo] npm install -g npm
路易Davaid梅 2020.03.23

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

安装示例:

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的仓库中的nodejs软件包包括npm和nodejs-dev。

不要sudo apt-get install nodejs npmsudo apt-get install nodejs

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android