Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 105 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: https://gist.github.com/blacktm/8302741
# --------------------------------------------------------------------------
# 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"
exit
fi
echo
# Time the install process
START_TIME=$SECONDS
if [[ -d ~/.rbenv ]]; then
# Check out rbenv into ~/.rbenv
echo -e "Installing rbenv from source 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
else
echo -e "Skipping (rbenv already installed)..."
fi
# 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.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
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"
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)..."
else
echo ">>> mkdir -p ./vendor/repos"
echo ">>> git clone https://github.com/codenamev/rpi_gpio.git ./vendor/repos/rpi_gpio"
mkdir -p ./vendor/repos
git clone https://github.com/codenamev/rpi_gpio.git ./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 -
fi
echo "Installing required gem dependencies..."
echo ">>> bundle install"
bundle install
You can’t perform that action at this time.