Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A Bash script to install Ruby 2.5 on the Raspberry Pi (Raspbian)
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby 2.5 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.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) " 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.5, 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"
@andrewhavens

This comment has been minimized.

Show comment Hide comment
@andrewhavens

andrewhavens Jan 7, 2014

๐Ÿ‘

๐Ÿ‘

@MtnBiker

This comment has been minimized.

Show comment Hide comment
@MtnBiker

MtnBiker Nov 7, 2014

Thanks for this. Wish I'd seen it earlier as I was having a problem installing. I think my install is taking more than two hours. But can watch the log to make sure it's still progressing.

MtnBiker commented Nov 7, 2014

Thanks for this. Wish I'd seen it earlier as I was having a problem installing. I think my install is taking more than two hours. But can watch the log to make sure it's still progressing.

@ceboxsell

This comment has been minimized.

Show comment Hide comment
@ceboxsell

ceboxsell Feb 11, 2015

Pi 2, 22 min 14 sec

Pi 2, 22 min 14 sec

@elsurudo

This comment has been minimized.

Show comment Hide comment
@elsurudo

elsurudo Mar 1, 2015

I've tried this multiple times, and it gets quite far in. However, at the "Parsing sources", stage, CPU usage goes through the roof, and the RPi eventually just reboots itself, and the installation doesn't finish.

Last few lines of log:

3% [33/967]  ChangeLog
  3% [34/967]  NEWS
  3% [35/967]  README.EXT
  3% [36/967]  README.EXT.ja
  3% [37/967]  addr2line.c
  3% [38/967]  array.c
  4% [39/967]  bignum.c
  4% [40/967]  class.c
  4% [41/967]  compar.c
  4% [42/967]  compile.c
  4% [43/967]  complex.c
  4% [44/967]  cont.c
  4% [45/967]  debug.c
  4% [46/967]  dir.c
  4% [47/967]  dln.c
  4% [48/967]  dln_find.c
  5% [49/967]  dmydln.c
  5% [50/967]  dmyenc.c
  5% [51/967]  dmyext.c
  5% [52/967]  doc/ChangeLog-1.8.0
  5% [53/967]  doc/ChangeLog-1.9.3
  5% [54/967]  doc/ChangeLog-2.0.0

Any ideas? I've tried three times now, and it always stops at the exact same point.

elsurudo commented Mar 1, 2015

I've tried this multiple times, and it gets quite far in. However, at the "Parsing sources", stage, CPU usage goes through the roof, and the RPi eventually just reboots itself, and the installation doesn't finish.

Last few lines of log:

3% [33/967]  ChangeLog
  3% [34/967]  NEWS
  3% [35/967]  README.EXT
  3% [36/967]  README.EXT.ja
  3% [37/967]  addr2line.c
  3% [38/967]  array.c
  4% [39/967]  bignum.c
  4% [40/967]  class.c
  4% [41/967]  compar.c
  4% [42/967]  compile.c
  4% [43/967]  complex.c
  4% [44/967]  cont.c
  4% [45/967]  debug.c
  4% [46/967]  dir.c
  4% [47/967]  dln.c
  4% [48/967]  dln_find.c
  5% [49/967]  dmydln.c
  5% [50/967]  dmyenc.c
  5% [51/967]  dmyext.c
  5% [52/967]  doc/ChangeLog-1.8.0
  5% [53/967]  doc/ChangeLog-1.9.3
  5% [54/967]  doc/ChangeLog-2.0.0

Any ideas? I've tried three times now, and it always stops at the exact same point.

@jackregnart

This comment has been minimized.

Show comment Hide comment
@jackregnart

jackregnart Mar 12, 2015

--disable-install-doc This seems to be a good trick... I'm at 306 minutes so far. Yesterday's attempt with a really bad SD card was at 580+ minutes before I went to bed and it failed sometime overnight... A good SD card is key too it seems - using my GoPro's class 10 now.

I think I am going to be getting into the habit of doing this now so ruby doesn't build docs if it doesn't need to - sstephenson/rbenv-vars#18 (comment)

--disable-install-doc This seems to be a good trick... I'm at 306 minutes so far. Yesterday's attempt with a really bad SD card was at 580+ minutes before I went to bed and it failed sometime overnight... A good SD card is key too it seems - using my GoPro's class 10 now.

I think I am going to be getting into the habit of doing this now so ruby doesn't build docs if it doesn't need to - sstephenson/rbenv-vars#18 (comment)

@the911s

This comment has been minimized.

Show comment Hide comment
@the911s

the911s Apr 19, 2015

๐Ÿ‘

the911s commented Apr 19, 2015

๐Ÿ‘

@luketlancaster

This comment has been minimized.

Show comment Hide comment
@luketlancaster

luketlancaster Apr 28, 2015

๐Ÿ‘ 1 hr, 55 min, 29 seconds. Thanks for the gist, worked like a dream

๐Ÿ‘ 1 hr, 55 min, 29 seconds. Thanks for the gist, worked like a dream

@facastagnini

This comment has been minimized.

Show comment Hide comment
@facastagnini

facastagnini Apr 28, 2015

Why to take all that work when you can simply do:

  cd /usr/src/
  wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
  tar -xvzf ruby-2.2.2.tar.gz
  cd ruby-2.2.2
  ./configure --enable-shared --disable-install-doc --disable-install-rdoc --disable-install-capi
  make install

Reference: https://github.com/facastagnini/raspberry-bitcoin/blob/master/bootstrap.sh

Why to take all that work when you can simply do:

  cd /usr/src/
  wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
  tar -xvzf ruby-2.2.2.tar.gz
  cd ruby-2.2.2
  ./configure --enable-shared --disable-install-doc --disable-install-rdoc --disable-install-capi
  make install

Reference: https://github.com/facastagnini/raspberry-bitcoin/blob/master/bootstrap.sh

@Donavan

This comment has been minimized.

Show comment Hide comment
@Donavan

Donavan Jun 27, 2015

@blacktm you should really add "--enable-shared" to the configure opts.
@facastagnini what you posted doesn't install of the dependencies not rbenv

Donavan commented Jun 27, 2015

@blacktm you should really add "--enable-shared" to the configure opts.
@facastagnini what you posted doesn't install of the dependencies not rbenv

@delneet

This comment has been minimized.

Show comment Hide comment
@delneet

delneet Oct 30, 2015

๐Ÿ‘

delneet commented Oct 30, 2015

๐Ÿ‘

@causztic

This comment has been minimized.

Show comment Hide comment
@causztic

causztic Jan 30, 2016

thanks for this!

thanks for this!

@LimeBlast

This comment has been minimized.

Show comment Hide comment
@LimeBlast

LimeBlast Feb 5, 2016

This is excellent, thank you. It took about 35 minutes on my rPi 2.

It didn't load rbenv for the current shell, but re-launching terminal fixed that right up.

This is excellent, thank you. It took about 35 minutes on my rPi 2.

It didn't load rbenv for the current shell, but re-launching terminal fixed that right up.

@daz

This comment has been minimized.

Show comment Hide comment
@daz

daz Mar 31, 2016

16 minutes on RPI 3

daz commented Mar 31, 2016

16 minutes on RPI 3

@medright

This comment has been minimized.

Show comment Hide comment
@medright

medright Aug 4, 2016

Thanks! Just got done running on my second pi, 19min 9sec on this one, 33min on the other, this was very smooth.

medright commented Aug 4, 2016

Thanks! Just got done running on my second pi, 19min 9sec on this one, 33min on the other, this was very smooth.

@davecozz

This comment has been minimized.

Show comment Hide comment
@davecozz

davecozz Sep 9, 2016

Great script, thanks. One suggestion: make sure git is installed before running git commands.
sudo apt-get update && sudo apt-get install -y git-core

Other than that it worked great on my Rpi 3
Finished in 0 hr, 15 min, and 56 sec

davecozz commented Sep 9, 2016

Great script, thanks. One suggestion: make sure git is installed before running git commands.
sudo apt-get update && sudo apt-get install -y git-core

Other than that it worked great on my Rpi 3
Finished in 0 hr, 15 min, and 56 sec

@MitchDresdner

This comment has been minimized.

Show comment Hide comment
@MitchDresdner

MitchDresdner Oct 13, 2016

Worked great for getting Ruby running on my Pi3

But ...

I had to come here to get rails working:

http://railsapps.github.io/installrubyonrails-ubuntu.html

Worked great for getting Ruby running on my Pi3

But ...

I had to come here to get rails working:

http://railsapps.github.io/installrubyonrails-ubuntu.html

@roberthchan

This comment has been minimized.

Show comment Hide comment
@roberthchan

roberthchan Nov 20, 2016

"Oh no! Something has gone wrong."

My Output:

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.32-v7+ #924 SMP Tue Nov 15 18:11:28 GMT 2016 armv7l GNU/Linux

pi@raspberrypi:~ $ sudo sh install_ruby_rpi.sh
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done

.....
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
install_ruby_rpi.sh: 53: install_ruby_rpi.sh: rbenv: not found
install_ruby_rpi.sh: 56: install_ruby_rpi.sh: rbenv: not found
-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: " - "

"Oh no! Something has gone wrong."

My Output:

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.32-v7+ #924 SMP Tue Nov 15 18:11:28 GMT 2016 armv7l GNU/Linux

pi@raspberrypi:~ $ sudo sh install_ruby_rpi.sh
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done

.....
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
install_ruby_rpi.sh: 53: install_ruby_rpi.sh: rbenv: not found
install_ruby_rpi.sh: 56: install_ruby_rpi.sh: rbenv: not found
-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: " - "

@roberthchan

This comment has been minimized.

Show comment Hide comment
@roberthchan

roberthchan Nov 20, 2016

Note:

pi@raspberrypi: sudo apt-get install ruby-full

pi@raspberrypi:~ $ ruby -v
ruby 2.1.5p273 (2014-11-13) [arm-linux-gnueabihf]
๐Ÿค˜
Source: Openshift

Note:

pi@raspberrypi: sudo apt-get install ruby-full

pi@raspberrypi:~ $ ruby -v
ruby 2.1.5p273 (2014-11-13) [arm-linux-gnueabihf]
๐Ÿค˜
Source: Openshift

@ministryman

This comment has been minimized.

Show comment Hide comment
@ministryman

ministryman Apr 4, 2017

@robertthcan: It's too late, but I ran into the same problem (after trying to install ruby and upgrading it to 2.4, and borking my system)

sudo apt-get install rbenv curl

I added curl just in case. The error output showed that the script could not find rbenv. I assumed it wasn't installed for some reason, so I did it.

Then Re run the script.

@robertthcan: It's too late, but I ran into the same problem (after trying to install ruby and upgrading it to 2.4, and borking my system)

sudo apt-get install rbenv curl

I added curl just in case. The error output showed that the script could not find rbenv. I assumed it wasn't installed for some reason, so I did it.

Then Re run the script.

@sirsnowy7

This comment has been minimized.

Show comment Hide comment
@sirsnowy7

sirsnowy7 Jun 10, 2017

took 44 minutes on a RPi 3B but helped a lot!! thanks

took 44 minutes on a RPi 3B but helped a lot!! thanks

@wheelertom

This comment has been minimized.

Show comment Hide comment
@wheelertom

wheelertom Aug 5, 2017

Great gist! Thanks!
Raspberry Pi Zero W:
Finished in 1 hr, 26 min, and 24 sec

wheelertom commented Aug 5, 2017

Great gist! Thanks!
Raspberry Pi Zero W:
Finished in 1 hr, 26 min, and 24 sec

@roosdorp

This comment has been minimized.

Show comment Hide comment
@roosdorp

roosdorp Aug 25, 2017

Thanks, very easy to install the latest version of Ruby onto my Raspberry Pi. Took 2 hr, 21 min, and 42 sec on an Model B+ with Raspbian Stretch.

Thanks, very easy to install the latest version of Ruby onto my Raspberry Pi. Took 2 hr, 21 min, and 42 sec on an Model B+ with Raspbian Stretch.

@pjha1994

This comment has been minimized.

Show comment Hide comment
@pjha1994

pjha1994 Dec 14, 2017

My version of ruby is still 2.1:

pi@raspberrypi:~ $ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [armv7l-linux-eabihf]

It installed successfully, without any errors. I had ruby installed earlier via apt-get. How do I get access tot he new version to work? Do I need to add some path?

My version of ruby is still 2.1:

pi@raspberrypi:~ $ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [armv7l-linux-eabihf]

It installed successfully, without any errors. I had ruby installed earlier via apt-get. How do I get access tot he new version to work? Do I need to add some path?

@DeafScribe

This comment has been minimized.

Show comment Hide comment
@DeafScribe

DeafScribe Dec 31, 2017

Pi3, 35 minutes and 28 seconds. My setup reported version 2.1 immediately after the install, but reports 2.5.0 after a reboot. Thank you, sir!

Pi3, 35 minutes and 28 seconds. My setup reported version 2.1 immediately after the install, but reports 2.5.0 after a reboot. Thank you, sir!

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