332 lines
6.1 KiB
Markdown
332 lines
6.1 KiB
Markdown
# nvm
|
||
|
||
|
||
|
||
[nvm](https://github.com/nvm-sh/nvm) est un gestionnaire de version pour Node.
|
||
|
||
|
||
|
||
### Installation
|
||
|
||
#### Avec Homebrew:
|
||
|
||
Installer nvm:
|
||
|
||
```bash
|
||
$ brew install nvm
|
||
```
|
||
|
||
Créer un répertoire où sera installé les différentes versions de Node.
|
||
|
||
```bash
|
||
$ mkdir ~/.nvm
|
||
```
|
||
|
||
Editer .bash_profile pour régler le répertoire NVM_DIR
|
||
|
||
```bash
|
||
$ nano ~/.bash_profile
|
||
```
|
||
|
||
et ajouter les lignes suivantes.
|
||
|
||
```bash
|
||
export NVM_DIR=~/.nvm
|
||
source $(brew --prefix nvm)/nvm.sh
|
||
```
|
||
|
||
Recharger le shell pour activer nvm.
|
||
|
||
```bash
|
||
$ source ~/.bash_profile
|
||
|
||
$ echo $NVM_DIR
|
||
$ nvm --version
|
||
```
|
||
|
||
|
||
|
||
#### Avec git (méthode officielle):
|
||
|
||
```bash
|
||
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.40.1/install.sh | bash
|
||
```
|
||
|
||
Le script d'installation ajoute les lignes suivantes à votre profil (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
||
|
||
```bash
|
||
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
|
||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||
```
|
||
|
||
#### Mettre à jour:
|
||
|
||
Relancer le script d'installation
|
||
|
||
```bash
|
||
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
||
```
|
||
|
||
|
||
|
||
|
||
|
||
### Utilisation:
|
||
|
||
Installer NodeJS.
|
||
|
||
```bash
|
||
# la dernière version 8
|
||
$ nvm install 8
|
||
|
||
# la version 8.9.4
|
||
$ nvm install 8.9.4
|
||
|
||
# la dernière version 6
|
||
$ nvm install 6
|
||
|
||
# la dernière version LTS (v18)
|
||
$ nvm install --lts=hydrogen
|
||
|
||
# la dernière version LTS (v20)
|
||
$ nvm install --lts=iron
|
||
```
|
||
|
||
https://nodejs.org/fr/about/previous-releases
|
||
|
||
Mettre à jour NodeJS et réinstaller les paquets.
|
||
|
||
```bash
|
||
Latest version:
|
||
nvm install node --reinstall-packages-from=node
|
||
# nvm install node && nvm reinstall-packages $(nvm current | sed 's/^.//')
|
||
|
||
Stable (LTS) version:
|
||
nvm install lts/* --reinstall-packages-from=node
|
||
# nvm install --lts=erbium && nvm reinstall-packages $(nvm current | sed 's/^.//')
|
||
# nvm install --lts=erbium && nvm reinstall-packages 12.18.3
|
||
|
||
nvm install --lts=hydrogen --reinstall-packages-from=18.17.0
|
||
```
|
||
|
||
Liste des versions de Node installées:
|
||
|
||
```bash
|
||
$ nvm ls
|
||
# ou
|
||
$nvm list
|
||
-> v8.11.4
|
||
v10.9.0
|
||
default -> 8 (-> v8.11.4)
|
||
node -> stable (-> v10.9.0) (default)
|
||
stable -> 10.9 (-> v10.9.0) (default)
|
||
iojs -> N/A (default)
|
||
lts/* -> lts/carbon (-> v8.11.4)
|
||
lts/argon -> v4.9.1 (-> N/A)
|
||
lts/boron -> v6.14.4 (-> N/A)
|
||
lts/carbon -> v8.11.4
|
||
```
|
||
|
||
Liste des versions de Node installables:
|
||
|
||
```bash
|
||
$ nvm ls-remote
|
||
v0.1.14
|
||
v0.1.15
|
||
.../...
|
||
v12.12.0
|
||
v12.13.0 (LTS: Erbium)
|
||
-> v12.13.1 (Latest LTS: Erbium)
|
||
v13.0.0
|
||
v13.0.1
|
||
v13.1.0
|
||
v13.2.0
|
||
```
|
||
|
||
Versions téléchargées:
|
||
|
||
```bash
|
||
$ cd $NVM_DIR
|
||
- OR -
|
||
$ cd ~/.nvm
|
||
$ ls versions/node
|
||
v10.9.0 v8.11.4
|
||
```
|
||
|
||
Version en usage:
|
||
|
||
```bash
|
||
$ nvm current
|
||
v16.17.1
|
||
|
||
$ node -v
|
||
v16.17.1
|
||
```
|
||
|
||
Changer de version:
|
||
|
||
```bash
|
||
$ nvm use 10.9.0
|
||
Now using node v10.9.0 (npm v6.2.0)
|
||
$ nvm use 10
|
||
Now using node v10.9.0 (npm v6.2.0)
|
||
$ node -v
|
||
v10.9.0
|
||
```
|
||
|
||
```bash
|
||
$ nvm use 8.11.4
|
||
Now using node v8.11.4 (npm v5.6.0)
|
||
$ node -v
|
||
v8.11.4
|
||
```
|
||
|
||
```bash
|
||
$ nvm use --lts
|
||
Now using node v8.11.4 (npm v5.6.0)
|
||
|
||
# Utilise la dernière version LTS
|
||
|
||
$ nvm use --lts=erbium
|
||
Now using node v12.20.0 (npm v6.14.8)
|
||
|
||
# Utilise la dernière version LTS=erbium
|
||
```
|
||
|
||
Alias:
|
||
|
||
```bash
|
||
$ nvm alias maintenance 16.17.0
|
||
maintenance -> 16.17.0 (-> v16.17.0)
|
||
```
|
||
|
||
```bash
|
||
$ nvm use maintenance
|
||
Now using node v16.17.0 (npm v8.19.2)
|
||
```
|
||
|
||
```bash
|
||
$ nvm unalias maintenance
|
||
Deleted alias maintenance - restore it with `nvm alias "maintenance" "16.17.0"`
|
||
```
|
||
|
||
Changer la version par défaut (résiste à un changement de fenêtre du terminal):
|
||
|
||
```bash
|
||
$ nvm alias default 10.15.0
|
||
default -> 10.15.0 (-> v10.15.0)
|
||
|
||
# Dernière version de node par défaut
|
||
$ nvm alias default node
|
||
default -> node (-> v14.15.0)
|
||
```
|
||
|
||
Réinstaller les paquets d'une ancienne version après une mise-à jour:
|
||
|
||
```bash
|
||
$ nvm current
|
||
v8.11.4
|
||
$ nvm install --lts=dubnium
|
||
Now using node v10.15.0 (npm v6.4.1)
|
||
|
||
$ nvm reinstall-packages 8
|
||
|
||
# update 12.13.1 depuis 12.13.0
|
||
$ nvm reinstall-packages 12.13.0
|
||
```
|
||
|
||
Désinstaller une version de Node:
|
||
|
||
```bash
|
||
$ nvm uninstall 10.16.2
|
||
Uninstalled node v10.16.2
|
||
|
||
$ nvm uninstall --lts=carbon
|
||
Uninstalled node v8.17.0
|
||
```
|
||
|
||
Les paquets sont installés dans:
|
||
|
||
```bash
|
||
bruno@silverbook: ~/.nvm/versions/node/v10.16.3/lib/node_modules $ ls
|
||
ezshare npm
|
||
|
||
bruno@silverbook: ~/.nvm/versions/node/v10.16.2/lib/node_modules $ ls
|
||
npm
|
||
```
|
||
|
||
Current:
|
||
|
||
https://medium.com/@danielzen/using-nvm-with-webstorm-or-other-ide-d7d374a84eb1
|
||
|
||
```bash
|
||
$ export NVM_SYMLINK_CURRENT=true
|
||
|
||
# choisir le dernier lts
|
||
$ nvm use --lts
|
||
Now using node v14.15.1 (npm v6.14.9)
|
||
|
||
$ ls -ld $NVM_DIR/current
|
||
lrwxr-xr-x 1 bruno staff 40 Nov 30 15:26 /Users/bruno/.nvm/current -> /Users/bruno/.nvm/versions/node/v14.15.1
|
||
|
||
# ~/.nvm/current/bin/node comme node par défaut
|
||
|
||
~/.nvm/current/bin tags/v0.37.2
|
||
❯ ls
|
||
total 81296
|
||
lrwxr-xr-x 1 bruno staff 36 Dec 21 12:05 ezshare -> ../lib/node_modules/ezshare/index.js
|
||
lrwxr-xr-x 1 bruno staff 34 Dec 26 08:47 joplin -> ../lib/node_modules/joplin/main.js
|
||
lrwxr-xr-x 1 bruno staff 39 Dec 21 12:05 ng -> ../lib/node_modules/@angular/cli/bin/ng
|
||
-rwxr-xr-x 1 bruno staff 73884800 Dec 17 20:17 node
|
||
lrwxr-xr-x 1 bruno staff 38 Dec 21 13:52 npm -> ../lib/node_modules/npm/bin/npm-cli.js
|
||
lrwxr-xr-x 1 bruno staff 38 Dec 21 13:52 npx -> ../lib/node_modules/npm/bin/npx-cli.js
|
||
lrwxr-xr-x 1 bruno staff 44 Dec 21 12:05 thumbsup -> ../lib/node_modules/thumbsup/bin/thumbsup.js
|
||
lrwxr-xr-x 1 bruno staff 44 Dec 21 12:05 workbox -> ../lib/node_modules/workbox-cli/build/bin.js
|
||
|
||
```
|
||
|
||
|
||
|
||
### Erreur:
|
||
|
||
```bash
|
||
# A l'ouverture d'une fenêtre bash
|
||
|
||
N/A: version "N/A -> N/A" is not yet installed.
|
||
|
||
You need to run "nvm install N/A" to install it before using it.
|
||
```
|
||
|
||
Entrer:
|
||
|
||
```bash
|
||
$ nvm alias default 12
|
||
```
|
||
|
||
|
||
|
||
### Desinstaller nvm:
|
||
|
||
1. Désactiver nvm
|
||
|
||
```bash
|
||
$ nvm deactivate
|
||
```
|
||
|
||
2. Désinstaller nvm
|
||
|
||
```bash
|
||
$ nvm unload
|
||
```
|
||
|
||
3. Nettoyer .zshrc ou .bashrc
|
||
|
||
```bash
|
||
# Supprimer les lignes:
|
||
|
||
export NVM_DIR="$HOME/.nvm"
|
||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm
|
||
```
|
||
|