在本指南中,我们将了解如何在RHEL,CentOS,Fedora,Debian和Ubuntu发行版中安装最新版本的Nodejs和NPM。
Nodejs是一个轻量级且高效的JavaScript平台,基于Chrome的V8 JavaScript引擎构建,NPM是默认的NodeJS包管理器。您可以使用它来构建可伸缩的网络应用程序。
第1步:添加NodeSource存储库
Node.js和NPM的最新版本可从官方的NodeSource Enterprise Linux,Fedora,Debian和Ubuntu二进制发行版存储库获得,该存储库由Nodejs网站维护,您需要将其添加到您的系统才能安装最新的Nodejs和NPM包。
重要提示:在RHEL 5和CentOS 5下,Node.js包依赖于EPEL存储库,因此如果未安装,脚本将检查并提供说明。
要为最新版本的Node.js添加存储库,请以root身份使用以下命令。
在RHEL,CentOS和Fedora上
---------- 安装 Node.js v11.x ----------
$ curl -sL https://rpm.nodesource.com/setup_11.x | bash -
---------- 安装 Node.js v10.x ----------
$ curl -sL https://rpm.nodesource.com/setup_10.x | bash -
示例输出
## Installing the NodeSource Node.js 11.x 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_11.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.AhnE1gAaMU' 'https://rpm.nodesource.com/pub_11.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.AhnE1gAaMU'
## Cleaning up...
+ rm -f '/tmp/tmp.AhnE1gAaMU'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `sudo yum install -y nodejs` to install Node.js 11.x and npm.
## You may also need development tools to build native addons:
sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn
在 Debian, Ubuntu 和 Linux Mint上
---------- 安装 Node.js v11.x ----------
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
---------- 安装 Node.js v10.x ----------
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
示例输出
## Installing the NodeSource Node.js v11.x repo...
## Populating apt-get cache...
+ apt-get update
Get:1 yakkety-security InRelease [102 kB]
Get:2 yakkety InRelease [247 kB]
Get:3 yakkety-security/main i386 Packages [109 kB]
Get:4 yakkety-updates InRelease [102 kB]
Get:5 yakkety-security/main amd64 Packages [112 kB]
Get:6 yakkety-security/universe amd64 Packages [56.5 kB]
Get:7 yakkety-security/universe i386 Packages [54.3 kB]
Get:8 yakkety-backports InRelease [102 kB]
Get:9 yakkety-security/universe Translation-en [35.2 kB]
Get:10 yakkety-updates/main amd64 Packages [224 kB]
Get:11 yakkety-updates/main i386 Packages [221 kB]
Get:12 yakkety-updates/main Translation-en [100.0 kB]
Get:13 yakkety-updates/universe amd64 Packages [144 kB]
Get:14 yakkety-updates/universe i386 Packages [142 kB]
Get:15 yakkety-updates/universe Translation-en [76.2 kB]
Get:16 yakkety-updates/multiverse amd64 Packages [4,632 B]
Get:17 yakkety-updates/multiverse Translation-en [2,252 B]
Fetched 1,835 kB in 7s (261 kB/s)
Reading package lists... Done
## Confirming "yakkety" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_11.x/dists/yakkety/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK
## Creating apt sources list file for the NodeSource Node.js v11.x repo...