Skip to content

Instantly share code, notes, and snippets.

@gmmoreira
Last active November 1, 2022 15:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gmmoreira/60a5c4f981dcc4fa79034cb93700f3c1 to your computer and use it in GitHub Desktop.
Save gmmoreira/60a5c4f981dcc4fa79034cb93700f3c1 to your computer and use it in GitHub Desktop.
Install Ruby 2.2.x, 2.3.x in Ubuntu 20.04
#!/bin/bash
set -e
# Usage
# ./install.sh # defaults to 2.3.8
# ./install.sh 2.3.3
# Explanation
# Ruby 2.3 or lower only support OpenSSL 1.0.
# Up to Ubuntu 18.04 there were debian packages libssl-dev and libssl1.0-dev.
# libssl1.0-dev provides the necessary libraries and headers to build these old Ruby versions
# In Ubuntu 20.04, the libssl1.0-dev has been removed from the repositories.
# This script just automates the process of downloading openssl 1.0 tarball,
# building it and installing Ruby with the necessary flags.
# A local ssl dir is installed during build of openssl and a symlink is made for the certs dir,
# otherwise SSL connections would not work.
openssl_version="openssl-1.0.2u"
ruby_version="${1:-2.3.8}"
openssl_package="$openssl_version.tar.gz"
openssl_prefix="/tmp/openssl"
openssl_dir="$HOME/.local/ssl"
openssl_download_url="https://ftp.openssl.org/source/old/1.0.2/$openssl_package"
openssl_package_path="/tmp/$openssl_package"
local_certs_path="$openssl_dir/certs"
system_certs_path="/etc/ssl/certs"
if [ ! -d "$openssl_prefix" ]; then
if [ ! -f "$openssl_package_path" ]; then
curl -o "$openssl_package_path" "$openssl_download_url"
fi
tar -C "/tmp" -xzf "$openssl_package_path"
pushd "/tmp/$openssl_version"
./config --prefix="$openssl_prefix" --openssldir="$openssl_dir" shared
make -j "$(nproc)"
make install
popd
rm -rf "$local_certs_path"
ln -s "$system_certs_path" "$local_certs_path"
fi
RUBY_CONFIGURE_OPTS="$RUBY_CONFIGURE_OPTS --with-openssl-dir=$openssl_prefix" \
rbenv install -k "$ruby_version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment