Skip to content

Instantly share code, notes, and snippets.

@2called-chaos
Last active July 2, 2017 15:33
Show Gist options
  • Save 2called-chaos/e06bf6322525d37a5bf7 to your computer and use it in GitHub Desktop.
Save 2called-chaos/e06bf6322525d37a5bf7 to your computer and use it in GitHub Desktop.
Install chruby and ruby-build onto Ubuntu
#!/bin/bash
# You can make some decisions in this file by (un)commenting parts, look through it first!
# Install:
# aptitude install -y curl \
# && curl -O https://gist.githubusercontent.com/2called-chaos/e06bf6322525d37a5bf7/raw/_setup_chruby.sh \
# && chmod u+x _setup_chruby.sh
#
# ./_setup_chruby.sh
#
# For Debian/Ubuntu you might also want to install these before building ruby:
# aptitude install wget git build-essential autoconf bison libssl-dev libyaml-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev
#
# For CentOS/RedHat you might also want to install these before building ruby:
# yum install wget git gcc gcc-c++ kernel-devel make autoconf bison openssl-devel libyaml-devel readline readline-devel zlib zlib-devel
### START CONFIG
# The version of chruby to install (check for more recent version)
VERSION="0.3.9"
# where to install ruby-build
RUBY_BUILD_PATH="/opt/ruby-build"
# where to link the ruby-build executable to? (omit bin/ruby-build)
RUBY_BUILD_PREFIX="/usr/local"
### END CONFIG
# requirements
python -mplatform | grep Ubuntu && sudo aptitude install git wget || sudo yum install git wget
# stop script of command fails
set -e
# get & install
cd /usr/local/src
wget -O chruby-$VERSION.tar.gz https://github.com/postmodern/chruby/archive/v$VERSION.tar.gz
tar -xzf chruby-$VERSION.tar.gz && rm chruby-$VERSION.tar.gz
cd chruby-$VERSION/
sudo make install
# load in every bash session
cat > /etc/profile.d/chruby.sh <<EOF
[ -n "\$BASH_VERSION" ] || [ -n "\$ZSH_VERSION" ] || return
source /usr/local/share/chruby/chruby.sh
EOF
# prepare ruby folder
mkdir -p /opt/rubies/
# get ruby-build
git clone https://github.com/sstephenson/ruby-build.git $RUBY_BUILD_PATH
cd $RUBY_BUILD_PATH
./install.sh PREFIX=$RUBY_BUILD_PREFIX
echo "Done, you can now install rubies with \`ruby-build 2.whatever /opt/rubies/2.whatever'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment