asdf
asdf is a great version manager for programming languages.
After you’ve got it installed, it’s this easy to install something:
asdf plugin add ruby
asdf install ruby latest
asdf global ruby latest
asdf local ruby latest
$ ruby -v
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]
asdf writes the versions used to a local .tool-versions
file:
$ cat .tool-versions
ruby 3.4.2
Gemfile support
Turns out, bundler
supports .tool-versions
, so you can do this:
source "https://rubygems.org"
ruby file: ".tool-versions"
Rails Dockerfile
Just be sure to add it to your Dockerfile
- assuming you’re using the default Rails Dockerfile
, that’ll look like this:
diff --git a/Dockerfile b/Dockerfile
index 1367120..5f67449 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -34,7 +34,7 @@ RUN apt-get update -qq && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install application gems
-COPY Gemfile Gemfile.lock ./
+COPY Gemfile Gemfile.lock .tool-versions ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git