Come installare l’ultima versione di NodeJS e NPM in Linux

In questa guida, vedremo come è possibile installare l’ultima versione di Nodejs e NPM sulle distribuzioni basate su RHEL come CentOS, Fedora, Rocky & AlmaLinux e le distribuzioni basate su Debian come Ubuntu & Linux Mint.

Nodejs è una piattaforma JavaScript leggera ed efficiente che è costruita basandosi sul motore JavaScript V8 di Chrome e NPM è un gestore di pacchetti NodeJS predefinito. Puoi usarlo per creare applicazioni di rete scalabili.

Come Installare Node.js nelle Distribuzioni RHEL

La versione più recente di Node.js e NPM è disponibile dal repository ufficiale NodeSource Enterprise Linux, mantenuto dal sito web di Nodejs e sarà necessario aggiungerlo al sistema per poter installare le ultime versioni dei pacchetti Nodejs e NPM.

Importante: Se stai usando una versione più vecchia di RHEL 6 o CentOS 6, potresti voler leggere su come eseguire Node.js su distro più vecchie.

Installazione di NodeJS in RHEL, CentOS, Fedora, Rocky & Alma

Per aggiungere il repository per l’ultima versione di Node.js, usa il seguente comando come root o utente non root.

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_19.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v18.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v16.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
$ sudo yum install -y nodejs

------------- For Node.js v14.x ------------- 
$ curl -fsSL https://rpm.nodesource.com/setup_14.x | sudo bash -
$ sudo yum install -y nodejs

Opzionale: Ci sono strumenti di sviluppo come gcc-c++ e make che devi avere sul sistema, per poter compilare i componenti aggiuntivi nativi da npm.

# yum install gcc-c++ make
OR
# yum groupinstall 'Development Tools'

Come installare Node.js in Debian, Ubuntu e Linux Mint

La versione più recente di Node.js e NPM è disponibile anche dal repository ufficiale di NodeSource Enterprise Linux, mantenuto dal sito web di Nodejs e sarà necessario aggiungerlo al sistema per poter installare le ultime versioni dei pacchetti Nodejs e NPM.

Installare Node.js su Ubuntu e Mint

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v18.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v16.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v14.x -------------
$ curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - &&\
$ sudo apt-get install -y nodejs

Installare Node.js su Debian

------------- For Node.js v19.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_19.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v18.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v16.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &&\
$ sudo apt-get install -y nodejs

------------- For Node.js v14.x ------------- 
$ curl -fsSL https://deb.nodesource.com/setup_14.x | bash - &&\
$ sudo apt-get install -y nodejs

Opzionale: Ci sono strumenti di sviluppo come gcc-c++ e make che è necessario avere nel proprio sistema, al fine di compilare componenti aggiuntivi nativi da npm.

$ sudo apt-get install -y build-essential

Test di Nodejs e NPM più recenti in Linux

Per effettuare un semplice test di Nodejs e NPM, è possibile controllare le versioni installate nel proprio sistema utilizzando i seguenti comandi:

Sui sistemi basati su RHEL

# node --version
# npm --version

Su Debian, Ubuntu e Linux Mint

$ nodejs --version
$ npm --version
Check NodeJS Version on CentOS

Ecco fatto, Nodejs e NPM sono ora installati e pronti per l’uso nel tuo sistema.

I believe these were easy and simple steps to follow but in case of problems you faced, you can let us know and we find ways of helping you. I hope this guide was helpful to you and always remember to stay connected to Tecmint.

Source:
https://www.tecmint.com/install-nodejs-npm-in-centos-ubuntu/