Last active
December 18, 2015 04:18
-
-
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.
This file contains hidden or 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
#!/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