Skip to content

Instantly share code, notes, and snippets.

@pzol
Created December 5, 2010 08:33
Show Gist options
  • Save pzol/728943 to your computer and use it in GitHub Desktop.
Save pzol/728943 to your computer and use it in GitHub Desktop.
rvm installation under ubuntu
#!/bin/bash -l
install_path="$HOME/install"
### Verify if the executing user is the root
function is_root {
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "The installation process requires to be run as root. Consider using sudo."
false
fi
}
function is_rvm_installed {
[[ "`type rvm | head -n1`" == "rvm is a function" ]]
}
### to run ruby and native gems with extensions we need those:
function do_install {
if is_rvm_installed; then
echo "Rvm is already installed"
exit 0
else
mkdir -p $install_path
# cd $install_path
apt-get install -y libruby1.8 zlib1g-dev libssl-dev libreadline5-dev build-essential \
libxslt-dev libxml2-dev curl git-core
curl -L http://bit.ly/rvm-install-system-wide > $install_path/rvm-install-system-wide
bash -l < $install_path/rvm-install-system-wide
usermod -a -G rvm $USER
fi
}
### add the rvm script so it is run by all users and run it so it is available in the current session
function install_to_profile {
cat > $install_path/rvm.sh <<EOF
[[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm" # This loads RVM into a shell session
EOF
cp $install_path/rvm.sh /etc/profile.d/rvm.sh
chmod a+x /etc/profile.d/rvm.sh
source /usr/local/lib/rvm
}
function install_failed {
echo "Install failed :("
exit 1
}
is_root &&
do_install &&
install_to_profile &&
is_rvm_installed || install_failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment