Can't deploy with Ruby 3.1.2

My Netlify site is quiet-custard-3a5bea. I just upgraded from Ruby 2.7.2 to 3.1.2, and now my deploys aren’t working because the ruby binary isn’t being found.

The build log is:

1:53:18 PM: Build ready to start
1:53:19 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
1:53:19 PM: build-image tag: v4.8.0
1:53:19 PM: buildbot version: 5271e9715084f43bb9084ec0da517d4a5a908ada
1:53:20 PM: Fetching cached dependencies
1:53:20 PM: Starting to download cache of 394.5MB
1:53:24 PM: Finished downloading cache in 4.499486575s
1:53:24 PM: Starting to extract cache
1:53:32 PM: Finished extracting cache in 7.778835692s
1:53:32 PM: Finished fetching cache in 12.331198536s
1:53:32 PM: Starting to prepare the repo for build
1:53:32 PM: Preparing Git Reference refs/heads/main
1:53:35 PM: Parsing package.json dependencies
1:53:37 PM: Starting build script
1:53:37 PM: Installing dependencies
1:53:37 PM: Python version set to 2.7
1:53:37 PM: Started restoring cached node version
1:53:38 PM: Finished restoring cached node version
1:53:39 PM: v16.15.0 is already installed.
1:53:40 PM: Now using node v16.15.0 (npm v8.5.5)
1:53:40 PM: Started restoring cached build plugins
1:53:40 PM: Finished restoring cached build plugins
1:53:40 PM: Required ruby-3.1.2 is not installed.
1:53:40 PM: To install do: 'rvm install "ruby-3.1.2"'
1:53:40 PM: Attempting ruby version 3.1.2, read from .ruby-version file
1:53:40 PM: Started restoring cached ruby version
1:53:41 PM: Finished restoring cached ruby version
1:53:43 PM: Using ruby version 3.1.2
1:53:43 PM: Using bundler version 2.1.4 from Gemfile.lock
1:53:44 PM: Successfully installed bundler-2.1.4
1:53:44 PM: 1 gem installed
1:53:44 PM: Using PHP version 8.0
1:53:44 PM: Started restoring cached ruby gems
1:53:44 PM: Finished restoring cached ruby gems
1:53:44 PM: Creating deploy upload records
1:53:44 PM: Installing gem bundle
1:53:44 PM: /opt/buildhome/.rvm/gems/ruby-3.1.2/bin/bundle: 6: exec: /opt/buildhome/.rvm/gems/ruby-3.1.2/bin/ruby: not found
1:53:44 PM: Error during gem install
1:53:44 PM: Build was terminated: Build script returned non-zero exit code: 1
1:53:44 PM: Failing build: Failed to build site
1:53:45 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (
1:53:45 PM: Finished processing build request in 25.277257658s

Using Ruby 3.1.1 works fine, though.

hi there @sbleon ,

that’s interesting and a little odd.

according to our build image software list for focal (the build image you are using, ruby 3.1.2 should be fine:

is it possible that there was a syntax error or something similar in your .ruby-version file? :thinking:

according to our docs, you can set the ruby version via an env var or the file. does one or the other give different results?

I’m having the exact same issue: Netlify App

As far as I can tell, my .ruby-version file is correct: gateway/.ruby-version at redesign · gesteves/gateway · GitHub

For what it’s worth, if I hit “clear cache and retry deploy”, it works correctly, so it seems it’s related to caching somehow (unfortunately this makes deploys take longer and it’s eating into my build minutes, so it’s not a tenable long-term solution).

hi again, thanks for that info. We can absolutely forgive you some build minutes if you’d like to keep troubleshooting. let me know.

if it were related to caching, the error shouldn’t appear on a brand new site - would you mind trying either of your broken configs on a brand new site and see if those work?

Hey sorry, I finally got around to trying this on a new site. The initial deploy succeeded, but subsequent deploys fail with the same error:

9:01:27 AM: Started restoring cached ruby gems
9:01:27 AM: Creating deploy upload records
9:01:27 AM: Finished restoring cached ruby gems
9:01:27 AM: Installing gem bundle
9:01:27 AM: /opt/buildhome/.rvm/gems/ruby-3.1.2/bin/bundle: 6: exec: /opt/buildhome/.rvm/gems/ruby-3.1.2/bin/ruby: not found
9:01:27 AM: Error during gem install
9:01:27 AM: Build was terminated: Build script returned non-zero exit code: 1

hi there @gesteves ,

Thank you for that! I have filed a bug for this with the appropriate team and we will get it looked at. Until we can fix it, is 3.1.1 working for you so far?

We’ll let you know once you can try upgrading to 3.1.2 here.

Ruby 3.1.2 worked for my site until yesterday, May 11, when my daily builds started failing with this exact error message. It works if I build while clearing cache, but fails if I build without clearing cache.

Downgrading to Ruby 3.1.1 resolves the problem, and cached builds start working again. This is very annoying. :frowning:

Downgrading to ruby 3.1.1 on Ubuntu 16.04 fixed it for me.

Also upgrading to Ubuntu 20.04 allowed me to use ruby 3.1.2.

Unfortunately, for me even Ubuntu 20.04 only works the first time with Ruby 3.1.2, and building the same commit again without clearing the cache fails.

Hey all, we’ve filed an issue for investigation and would keep you all updated about the progress.