Node Version Manager (NVM)

12. Januar 2017 / JS / Mac / Node.js / Ubuntu

×Info: This post is older than 2 years! Displayed information may be outdated!

Mit Node Version Manager kann man als Developer mehrere Node-Versionen parallel installieren und nutzen.

Zuvor habe ich Node auf dem Mac mit Homebrew installiert, aber dort fällt immer nur die jeweils aktuelle Version raus (v7.4.x in meinem Fall). Mit NVM kann man auch die aktuelle „LTS“-Version (v6.9.x) installieren (gleiches gilt für die Installation auf Ubuntu).

Vorbereitungen

Zuvor alle Node-Versionen löschen / deinstallieren (egal ob Node mit Homebrew oder mit dem .pkg-Installer installiert wurde).

Installation

# install
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

# The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
# Note: On OS X, if you get nvm: command not found after running the install script, your system may not have a [.bash_profile file] where the command is set up. Simply create one with touch ~/.bash_profile and run the install script again.
#If the above doesn't fix the problem, open your .bash_profile and add the following line of code:
# source ~/.bashrc

# verify that nvm has been installed (in a new shell):
command -v nvm

# install current Node LTS version:
nvm install --lts

# installs specific LTS version:
nvm install --lts=boron # boron = v6.x.x

# setting my current Node LTS Version (v6.9.4) as default:
# if no default is set, "node" will not be found after a terminal restart
nvm alias default v6.9.4
# or more generic
nvm alias default node # uses latest version locally available

# finally, check:
node --version
npm --version

Info: global installierte Tools (wie z.B. Grunt) müssen für jede mit NVM installierte Node-Version installiert werden.

Updates

# migrate global packages while installing
nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION

# delete old Node (optional)
nvm uninstall OLD_VERSION

Globale Module

Der Vollständigkeit halber: ich nutze i.d. Regel diese Module global:

# gulp
npm install -g gulp

# nodemon
npm install -g nodemon