Instale la última versión de Nodejs y NPM en sistemas Linux


En esta guía, veremos cómo instalar la última versión de Nodejs y NPM en las distribuciones RHEL, CentOS, Fedora, Debian y Ubuntu.

Nodejs es una plataforma de JavaScript liviana y eficiente que se basa en el motor Chrome de JavaScript V8 y NPM es un administrador de paquetes predeterminado de NodeJS. Puedes usarlo para construir aplicaciones de red escalables.

Paso 1: Agregar el repositorio de NodeSource

La última versión de Node.js y NPM está disponible en la versión oficial de NodeSource Enterprise Linux , Fedora , Debian y el repositorio de distribuciones binarias de Ubuntu , que se mantiene en el sitio web de Nodejs y deberá agregarlo a su sistema para poder instalar el último Nodejs y NPM paquetes.

rojo

Para agregar el repositorio para la última versión de Node.js , use el siguiente comando como root.

---------- Install Node.js v11.x ---------- 
$ curl -sL https://rpm.nodesource.com/setup_11.x | bash -

---------- Install 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
---------- Install Node.js v11.x ---------- 
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -

---------- Install 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

Paso 2: Instala los últimos Nodejs y NPM

A continuación, ahora puede instalar Nodejs y NPM en su sistema usando el siguiente comando:

# 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 <[email protected]>"
 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!
$ sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 106 not upgraded.
Need to get 10.3 MB of archives.
After this operation, 52.1 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_11.x yakkety/main amd64 nodejs amd64 11.3.0-1nodesource1~yakkety1 [10.3 MB]
Fetched 10.3 MB in 45s (224 kB/s)                                                                                                   
Selecting previously unselected package nodejs.
(Reading database ... 65830 files and directories currently installed.)
Preparing to unpack .../nodejs_11.3.0-1nodesource1~yakkety1_amd64.deb ...
Unpacking nodejs (11.3.0-1nodesource1~yakkety1) ...
Setting up nodejs (11.3.0-1nodesource1~yakkety1) ...
Processing triggers for man-db (2.7.5-1) ...

rojo

------- On RHEL, CentOS and Fedora -------
# yum install gcc-c++ make

------- On Debian, Ubuntu and Linux Mint -------
$ sudo apt-get install -y build-essential

Paso 3: Probando los últimos Nodejs y NPM

Para realizar una prueba simple de nodejs y NPM , puede verificar las versiones instaladas en su sistema usando los siguientes comandos:

# node --version
# npm --version
$ nodejs --version
$ npm --version

Eso es todo, Nodejs y NPM ahora están instalados y listos para su uso en su sistema.

Creo que estos fueron pasos fáciles y sencillos de seguir, pero en caso de problemas que enfrentó, puede informarnos y encontrar formas de ayudarlo. Espero que esta guía le haya sido útil y recuerde siempre estar conectado con Tecmint .