GNU/Linux >> Linux Esercitazione >  >> Debian

Come installare e utilizzare NVM su Debian 11

NVM è un gestore di versioni per Node.js utilizzato per installare e gestire più versioni di Node.js in Linux. È un'utilità della riga di comando e fornisce diverse opzioni per la facile installazione di Node.js. Ti permette di scaricare e installare qualsiasi versione di Node in locale con un semplice comando.

In questo post, ti mostreremo come installare e utilizzare NVM per gestire Node.js su Debian 11.

Prerequisiti

  • Un server che esegue Debian 11.
  • Sul server è configurata una password di root.

Installa NVM

L'installazione di NVM è un processo molto semplice. Puoi semplicemente installarlo usando il comando CURL.

Innanzitutto, installa CURL e Gnupg2 con il seguente comando:

apt-get install curl gnupg2 -y

Quindi, esegui il comando seguente per scaricare ed eseguire lo script di installazione della NVM:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

Il comando precedente installerà NVM ed eseguirà tutte le impostazioni dell'ambiente richieste in .bashrc file.

Ora, attiva tutte le impostazioni usando il seguente comando:

source ~/.bashrc

Ora verifica la versione NVM usando il seguente comando:

nvm --version

Dovresti vedere il seguente output:

0.38.0

Installa Node.js con NVM

A questo punto, NVM è installato nel tuo sistema. Ora puoi installare qualsiasi versione di Node.js sul tuo sistema.

Per installare l'ultima versione di Node.js, esegui il comando seguente:

nvm install node

Dovresti vedere il seguente output:

Downloading and installing node v16.9.0...
Downloading https://nodejs.org/dist/v16.9.0/node-v16.9.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.9.0 (npm v7.21.1)
Creating default alias: default -> node (-> v16.9.0)

Per verificare la versione installata di Node.js, esegui il comando seguente:

node --version

Dovresti vedere il seguente output:

v16.9.0

Se desideri installare l'ultima versione stabile di Node.js, esegui il comando seguente:

nvm install node --lts

Dovresti vedere il seguente output:

v16.9.0 is already installed.
Now using node v16.9.0 (npm v7.21.1)

Per installare la versione specifica di Node.js (12.17.0), eseguire il comando seguente:

nvm install 12.17.0

Dovresti vedere il seguente output:

Downloading and installing node v12.17.0...
Downloading https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.xz...
######################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.17.0 (npm v6.14.4)

Ora verifica la versione corrente di Node.js usando il seguente comando:

node --version

Dovresti vedere il seguente output:

v12.17.0

Utilizza NVM per gestire le versioni di Node.js

Per elencare tutte le versioni di Node.js installate nel tuo sistema, esegui il comando seguente:

nvm ls

Dovresti vedere il seguente output:

->     v12.17.0
        v16.9.0
default -> node (-> v16.9.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.9.0) (default)
stable -> 16.9 (-> v16.9.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.6 (-> N/A)
lts/fermium -> v14.17.6 (-> N/A)

Puoi trovare tutte le versioni di Node.js disponibili usando il seguente comando:

nvm ls-remote

Per impostare la versione predefinita di Node.js su 12.17.0, esegui il comando seguente:

nvm use 12.17.0

Dovresti vedere il seguente output:

Now using node v12.17.0 (npm v6.14.4)

Per trovare la versione predefinita per l'utente corrente, eseguire il comando seguente:

nvm run default --version

Dovresti vedere il seguente output:

Running node v16.9.0 (npm v7.21.1)
v16.9.0

Puoi anche eseguire un'applicazione Node con una versione di Node.js specifica utilizzando il comando seguente:

nvm run v12.17.0 app.js

Per rimuovere una specifica versione di Node.js dal tuo sistema, esegui il comando seguente:

nvm uninstall v12.17.0

Conclusione

In questo post, abbiamo spiegato come installare NVM per installare Node.js su Debian 11. Abbiamo anche spiegato come passare da una versione all'altra di Node.js usando NVM. Spero che ora tu possa eseguire la tua applicazione con qualsiasi versione di Node.js.


Debian
  1. Come installare e utilizzare Debian Backports

  2. Come installare e utilizzare Ansible su Debian 11

  3. Come installare Node.js e npm su Debian 11

  4. Installa e usa NVM su Debian 11

  5. Come installare Node.js e NPM su Debian 11

Come installare Node.js su Debian 8

Come installare Node.js su Debian 9

Come installare Node.js su Debian 10

Come installare Node.js su Debian 11

Come installare NVM su Debian 11

Come installare Node.js su Debian