Skip to content

Instantly share code, notes, and snippets.

@dannymcc
Forked from blacktm/install_ruby_rpi.sh
Created March 14, 2017 16:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannymcc/28acb7a5e51ab3658295aa961ce8fbeb to your computer and use it in GitHub Desktop.
Save dannymcc/28acb7a5e51ab3658295aa961ce8fbeb to your computer and use it in GitHub Desktop.
A Bash script to install Ruby 2.4 on the Raspberry Pi (Raspbian)
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby 2.4 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh)
# --------------------------------------------------------------------------------------------
# Welcome message
echo -e "
This will install Ruby 2.4 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) " 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/rbenv/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
# 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 https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# Install dependencies
# See: https://github.com/rbenv/ruby-build/wiki#suggested-build-environment
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.4, don't generate RDoc to save lots of time
CONFIGURE_OPTS="--disable-install-doc --enable-shared" rbenv install 2.4.0 --verbose
# Set Ruby 2.4 as the global default
rbenv global 2.4.0
# 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
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo -e "\nFinished in $(($ELAPSED_TIME/60/60)) hr, $(($ELAPSED_TIME/60%60)) min, and $(($ELAPSED_TIME%60)) sec\n"
@Cmorling
Copy link

This worked great! Very appreciated.

@al-dot-exe
Copy link

You're a life saver with this one!

@vollh4rD
Copy link

how to use this plz help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment