Heroku - migrating to Cedar 14 & updating ruby version - ruby-on-rails

I'm trying to migrate my heroku app to Cedar 14 (following this: https://devcenter.heroku.com/articles/cedar-14-migration)
My problem is that heroku thinks I'm using ruby v 2.1.1 (where my machine is on ruby 2.2.2. This is confirmed by ruby -v and which ruby (both return 2.2.2).
However, when I try:
heroku run ruby -v
The return is:
Running `ruby -v` attached to terminal... up, run.4550
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
I can't figure out how to get heroku to recognise that ruby 2.2.2 is what should be used. It's in my gem file, I set it as the default and its in my bash profile at the top of the list.
As a result, I can't push the migration on heroku because it's not supported by older versions of ruby. I get this error:
Only the most recent version of Ruby 2.1 is supported on Cedar-14
remote: ! Command: 'set -o pipefail; curl --fail --retry 3 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/cedar-14/ruby-2.1.1.tgz -s -o - | tar zxf - ' failed unexpectedly:
Does anyone know how to get heroku to recognise ruby v 2.2.2?
Thank you

You have the add the desired Ruby version to your Gemfile like this:
source 'https://rubygems.org'
ruby '2.2.3'
gem 'rails', '~> 4.2.4'
# ...
There is an article about Specifying a Ruby Version in their devcenter.

I had updated my ruby version in my gem file, and updated my path and set the default. I had installed all my gems, but I didn't update my gems. Gem update solved this for me.

Related

heroku run rake db:migrate fails to deploy

I'm trying to deploy my Rails6 app to Heroku
I'm able to successfully build after pushing my app to Heroku but the app immediately crashes.
I just added
group :production do
gem 'pg', '~> 1.2', '>= 1.2.3'
end
to my Gemfile after developing in sqlite so I figured I'd need to migrate which brings me to my error
peter.walker#MACSB-RJ2CLKF45C friends % heroku run rake db:migrate
Running rake db:migrate on ⬢ ptw-friends... up, run.5761 (Free)
Your Ruby version is 2.7.0, but your Gemfile specified 2.6.10
I'm not sure why I'm being told my Ruby version is 2.7.0.
My Gemfile has ruby '2.6.10',
my Gemfile.lock has RUBY VERSION ruby 2.6.10p210,
and my $ ruby -v returns ruby 2.6.10p210 (2022-04-12 revision 67958) [arm64-darwin21]
Could it be from adding
"scripts": {
"start": "rails s"
},
to my package.json?
Could I not be specifying the Ruby version in Procfile?
The full error is here along with my repo
https://github.com/petertimwalker/friends/issues/1
Heroku doesn't support all Ruby versions. When a Ruby version reaches end-of-life and is not maintained anymore then Heroku stops supporting it.
Ruby 2.6 reached end-of-life December last year.
Therefore you need to update your application and your local environment to at least 2.7 when you still want to be able to deploy on Heroku.
Please see the list of Ruby versions supported by Heroku.
install ruby version 2.6.10 and use that version in local
if you using rvm check your current version with rvm list and
install ruby 2.6.10 with rvm install 2.6.10
then use command rvm use 2.6.10

rails command does not use homebrew ruby and only invoke `/usr/bin/ruby`?

It feels like rails command would only invoke the ruby bin under /usr/bin/ruby and ignore the homebrew installed ruby. The bash/zshrc file has been set up as can be seen from which ruby output below. I can not use rails command to create a new rails project because of this. Can anyone help to point to the right configuration to change this behavior? Thanks!
➜ rails -v
Rails 7 requires Ruby 2.7.0 or newer.
You are running
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]
Please upgrade to Ruby 2.7.0 or newer to continue.
➜ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]
➜ which -a ruby
/usr/local/opt/ruby/bin/ruby
/usr/bin/ruby
➜ which ruby
/usr/local/opt/ruby/bin/ruby
➜ which -a rails
/usr/bin/rails
➜ which -a gem
/usr/local/opt/ruby/bin/gem
/usr/bin/gem

Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1

ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
cat Gemfile.lock | grep -A 2 RUBY
RUBY VERSION
ruby 2.7.1p83
bundle platform --ruby
ruby 2.7.1p83
sudo rake db:create
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1
I can't see what is the problem here. This is a fresh installation of Ubuntu it's 20.04 and I was trying to set up a ruby on rails env for the first time.
Different users can have different versions of ruby installed.
When you run ruby -v you will see the version of ruby in your user environment.
When you run sudo rake ... (or sudo anything) you will use the version of ruby in the super user’s environment.
In short, don’t use sudo. bundle exec rake db:migrate Will ensure you’re using the same version of ruby as you see in the output of bundle platform —ruby
To help understand what’s happening when you try to check the version, try sudo ruby -v That should be where v2.7.0 comes from

