Skip to content

Instantly share code, notes, and snippets.

@deiga
Created March 27, 2017 15:30
Show Gist options
  • Save deiga/0087c0b7c5b9dc59a9120e29479f058c to your computer and use it in GitHub Desktop.
Save deiga/0087c0b7c5b9dc59a9120e29479f058c to your computer and use it in GitHub Desktop.
Node installation script with bash
function install_node() {
local REQUIRED_MAJOR_NODE_VERSION=${REQUIRED_NODEJS_VERSION:0:1}
echo "${BLUE}Which version manager do you want to install node.js with? If you don't know, choose 'brew'${NORMAL}:"
select NODE_VERSION_MANAGER in 'brew' 'nvm' 'nodenv' 'other';
do
case $NODE_VERSION_MANAGER in
'nvm'|'nodenv')
verify_command $NODE_VERSION_MANAGER
set +x
$NODE_VERSION_MANAGER install $REQUIRED_MAJOR_NODE_VERSION
set -x
break
;;
'other')
read -p "${BLUE}Please write the command of your node version manager: ${NORMAL}" -r
local OTHER=$REPLY
if ! command -v "$OTHER"; then
echo "${RED}$OTHER does not exist.$NORMAL" >&2
install_node_homebrew
else
${OTHER} install $REQUIRED_MAJOR_NODE_VERSION
fi
break
;;
'brew'|*)
install_node_homebrew
break
;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment