Skip to content

Instantly share code, notes, and snippets.

@dennisverspuij
Created September 14, 2018 09:10
Show Gist options
  • Save dennisverspuij/53676dd2288c5c8c0cd1b13bfa7a8b81 to your computer and use it in GitHub Desktop.
Save dennisverspuij/53676dd2288c5c8c0cd1b13bfa7a8b81 to your computer and use it in GitHub Desktop.
Bash profile script for seamless installation, loading and execution of nvm (Node Version Manager) at once. Supports custom NVM_DIR, --no-use, nvm unload, etcetera. Install as /etc/profile.d/nvm.sh to make available globally on your Unix system.
function _nvm {
local DO_RUN=yes
unalias nvm
if [ "`type -t nvm`" != "function" ] ; then
NVM_DIR="${NVM_DIR:-${ORIG_NVM_DIR:-$HOME/.nvm}}"
ORIG_NVM_DIR="$NVM_DIR"
if [ ! -d "$NVM_DIR" ] ; then
mkdir "$NVM_DIR"
TMPPROFILE="${NVM_DIR}.tmp"
touch "$TMPPROFILE"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh |\
NVM_DIR="$NVM_DIR" PROFILE="$TMPPROFILE" bash
/bin/rm -f "$TMPPROFILE"
unset TMPPROFILE
fi
source "$NVM_DIR/nvm.sh" "$@"
[ "$1" = "--no-use" ] && shift
[ $# -eq 0 ] && DO_RUN=no
fi
[ "$DO_RUN" = "yes" ] && nvm "$@"
alias nvm='_nvm'
}
alias nvm='_nvm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment