Skip to content

Instantly share code, notes, and snippets.

@omerlh
Created October 26, 2017 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerlh/cfe6394754788b2b0b9f836c6c238be7 to your computer and use it in GitHub Desktop.
Save omerlh/cfe6394754788b2b0b9f836c6c238be7 to your computer and use it in GitHub Desktop.
Use this script in Dockerfile to install specific ruby version
#!/bin/bash
# Source: oficial ruby docker image
set -ex
mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
buildDeps=' \
bison \
dpkg-dev \
libgdbm-dev \
ruby \
' \
apt-get update
apt-get install -y --no-install-recommends $buildDeps
rm -rf /var/lib/apt/lists/*
wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz"
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum -c -
mkdir -p /usr/src/ruby
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1
rm ruby.tar.xz
cd /usr/src/ruby
# hack in "ENABLE_PATH_CHECK" disabling to suppress:
# warning: Insecure world writable dir
{ \
echo '#define ENABLE_PATH_CHECK 0'; \
echo; \
cat file.c; \
} > file.c.new
mv file.c.new file.c
autoconf
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
./configure \
--build="$gnuArch" \
--disable-install-doc \
--enable-shared
make -j "$(nproc)"
make install
apt-get purge -y --auto-remove $buildDeps
cd /
rm -r /usr/src/ruby
gem update --system "$RUBYGEMS_VERSION"
gem install bundler --version "$BUNDLER_VERSION"
@omerlh
Copy link
Author

omerlh commented Oct 26, 2017

To use the script you need to set the following environment variables:

ENV RUBY_MAJOR 2.4
ENV RUBY_VERSION 2.4.2
ENV RUBY_DOWNLOAD_SHA256 748a8980d30141bd1a4124e11745bb105b436fb1890826e0d2b9ea31af27f735
ENV RUBYGEMS_VERSION 2.6.14
ENV BUNDLER_VERSION 1.15.4

Checkout the official ruby image, or this repo for a sample usage.

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