GNU/Linux >> Linux Esercitazione >  >> Cent OS

Centos:perché la nuova versione corretta di Node.js non viene installata su Centos 7?

Nota:questo problema è parzialmente risolto, ma richiede un po' più di attenzione. Vedi le note in fondo a OP e la risposta parziale di @Digisec.

Sto provando a configurare Node.js su CentOS 7, ma i seguenti comandi non riescono a installare l'ultima versione. Cosa devo modificare nel codice seguente per installare la versione più recente di Node.js su CentOS 7?

Comincio digitando node --version che risulta in v0.12.7 . Questa è chiaramente una vecchia versione perché nodejs.org dice che v5.6.0 è l'ultima versione stabile.

Quindi digito quanto segue per ottenere l'ultima versione di node.js:

cd /tmp
curl -sL https://rpm.nodesource.com/setup | bash -

Il terminale stampa che dovrei digitare quanto segue per rimuovere la versione obsoleta di node.js, quindi digito quanto segue:

yum remove -y nodejs npm

Il terminale dice anche di digitare quanto segue per installare la versione più recente di node.js, quindi digito quanto segue:

yum install -y nodejs

Ma poi digito node --version di nuovo, e il terminale risponde con v0.12.7 ancora una volta, mostrando che i comandi precedenti hanno semplicemente reinstallato di nuovo la vecchia versione obsoleta.

Quindi cosa devo fare per ottenere la versione stabile più recente di node.js installata sulla macchina CentOS 7?

SFORZI IN CORSO:

Secondo il suggerimento di @Digisec, ho eseguito nuovamente i comandi precedenti, ma questa volta ho registrato tutto l'output nel testo seguente. Tieni presente che la sequenza è leggermente diversa ora che la sto eseguendo di nuovo, ma il risultato è lo stesso, come segue:

[[email protected] ~]# node --version
v0.12.7
[[email protected] ~]# cd /tmp
[[email protected] tmp]# curl -sL https://rpm.nodesource.com/setup | bash -

## Installing the NodeSource Node.js 0.10 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_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.ePYEdVWXQH' 'https://rpm.nodesource.com/pub_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.ePYEdVWXQH'

## Cleaning up...

+ rm -f '/tmp/tmp.ePYEdVWXQH'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `yum install -y nodejs` (as root) to install Node.js 0.10 and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

