Skip to content

Instantly share code, notes, and snippets.

@inre
Forked from blacktm/install_ruby_rpi.sh
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inre/be512d3c6be9c2b43774 to your computer and use it in GitHub Desktop.
Save inre/be512d3c6be9c2b43774 to your computer and use it in GitHub Desktop.
#!/bin/bash
# -----------------------------------------------------------------------
# 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
bold="\033[1m"
normal="\033[0m"
# 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"
exit
fi
echo
# Time the install process
START_TIME=$SECONDS
# Check out rbenv into ~/.rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# Add ~/.rbenv/bin to $PATH, enable shims and autocompletion
read -d '' String <<"EOF"
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
EOF
# 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 https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# Install dependencies
# See: https://github.com/sstephenson/ruby-build/wiki#suggested-build-environment
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
ELAPSED_TIME=$(($SECONDS - $START_TIME))
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