Running Rails 7 with YJIT in Heroku Bash

Created at: 01 May 2024 Last updated: 28 Jan 2025

I use this guide to install Ruby locally with Ruby's "just in time compiler", substituting for latest versions where possible:

https://dev.to/wizardhealth/install-ruby-320-with-yjit-3mmo

But what about getting yjit on Heroku?

I ran into an issue today after running commands like:
heroku run bash
Running bash on β¬’ my-app... up, run.8292 (Standard-1X) 
~ $ rails db:status 
/usr/bin/env: β€˜ruby --yjit’: No such file or directory 
/usr/bin/env: use -[v]S to pass options in shebang lines

Running Rails 7 with YJIT with this shebang that goes at the top of bin/rails works locally:
#!/usr/bin/env ruby --yjit

It was recommended here:
https://netoff.dev/blog/2023-02-01-using-rails-7-with-yjit

But, this doesn't work when running bash on Heroku dynos, even with --yjit enabled via options.
See: https://devcenter.heroku.com/articles/ruby-support#ruby-versions

But this does:

#!/usr/bin/env -S ruby --yjit

Why? See the attached CoPilot chat and this StackExchange thread: https://unix.stackexchange.com/questions/399690/multiple-arguments-in-shebang/477651#477651
This is a crosspost with X, to read the post on that platform click here.

Back