[[email protected] tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                     Repository                                Size
====================================================================================================================================================================================
Removing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                              @nodesource                               16 M

Transaction Summary
====================================================================================================================================================================================
Remove  1 Package

Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 

Removed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[[email protected] tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                      Repository                               Size
====================================================================================================================================================================================
Installing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                               nodesource                              4.5 M

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

Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm                                                                                                             | 4.5 MB  00:00:09     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 

Installed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[[email protected] tmp]# node --version
v0.12.7
[[email protected] tmp]#   

Quindi, secondo la risposta di @Digisec , ho quindi provato quanto segue, ma ​​il risultato continua a non installare la versione corretta , come puoi vedere dal seguente output di terminale:

[[email protected] tmp]# curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

## Installing the NodeSource Node.js 5.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_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.NEM1bxM9WB' 'https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.NEM1bxM9WB'

## Cleaning up...

+ rm -f '/tmp/tmp.NEM1bxM9WB'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `yum install -y nodejs` (as root) to install Node.js 5.x and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

[[email protected] tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                     Repository                                Size
====================================================================================================================================================================================
Removing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                              @nodesource                               16 M

Transaction Summary
====================================================================================================================================================================================
Remove  1 Package

Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                             1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                             1/1 

Removed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[[email protected] tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                      Repository                               Size
====================================================================================================================================================================================
Installing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                               nodesource                              4.5 M

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

Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
nodejs-0.10.42-1nodesource.el7 FAILED                                          
https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found           ]  0.0 B/s |    0 B  --:--:-- ETA 
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/



Error downloading packages:
  nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.

[[email protected] tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                      Repository                               Size
====================================================================================================================================================================================
Installing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                               nodesource                              4.5 M

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

Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
No Presto metadata available for nodesource  
nodejs-0.10.42-1nodesource.el7 FAILED    
https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found           ]  0.0 B/s |    0 B  --:--:-- ETA 
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/



Error downloading packages:
  nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.

[[email protected] tmp]# node --version
v0.12.7
[[email protected] tmp]# 

Ho quindi visitato l'articolo della knowledge base a cui fa riferimento il registro degli errori sopra, ma ho scoperto che non riesco ad accedere all'articolo completo perché non sono un cliente Red Had.

Correlati:Linux – Directory standard e/o comuni su sistemi operativi Unix/Linux?

SOLUZIONE PARZIALE:

@Digisec ha parzialmente risolto questo problema mostrando come installare la nuova versione, ma non siamo ancora in grado di rimuovere la vecchia versione, il che lascerà il rischio di conflitti in futuro. Quali passaggi sono necessari per rimuovere la vecchia versione in modo che la nuova installazione possa essere pulita e completa?

Ho trovato l'URL tar per la vecchia versione v0.12.7 a questo link. E @Digisec' ha anche suggerito di leggere questo altro link, che suggerisce di usare il comando make uninstall . Ho la sensazione che potrebbero esserci solo cinque o dieci comandi da digitare nel terminale per rimuovere la vecchia v0.12.7 e reinstallare la nuova versione di nodejs. Quali sono i comandi richiesti?

Mi sembra di aver trovato tre file tar sulla macchina CentOS 7 correlati a nodejs v0.12.7 utilizzando i seguenti comandi da terminale:

[[email protected] ~]# cd /
[r[email protected] /]# find . -type f -iname "*.tar"
find: ‘./run/user/1000/gvfs’: Permission denied
./opt/node-v0.12.7/deps/npm/node_modules/tar/test/dir-normalization.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore-2.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore-2.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/node_modules/tar/test/dir-normalization.tar
[[email protected] /]# 

Nota che ci sono altri tre file tar contrassegnati con node_modules la cui relazione con v0.12.7 non è chiaro.

Quali comandi specifici eseguo per disinstallare in modo sicuro v0.12.7 e rimuovi tutto il v0.12.7 file tar associati dalla macchina?

Risposta accettata:

Ho appena controllato il link da cui l'hai preso. Stai installando, in particolare, la versione 0.10 , o almeno provando a farlo, ma hai una versione più recente nel repository in fase di installazione. Devi seguire la configurazione per il nodo v5.

curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

PS :per riferimento futuro, assicurati di leggere i siti con molta attenzione specialmente quando esegui comandi come root .

MODIFICA: Va bene, sembra che tu abbia aggiunto il repository correttamente. Esaminando il repository, i tuoi pacchetti sono lì ma il sistema sta cercando la versione sbagliata. A questo punto, suggerirei.

yum clean all && yum update

Ciò pulirà il repository memorizzato nella cache e acquisirà da remoto.

Correlati:perché Windows Update sta tentando di installare un aggiornamento che non mi serve?

Risposta: Dopo il lavoro che abbiamo svolto sulla chat , ecco la risposta corretta per te. nodejs v5 installato bene. In precedenza hai compilato nodejs v0.12 manualmente, il che non è una buona idea sulle distribuzioni binarie, perché finirai in questa posizione.

which node

restituito

/usr/local/bin/node

mentre

/usr/bin/node

ha restituito la risposta corretta di v5.x .

A questo punto hai più opzioni per risolverlo, ma ti consiglio 2.

  • Opzione 1 :Questa è la via d'uscita più semplice. Puoi modificare il tuo .bashrc e aggiungi un alias che punterà a node -> /usr/bin/node . Questo è semplice come aggiungere alias node="/usr/bin/node" . Questo chiamerà ogni volta la versione corretta, ma non posso garantire che non causerà conflitti in futuro con le librerie.
  • Opzione 2 :Questo è il modo più difficile, ma lo risolverà. Per prima cosa, elimina con yum il nodejs installato sul sistema. Secondo, prendi il tarball per la versione che hai compilato, decomprimilo, ./configure e disinstallarlo. Questo passaggio lo puoi trovare facilmente online. Infine, reinstalla nodejs tramite yum , e questo dovrebbe risolvere il tuo problema.

Cent OS
  1. Come installare l'ultima versione di Python 3 su CentOS 7

  2. Come installare lo stack LAMP su CentOS 7

  3. Come installare Node.js e NPM su CentOS

  4. Come installare MongoDB 4.2 / 4.0 su CentOS 6 / RHEL 6

  5. Come installare il firewall CSF su CentOS 7

Come installare PHP 7.4 su CentOS 8

Come installare l'ultima versione di LibreOffice su CentOS 8

Come installare una versione specifica del kernel in CentOS

Come installare Node.js su CentOS 7

Come installare la versione principale di Nginx su CentOS 7

Come installare Node.js su CentOS Stream 9