Skip to content

Instantly share code, notes, and snippets.

@robbwagoner
Created September 15, 2016 16:45
Show Gist options
  • Save robbwagoner/e633bf9dc57fa7b6609a71c320cbae82 to your computer and use it in GitHub Desktop.
Save robbwagoner/e633bf9dc57fa7b6609a71c320cbae82 to your computer and use it in GitHub Desktop.
NVM Bootstrap for OSX and Ubuntu Linux
#!/usr/bin/env bash
#
# https://github.com/creationix/nvm
#
DIR="$(cd $(dirname $0) ; pwd)"
# Error codes
ERROR_NVM_INSTALL_SHA=2
# Installer script from NVM repo
NVM_INSTALL_VERSION="v0.31.7"
NVM_INSTALL_URL="https://raw.githubusercontent.com/creationix/nvm/${NVM_INSTALL_VERSION}/install.sh"
NVM_INSTALL_SHA256="04a98a895859e6fd86219cfdd8fcc532981f7ce33089feb44e47fcaddd0d985c"
echo "Node Version Manager"
case $(uname -s) in
( Darwin )
;;
( Linux )
TMPDIR=/tmp
;;
esac
# Install NVM
function install_nvm() {
if ! [ -f $HOME/.nvm/nvm.sh ] ; then
echo "NVM: nvm is not installed."
echo "NVM: installing..."
NVM_INSTALL="$TMPDIR/nvm-${NVM_INSTALL_VERSION}-install.sh"
printf "${NVM_INSTALL_SHA256} $(basename ${NVM_INSTALL})\n" > ${NVM_INSTALL}.sha256
curl -o $TMPDIR/nvm-${NVM_INSTALL_VERSION}-install.sh ${NVM_INSTALL_URL}
if cd $TMPDIR && shasum -t -a 256 -c ${NVM_INSTALL}.sha256 --status ; then
bash ${NVM_INSTALL}
else
echo "NVM ERROR: SHA-256 sum of NVM install script failed." 1>&2
return ${ERROR_NVM_INSTALL_SHASUM}
fi
fi
}
install_nvm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment