Skip to content

Instantly share code, notes, and snippets.

@thibmaek
Last active June 22, 2017 22:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thibmaek/45243bec27f8cb05b9c7 to your computer and use it in GitHub Desktop.
Save thibmaek/45243bec27f8cb05b9c7 to your computer and use it in GitHub Desktop.
Update node with nvm, migrating global modules
# Usage: nvmi v6.0.1 (will install specified version)
# Usage: nvmi_latest (will install latest node version)
# these functions will replace the current 'default' version known in the shell.
# to install a node version next to your current 'default' just use nvm install vX.X.X
function nvmi() {
CURRENT=$(node -v)
nvm install $1 --reinstall-packages-from=$CURRENT
nvm alias default $1
nvm uninstall $CURRENT
}
function nvmi_latest() {
CURRENT=$(node -v)
LATEST=$(nvm ls-remote | tail -1 | grep -E -o '.{0,0}v.{0,6}' | tr -d '\n')
nvm install $LATEST --reinstall-packages-from=$CURRENT
nvm alias default $LATEST
nvm uninstall $CURRENT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment