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

2020-09-17 0 397 百度已收录

在本指南中,我们将了解如何在RHEL,CentOS,FedoraDebian和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 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu yakkety-security/main i386 Packages [109 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]
Get:5 http://security.ubuntu.com/ubuntu yakkety-security/main amd64 Packages [112 kB]
Get:6 http://security.ubuntu.com/ubuntu yakkety-security/universe amd64 Packages [56.5 kB]
Get:7 http://security.ubuntu.com/ubuntu yakkety-security/universe i386 Packages [54.3 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB]
Get:9 http://security.ubuntu.com/ubuntu yakkety-security/universe Translation-en [35.2 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 Packages [224 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main i386 Packages [221 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main Translation-en [100.0 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 Packages [144 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe i386 Packages [142 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe Translation-en [76.2 kB]                                                                                               
Get:16 http://us.archive.ubuntu.com/ubuntu yakkety-updates/multiverse amd64 Packages [4,632 B]                                                                                             
Get:17 http://us.archive.ubuntu.com/ubuntu 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…

+ echo ‘deb https://deb.nodesource.com/node_11.x yakkety main’ > /etc/apt/sources.list.d/nodesource.list
+ echo ‘deb-src https://deb.nodesource.com/node_6.11 yakkety main’ >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you…

+ apt-get update
Get:1 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety InRelease [247 kB]   
Get:3 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]
Get:4 https://deb.nodesource.com/node_11.x yakkety InRelease [3,915 B]
Get:5 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB]
Get:6 https://deb.nodesource.com/node_11.x yakkety/main Sources [765 B]
Get:7 https://deb.nodesource.com/node_11.x yakkety/main i386 Packages [961 B]
Get:8 https://deb.nodesource.com/node_11.x yakkety/main amd64 Packages [964 B]
Fetched 560 kB in 2s (215 kB/s) 
Reading package lists… Done

## Run `apt-get install nodejs` (as root) to install Node.js v11.x and npm

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

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

在RHEL,CentOS和Fedora上

# yum -y install nodejs
# dnf -y install nodejs  [On Fedora 22+ versions]

示例输出
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.vbctv.in
 * elrepo: mirrors.coreix.net
 * epel: repos.del.extreme-ix.org
 * extras: mirror.vbctv.in
 * updates: mirror.vbctv.in
Resolving Dependencies
–> Running transaction check
—> Package nodejs.x86_64 2:11.3.0-1nodesource will be installed
–> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                  Arch                                    Version                                                  Repository                                    Size
===============================================================================================================================================================================================
Installing:
 nodejs                                  x86_64                                  2:11.3.0-1nodesource                                    nodesource                                    18 M

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package

Total download size: 18 M
Installed size: 54 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/nodesource/packages/nodejs-11.3.0-1nodesource.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 34fa74dd: NOKEY===========-] 2.8 MB/s |  18 MB  00:00:00 ETA
Public key for nodejs-11.3.0-1nodesource.x86_64.rpm is not installed
nodejs-11.3.0-1nodesource.x86_64.rpm                                                                                                                                    |  18 MB  00:00:05   
Retrieving key from file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Importing GPG key 0x34FA74DD:
 Userid    : “NodeSource “
 Fingerprint: 2e55 207a 95d9 944b 0cc9 3261 5ddb e8d4 34fa 74dd
 Package    : nodesource-release-el7-1.noarch (installed)
 From      : /etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : 2:nodejs-11.3.0-1nodesource.x86_64                                                                                                                                          1/1
  Verifying  : 2:nodejs-11.3.0-1nodesource.x86_64                                                                                                                                          1/1

Installed:
  nodejs.x86_64 2:11.3.0-1nodesource                                                                                                                                                         

Complete!

在 Debian, Ubuntu 和 Linux Mint

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo apt-get install -y nodejs
正在读取软件包列表… 完成
正在分析软件包的依赖关系树     
正在读取状态信息… 完成     
下列软件包是自动安装的并且现在不需要了:
  gyp javascript-common libc-ares2 libhttp-parser2.7.1 libjs-async
  libjs-inherits libjs-jquery libjs-node-uuid libjs-underscore
  libssl1.0-dev libuv1-dev nodejs-doc
使用’sudo apt autoremove’来卸载它(它们)。
下列【新】软件包将被安装:
  nodejs
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 71 个软件包未被升级。
需要下载 16.0 MB 的归档。
解压缩后会消耗 77.4 MB 的额外空间
获取:1 https://deb.nodesource.com/node_11.x bionic/main amd64 nodejs amd64 11.10.0-1nodesource1 [16.0 MB]
已下载 14.8 MB,耗时 8分 37秒 (28.6 kB/s)                                 
正在选中未选择的软件包 nodejs。
(正在读取数据库 … 系统当前共安装有 157990 个文件目录。)
正准备解包 …/nodejs_11.10.0-1nodesource1_amd64.deb  …
正在解包 nodejs (11.10.0-1nodesource1) …
正在设置 nodejs (11.10.0-1nodesource1) …
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 …

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

可选:为了从npm构建本机插件,有一些开发工具,如gcc-c ++和make,你需要在你的系统上使用。

——- 在 RHEL, CentOS 和 Fedora ——-
# yum install gcc-c++ make

——- 在 Debian, Ubuntu 和 Linux Mint ——-
$ sudo apt-get install -y build-essential

第3步:测试最新的Nodejs和NPM

要对nodejs和NPM进行简单测试,可以使用以下命令检查系统上安装的版本:

在 RHEL, CentOS 和 Fedora
# node –version
# npm –version

在 Debian, Ubuntu 和 Linux Mint
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ npm –version
6.7.0
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ nodejs –version
v11.10.0

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

就是这样,Nodejs和NPM现在已经安装好并可以在你的系统上使用了

我相信这些都是简单而简单的步骤,但如遇到您遇到的问题,您可以告诉我们,我们会找到帮助您的方法。 希望本指南对您有所帮助,并始终记得与linuxidc.com保持联系。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 在Linux系统中安装最新的Nodejs和NPM版本 https://www.lizi.tw/soft/13759.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

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

分享本文封面