在Linux系统中安装最新的Nodejs和NPM版本

在本指南中,我们将看看如何在RHEL,CentOS,Fedora,Debian,Ubuntu和Mint发行版中安装最新版本的Nodejs和NPM。

在本指南中,我们将看看如何在RHEL / CentOS的和Fedora发行版安装最新版本的NodeJSNPM的。

在Linux中安装Nodejs和NPM

在Linux中安装Nodejs和NPM

的NodeJS一个轻量级的,高效的JavaScript平台,基于Chrome的V8 JavaScript引擎构建和NPM是默认的NodeJS包管理器。 您可以使用它来构建可扩展的网络应用程序。

第1步:添加NodeSource Repository

的Node.jsNPM的最新版本可从官方NodeSource企业版Linux,Fedora ,DebianUbuntu的二进制分发库,这是由网站的NodeJS维护和你需要将它添加到您的系统能够安装最新的和的NodeJS NPM包。

重要提示 :在RHEL 5CentOS 5,Node.js的包取决于EPEL软件库 ,因此该脚本将检查并下达指令,如果柜面它没有安装。

要添加存储库Node.js的V4 LTS氩的最新版本,请使用以下命令根..

在RHEL,CentOS和Fedora上

# curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
示例输出
## Installing the NodeSource Node.js 4.x LTS Argon repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_4.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.PsUJCZaiu2' 'https://rpm.nodesource.com/pub_4.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.PsUJCZaiu2'
## Cleaning up...
+ rm -f '/tmp/tmp.PsUJCZaiu2'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `yum install -y nodejs` (as root) to install Node.js 4.x LTS Argon and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

另外对Node.js的V6Node.js的0.10添加以下信息库。

------- For Node.js v6 -------
# curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
------- For Node.js 0.10 -------
# curl --silent --location https://rpm.nodesource.com/setup | bash -

在Debian,Ubuntu和Linux Mint

$ sudo curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
示例输出
## Installing the NodeSource Node.js 4.x LTS Argon repo...
## Populating apt-get cache...
+ apt-get update
Get:1 http://security.ubuntu.com vivid-security InRelease [65.9 kB]
Get:2 http://ppa.launchpad.net vivid InRelease [15.5 kB]                                                                        
Get:3 http://security.ubuntu.com vivid-security/main Sources [59.7 kB]                                                                
Get:4 http://ppa.launchpad.net vivid/main amd64 Packages [2,304 B]                                                             
Get:5 http://security.ubuntu.com vivid-security/restricted Sources [3,418 B]                                                   
Get:6 http://security.ubuntu.com vivid-security/universe Sources [24.3 kB]                                                 
Get:7 http://security.ubuntu.com vivid-security/multiverse Sources [1,942 B]                                              
Get:8 http://security.ubuntu.com vivid-security/main amd64 Packages [200 kB]                                      
Hit http://dl.hhvm.com trusty InRelease                                                             
Get:9 http://ppa.launchpad.net vivid/main i386 Packages [2,361 B]                                       
Get:10 http://us.archive.ubuntu.com vivid InRelease [218 kB]                                               
Get:11 http://ppa.launchpad.net vivid/main Translation-en [2,148 B]                                         
Get:12 http://dl.hhvm.com trusty/main amd64 Packages [1,688 B]                                                                     
Get:13 http://security.ubuntu.com vivid-security/restricted amd64 Packages [11.2 kB]                               
Get:14 http://security.ubuntu.com vivid-security/universe amd64 Packages [77.0 kB]                                          
Get:15 http://us.archive.ubuntu.com vivid-updates InRelease [65.9 kB]                      
Get:16 http://dl.hhvm.com trusty/main i386 Packages [20 B]                         
Get:17 http://security.ubuntu.com vivid-security/multiverse amd64 Packages [6,028 B]
Get:18 http://security.ubuntu.com vivid-security/main i386 Packages [197 kB]                              
Get:19 http://us.archive.ubuntu.com vivid-backports InRelease [64.5 kB]                   
Get:20 http://security.ubuntu.com vivid-security/restricted i386 Packages [10.9 kB]           
Get:21 http://security.ubuntu.com vivid-security/universe i386 Packages [77.0 kB]                        
Get:22 http://security.ubuntu.com vivid-security/multiverse i386 Packages [6,197 B]                      
Get:23 http://security.ubuntu.com vivid-security/main Translation-en [96.9 kB]                
Ign http://dl.hhvm.com trusty/main Translation-en_US                                   
Get:24 http://security.ubuntu.com vivid-security/multiverse Translation-en [2,743 B]   
Get:25 http://security.ubuntu.com vivid-security/restricted Translation-en [2,774 B]                
Get:26 http://security.ubuntu.com vivid-security/universe Translation-en [48.1 kB]                  
Ign http://dl.hhvm.com trusty/main Translation-en                                     
100% [Working]                                       
....

另外对Node.js的6版添加下面的资料库。

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

第2步:安装最新的Nodejs和NPM

接下来,你现在可以在系统上使用以下命令安装和的NodeJS NPM:

在RHEL,CentOS和Fedora上