Problem when running git push Heroku, Ruby version is 2.6.4, but your Gemfile specified 2.6.3

I am trying to push something to Heroku by this command
git push heroku master
and it gave me this error :
Your Ruby version is 2.6.4, but your Gemfile specified 2.6.3
Failed to install gems via Bundler.
Detected a mismatch between your Ruby version installed and
Ruby version specified in Gemfile or Gemfile.lock.
You can correct this by running:
$ bundle update --ruby
$ git add Gemfile.lock
$ git commit -m "update ruby version"
I changed my Gemfile from 2.6.3 to 2.6.4, ofcourse update the gemfile by bundle install command, but I failed. I also tried to run all the command they gave me, but nothing changed, I still have the error. When I check, the Gemfile still 2.6.4, but the error still told me that your Gemfile specified 2.6.3.
Could you still give me some ideas for me? Thank you very much.
I was breaking my head.
$ ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]
$ bundle 2.2.17 platform --ruby
ruby 2.7.4p191
$ cat .ruby-version
2.7.4p191
$ cat Gemfile.lock | grep -A 2 RUBY
RUBY VERSION
ruby 2.7.4p191
$ cat Gemfile | grep -A 2 "ruby '2.7.4'"
ruby '2.7.4', :patchlevel => '191'
They all point to the same ruby version: 2.7.4p191. Reading the Heroku log output, I edited the line in the bin/bundle file where it says
#!/usr/bin/env ruby2.7
to
#!/usr/bin/env ruby
That's all.

This version of Ruby is not available on Heroku-18

When I try to build my app on Heroku, it fails because the Ruby version I purportedly am using is not supported by Heroku. My app has no problem building/deploying locally. Here is full message log:
-----> Ruby app detected
-----> Compiling Ruby/Rails
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.8.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.8.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
!
! An error occurred while installing ruby-2.3.8
!
! This version of Ruby is not available on Heroku-18. The minimum supported version
! of Ruby on the Heroku-18 stack can found at:
!
! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
!
! Push rejected, failed to compile Ruby app.
! Push failed
However, in my Gemfile and Gemfile.lock, I am NOT using ruby-2.3.8. That is why I am very confused. I have links to my Gemfile gist and Gemfile.lock gist.
Things I have tried on Heroku:
Running bundle install.
This. Did not resolve issue, my Gemfile, Gemfile.lock, and local Ruby is ALL 2.6.3.
Making sure Gemfile and Gemfile.lock are the most recent ones in my Github.
Running gem install bundler -v 1.17.3 but it gives me ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.5.0 directory
EDIT:
It appears after running heroku run ruby -v, that my Ruby version is actually ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
It's possible that the "blessed" version of bundler hasn't been updated yet to 2.0.2, and only 2.0.1 is supported on the official ruby buildpack.
To test this out, you can edit your Gemfile.lock manually and change:
BUNDLED WITH
2.0.2
to 2.0.1
It will be overridden every time you bundle though, so if that is the fix, you might want to downgrade bundler for the time being.
On Heroku you cannot configure the version of bundler directly -> https://devcenter.heroku.com/articles/bundler-version#app-not-using-the-currently-supported-bundler-version
I am guessing you are using the heroku buildpack, if not you will want to set that up.
You can switch to a supported buildpack with:
heroku buildpacks:set heroku/ruby
I believe I have had issues where heroku wasn't updating, try the top 2 answers here:
Heroku is not updating my code?
One of the pitfalls of heroku is you will need to work with in their construct. I would make sure you are using whatever version of bundler and ruby they want locally prior to deployment and after deployment confirm by sshing on to the heroku box to confirm it is the same version.
Sidenote, using the ruby keyword will only work for certain versions of bundler
https://devcenter.heroku.com/articles/ruby-versions#selecting-a-version-of-ruby
I usually set my ruby version in a .ruby-version file in the root of the project.

Resources