Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
executable file 104 lines (81 sloc) 3.2 KB
#!/usr/bin/env bash
# --------------------------------------------------------------------------
# Installs Ruby 2.5 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
# Thanks to @blacktm:
# --------------------------------------------------------------------------
# Welcome message
echo -e "
This will install Ruby 2.5 using rbenv/ruby-build.
It will take about 2 hours to compile on the original Raspberry Pi,
35 minutes on the second generation, and 16 minutes on the third.\n"
# Prompt to continue
read -p " Continue? (y/n) " answer
if [[ $answer != "y" ]]; then
echo -e "\nQuitting...\n"
# Time the install process
if [[ -d ~/.rbenv ]]; then
# Check out rbenv into ~/.rbenv
echo -e "Installing rbenv from source 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 -)"
# Save to ~/.bashrc
echo -e "\n${String}" >> ~/.bashrc
# Enable rbenv for current shell
eval "${String}"
# Install ruby-build as an rbenv plugin, adds `rbenv install` command
git clone ~/.rbenv/plugins/ruby-build
echo -e "Skipping (rbenv already installed)..."
# Install dependencies
# See:
sudo apt update
sudo apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
# Install Ruby 2.5.1, don't generate RDoc to save lots of time
CONFIGURE_OPTS="--disable-install-doc --enable-shared" rbenv install 2.5.1 --verbose
# Set Ruby 2.5 as the global default
rbenv global 2.5.1
# Don't install docs for gems (saves lots of time)
echo "gem: --no-document" > ~/.gemrc
# Reminder to reload the shell
echo -e "\nReload the current shell to get access to rbenv using:"
echo " source ~/.bashrc"
# Print the time elapsed
echo -e "\nFinished in $(($ELAPSED_TIME/60/60)) hr, $(($ELAPSED_TIME/60%60)) min, and $(($ELAPSED_TIME%60)) sec\n"
echo "Installing the 'rake' gem..."
echo ">>> gem install rake"
sudo gem install rake --no-rdoc --no-ri
echo "Updating system gems"
echo ">>> sudo gem update --system"
sudo gem update --system --no-rdoc --no-ri
echo "Installing the 'bundler' gem..."
echo ">>> gem install bundler"
sudo gem install bundler --no-rdoc --no-ri
echo "Downloading forked gems to get all examples working..."
if [[ -d ./vendor/repos/rpi_gpio ]]; then
echo "Skipping (already cloned)..."
echo ">>> mkdir -p ./vendor/repos"
echo ">>> git clone ./vendor/repos/rpi_gpio"
mkdir -p ./vendor/repos
git clone ./vendor/repos/rpi_gpio
echo "Compiling forked repos with native extensions"
echo ">>> cd vendor/repos/rpi_gpio && bundle install && bundle exec rake compile"
cd vendor/repos/rpi_gpio && bundle install && bundle exec rake compile
echo ">>> cd - "
cd -
echo "Installing required gem dependencies..."
echo ">>> bundle install"
bundle install