# yum -y install nodejs npm
# dnf -y install nodejs npm   [On Fedora 23+ versions]
示例输出
yum -y install nodejs npm
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: centos.excellmedia.net
* epel: mirror.wanxp.id
* extras: mirrors.vhost.vn
* updates: mirrors.vhost.vn
(1/2): epel/x86_64primary_db                                            | 4.1 MB  00:00:28     
(2/2): updates/7/x86_64/primary_db                                      | 4.9 MB  00:00:31     
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:4.4.5-1nodesource.el7.centos will be installed
---> Package npm.noarch 0:1.3.6-5.el7 will be installed
--> Processing Dependency: npm(npmlog) = 0.0.4 for package: npm-1.3.6-5.el7.noarch
--> Processing Dependency: npm(npm-user-validate) = 0.0.3 for package: npm-1.3.6-5.el7.noarch
--> Processing Dependency: npm(init-package-json) = 0.0.10 for package: npm-1.3.6-5.el7.noarch
--> Processing Dependency: npm(editor) = 0.0.4 for package: npm-1.3.6-5.el7.noarch
--> Processing Dependency: npm(block-stream) = 0.0.7 for package: npm-1.3.6-5.el7.noarch
--> Processing Dependency: npm(which) < 2 for package: npm-1.3.6-5.el7.noarch
.....

在Debian,Ubuntu和Linux Mint

$ sudo apt-get install -y nodejs npm
示例输出
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
xsel zsh-common
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libjs-underscore libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-ansi-color-table node-archy node-async
node-block-stream node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent node-form-data node-fstream node-fstream-ignore node-github-url-from-git node-glob
node-graceful-fs node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt
node-normalize-package-data node-npmlog node-once node-osenv node-qs node-read node-read-package-json node-request node-retry node-rimraf node-semver node-sha node-sigmund node-slide
node-tar node-tunnel-agent node-underscore node-which nodejs-dev
Suggested packages:
node-hawk node-aws-sign node-oauth-sign node-http-signature
The following NEW packages will be installed:
gyp javascript-common libc-ares-dev libc-ares2 libjs-node-uuid libjs-underscore libv8-3.14-dev libv8-3.14.5 node-abbrev node-ansi node-ansi-color-table node-archy node-async
node-block-stream node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent node-form-data node-fstream node-fstream-ignore node-github-url-from-git node-glob
node-graceful-fs node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile node-lru-cache node-mime node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt
node-normalize-package-data node-npmlog node-once node-osenv node-qs node-read node-read-package-json node-request node-retry node-rimraf node-semver node-sha node-sigmund node-slide
node-tar node-tunnel-agent node-underscore node-which nodejs nodejs-dev npm
0 upgraded, 57 newly installed, 0 to remove and 92 not upgraded.
Need to get 3,208 kB of archives.
After this operation, 14.9 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ vivid/main libc-ares2 amd64 1.10.0-2 [38.5 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ vivid/universe gyp all 0.1~svn1729-3ubuntu1 [201 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ vivid/main javascript-common all 11 [6,066 B]
Get:4 http://us.archive.ubuntu.com/ubuntu/ vivid/universe libjs-node-uuid all 1.4.0-1 [11.1 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ vivid/main libjs-underscore all 1.7.0~dfsg-1ubuntu1 [46.7 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu/ vivid/universe libv8-3.14.5 amd64 3.14.5.8-5ubuntu2 [1,189 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu/ vivid/universe libv8-3.14-dev amd64 3.14.5.8-5ubuntu2 [57.6 kB]                      
Get:8 http://us.archive.ubuntu.com/ubuntu/ vivid/universe nodejs amd64 0.10.25~dfsg2-2ubuntu1 [684 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu/ vivid/universe node-async all 0.8.0-1 [22.2 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu/ vivid/universe node-node-uuid all 1.4.0-1 [2,530 B]
Get:11 http://us.archive.ubuntu.com/ubuntu/ vivid/universe node-underscore all 1.7.0~dfsg-1ubuntu1 [3,780 B]
Get:12 http://us.archive.ubuntu.com/ubuntu/ vivid/main libc-ares-dev amd64 1.10.0-2 [109 kB]   
...

可选 :有开发工具,如gcc-C ++, 您需要在您的系统上,为了从NPM构建本地插件。

------- On RHEL, CentOS and Fedora -------
# yum install gcc-c++ make
------- On Debian, Ubuntu and Linux Mint -------
$ sudo apt-get install -y build-essential

第3步:测试最新的Node.js和NPM

有和的NodeJS NPM的一个简单的测试,你可以通过检查使用以下命令在系统上安装的版本:

在RHEL,CentOS和Fedora上

# node --version
# npm --version
CentOS 7-检查Nodejs和NPM版本

CentOS 7 - 检查Nodejs和NPM版本

在Debian,Ubuntu和Linux Mint

$ nodejs --version
$ npm --version
Ubuntu 15.10  - 检查Nodejs和NPM版本

Ubuntu 15.10 - 检查Nodejs和NPM版本

这就是它,和的NodeJS NPM已经安装好了,您的系统上使用。

我相信这些是容易和简单的步骤,但是如果你遇到的问题,你可以让我们知道,我们找到方法来帮助你。 希望本指南是对您有所帮助,并永远记住保持联系Howtoing。