Running Rails 7 with YJIT in Heroku Bash

Created at: 01 May 2024 Last updated: 01 May 2024

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 works locally with this shebang which goes at the top of bin/rails:
#!/usr/bin/env ruby --yjit

It was recommended here:

But, this doesn't work when running bash on Heroku dynos, even with --yjit enabled via options.

But this does:

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

Why? See the attached CoPilot chat and this StackExchange thread:
This is a crosspost with X, to read the post on that platform click here.