Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Bash script to install Ruby 2.2 on the Raspberry Pi (Raspbian).
# -----------------------------------------------------------------------
# Installs Ruby 2.2 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
# Run from the web:
# bash <(curl -s raw_script_url_here)
# -----------------------------------------------------------------------
# Set up variables
# Welcome message
echo -e "\n${bold}This will install Ruby 2.2 using rbenv/ruby-build."
echo -e "It can take about 2 hours to compile on the Raspberry Pi.${normal}"
# Prompt to continue
read -p " Continue? (y/n) " ans
if [[ $ans != "y" ]]; then
echo -e "\nQuitting...\n"
# Time the install process
# Check out rbenv into ~/.rbenv
git clone ~/.rbenv
# Add ~/.rbenv/bin to $PATH, enable shims and autocompletion
read -d '' String <<"EOF"
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# For new shells
echo -e "\n${String}\n" >> ~/.bashrc
# For current shell
eval "${String}"
# Install ruby-build as an rbenv plugin, adds `rbenv install` command
git clone ~/.rbenv/plugins/ruby-build
# Install dependencies
# See:
sudo apt-get update
sudo apt-get install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev
# Install Ruby 2.2, don't generate RDoc to save lots of time
CONFIGURE_OPTS="--disable-install-doc" rbenv install 2.2.2 --verbose
# Set Ruby 2.2 as the global default
rbenv global 2.2.2
# Don't install docs for gems (saves lots of time)
echo -e "gem: --no-document" > ~/.gemrc
# Print the time elapsed
echo -e "\n${bold}Finished in $(($ELAPSED_TIME/60/60)) hr, $(($ELAPSED_TIME/60%60)) min, and $(($ELAPSED_TIME%60)) sec${normal}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.