Last active
November 28, 2024 20:35
-
Star
(146)
You must be signed in to star a gist -
Fork
(43)
You must be signed in to fork a gist
-
-
Save blacktm/8302741 to your computer and use it in GitHub Desktop.
A Bash script to install Ruby on the Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -------------------------------------------------------------------------------------------- | |
# Installs Ruby 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) | |
# -------------------------------------------------------------------------------------------- | |
# Set the Ruby version you want to install | |
RUBY_VERSION=3.3.0 | |
# Welcome message | |
echo -e " | |
This will install Ruby 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 libgdbm6 libgdbm-dev libdb-dev | |
# Install Ruby, don't generate RDoc to save lots of time | |
CONFIGURE_OPTS="--disable-install-doc --enable-shared" rbenv install $RUBY_VERSION --verbose | |
# Set Ruby as the global default | |
rbenv global $RUBY_VERSION | |
# 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" |
I have the following warning messages :
install_ruby_rpi.sh: 19: install_ruby_rpi.sh: [[: not found
- The installation stopped and it says :
Installed ruby-2.6.3 to /home/pi/.rbenv/versions/2.6.3
~
-e
Reload the current shell to get access to rbenv using:
source ~/.bashrc
install_ruby_rpi.sh: 66: install_ruby_rpi.sh: arithmetic expression: expecting primary: " - "`
Thanks a million @blacktm for creating this bash script. Ruby 2.6 downloaded for me in 22 minutes. No stress. :-)
Wonderful script. Thank you again for posting.
Hey @blacktm! First of all amazing work. This is a solid script. But I'm having an issue getting it to work on a Raspberry Pi 4 running Raspbian Buster 2020-2-13 version. Everything gets installed correctly, but when I try to invoke Rails s (or sidekiq or any gem) I get a massive error 1000+ lines long that ends with "You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome."
Any ideas?
Calculate total time compilation.
total_time() {
local T=$1
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
printf '\nFinished in '
[[ $H -gt 0 ]] && printf '%d hours ' $H
[[ $M -gt 0 ]] && printf '%d minutes ' $M
[[ $D -gt 0 || $H -gt 0 || $M -gt 0 ]] && printf 'and '
printf '%d seconds\n' $S
}
total_time $SECONDS
tnk u
SET RUBY VIA ARGV OR FALLBACK TO DEFAULT
Set the default Ruby version
DEFAULT_RUBY_VERSION=3.3.0
Set the Ruby version from command-line argument or fallback to default
RUBY_VERSION=${1:-$DEFAULT_RUBY_VERSION}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't care how long it takes as long as it worked. I bet he took his precious time writing this wonderful script. Thank you so much for your contribution. I wish I could write a script like you.