Skip to content

Instantly share code, notes, and snippets.

@snarlysodboxer
Last active December 18, 2015 04:18
Show Gist options
  • Save snarlysodboxer/5724256 to your computer and use it in GitHub Desktop.
Save snarlysodboxer/5724256 to your computer and use it in GitHub Desktop.
Install rbenv, rbenv-build, and ruby idempotently for use in bash.Works for Ubuntu and Mac.
#!/bin/bash
if test -f $HOME/.profile
then
PROFILE_FILE="$HOME/.profile"
elif test -f $HOME/.bash_profile
then
PROFILE_FILE="$HOME/.bash_profile"
else
echo "Creating a new .bash_profile file."
touch $HOME/.bash_profile
PROFILE_FILE="$HOME/.bash_profile"
fi
if ! test -d $HOME/.rbenv
then
git clone git://github.com/sstephenson/rbenv.git $HOME/.rbenv
fi
if ! grep -q "export PATH=\"\$HOME/.rbenv/bin:\$PATH\"" $PROFILE_FILE
then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $PROFILE_FILE
fi
if ! grep -q "eval \"\$(rbenv init -)\"" $PROFILE_FILE
then
echo 'eval "$(rbenv init -)"' >> $PROFILE_FILE
fi
#exec $SHELL -l
#source $PROFILE_FILE
. $PROFILE_FILE
if ! test -d $HOME/.rbenv/plugins/ruby-build
then
git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build
fi
VERSION=
until rbenv install -l | grep -q -x " $VERSION"
do
echo "Which version of ruby would you like to install? (example: '1.9.3-p429'): "
read VERSION
if ! rbenv install -l | grep -q -x " $VERSION"
then
echo "Version not found! Please try again."
sleep 1
rbenv install -l
fi
done
if ! rbenv versions | grep -q $VERSION
then
rbenv install $VERSION
rbenv rehash
else
echo "This version is already installed!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment