I’ve been down the rabbit hole of Ruby installations more times than I care to admit. When I first tried to install Ruby 1.9.3 via RVM on Ubuntu, I hit this brick wall:
$ rvm install 1.9.3
Searching for binary rubies, this might take some time.
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system..................................................................................................
Error running 'requirements_debian_update_system ruby-1.9.3-p448',
please read /home/troy/.rvm/log/1379872584_ruby-1.9.3-p448/update_system.log
Requirements installation failed with status: 100.
I know that staring at “status: 100” in your terminal can feel like a dead end. I’ll walk you through how I turned that failure into a reproducible, robust installation script complete with error handling, clear logs, and extra practice steps so you can level up your Bash and RVM skills.
Why Automate Ruby Installation?
Manually typing commands each time is error-prone. A script lets me:
- Capture errors immediately and log details.
- Retry flaky operations without starting over.
- Share a reproducible recipe across projects and teammates.
Ready? Let’s dive in.
The Installation Script
Create a file install_ruby.sh
in your home directory, then make it executable:
chmod +x ~/install_ruby.sh
Paste this content into it:
#!/usr/bin/env bash
# install_ruby.sh
# A simple wrapper to install Ruby via RVM with error detection
RUBY_VERSION="1.9.3"
LOGFILE="$HOME/rvm_install_$(date +%Y%m%d_%H%M%S).log"
echo "Starting Ruby $RUBY_VERSION installation at $(date)" | tee "$LOGFILE"
# 1. Update and install system requirements
echo "Step 1: Installing prerequisites…" | tee -a "$LOGFILE"
if sudo apt-get update && \
sudo apt-get install -y curl gnupg build-essential \
libssl-dev libreadline-dev zlib1g-dev; then
echo "✔ Prerequisites installed" | tee -a "$LOGFILE"
else
echo "✖ Failed to install prerequisites" | tee -a "$LOGFILE"
exit 1
fi
# 2. Import RVM GPG keys
echo "Step 2: Importing RVM GPG keys…" | tee -a "$LOGFILE"
command -v gpg >/dev/null || sudo apt-get install -y gnupg2
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys \
409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
&>> "$LOGFILE" || { echo "✖ GPG import failed" | tee -a "$LOGFILE"; exit 2; }
# 3. Install or reload RVM
echo "Step 3: Installing/reloading RVM…" | tee -a "$LOGFILE"
if ! command -v rvm >/dev/null; then
\curl -sSL https://get.rvm.io | bash -s stable &>> "$LOGFILE"
source "$HOME/.rvm/scripts/rvm"
else
echo "✔ RVM already installed" | tee -a "$LOGFILE"
source "$HOME/.rvm/scripts/rvm"
fi
# 4. Install Ruby
echo "Step 4: Installing Ruby $RUBY_VERSION…" | tee -a "$LOGFILE"
if rvm install "$RUBY_VERSION" &>> "$LOGFILE"; then
echo "✔ Ruby installed successfully" | tee -a "$LOGFILE"
else
code=$?
echo "✖ Ruby install failed with status $code" | tee -a "$LOGFILE"
echo "Check logs: $LOGFILE and ~/.rvm/log/" | tee -a "$LOGFILE"
exit $code
fi
# 5. Set default Ruby and verify
echo "Step 5: Setting default Ruby…" | tee -a "$LOGFILE"
rvm --default use "$RUBY_VERSION" &>> "$LOGFILE"
ruby -v | tee -a "$LOGFILE"
echo "Installation completed at $(date)" | tee -a "$LOGFILE"
Save and run:
~/install_ruby.sh
What “status: 100” Really Means
Whenever RVM exits with 100, it usually signals that dependency installation failed during the requirements_debian_update_system
phase. In plain terms, apt-get install
hit a snag—missing packages, network hiccups, or a locked dpkg database. The detailed reason lives in:
~/.rvm/log/<timestamp>/update_system.log
Peek at that log to pinpoint the broken dependency.
How the Script Works
- Prerequisite Installation
I updateapt
and install libraries (OpenSSL, Readline, zlib) that Ruby’s C-extensions need. - GPG Key Import
RVM’s install script is signed importing its public keys ensures we trust the code we’re running. - RVM Setup
If RVM isn’t present, we bootstrap it viacurl
; otherwise, we simply reload the existing install. - Ruby Compile & Install
All output funnels into our timestamped log for later inspection. On failure, we catch the exit code and bail. - Default Ruby & Verification
We mark our new Ruby version as the default and printruby -v
so we know it worked.
Extra Practice Functions
To stretch your Bash and RVM chops, sprinkle in these helper functions:
# List all known Ruby versions
function list_rubies() {
echo "Known Ruby versions:"
rvm list known
}
# Uninstall a specific Ruby version
function uninstall_ruby() {
echo "Removing Ruby $1…"
rvm remove "$1"
}
# Create & use a project gemset
function setup_gemset() {
echo "Creating gemset '$1'…"
rvm gemset create "$1"
rvm gemset use "$1"
}
# Retry flaky commands up to 3 times
function retry() {
local attempt=1 max=3 delay=5
until "$@"; do
if (( attempt == max )); then
echo "Command failed after $attempt tries."
return 1
fi
(( attempt++ ))
echo "Retry $attempt/$max in $delay sec…"
sleep $delay
done
return 0
}
You can call, for example:
retry sudo apt-get update
to guard against transient network failures.
Final Thoughts
I used to dread that “status: 100” error. Now, every time it crops up, I let my script handle it logging the details, retrying if necessary, and pointing me straight to the root cause. Automating repetitive setups like Ruby installations frees up my brainpower for the fun parts.