Last active
June 22, 2017 22:49
-
-
Save thibmaek/45243bec27f8cb05b9c7 to your computer and use it in GitHub Desktop.
Update node with nvm, migrating global modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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