Conflict between ruby version in gemfile and local ruby - ruby-on-rails

I'm having trouble running running an app because of its ruby version. But from everything I can tell, I have the right version of ruby running. What am I doing wrong?
user#computer project % rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.7.1
user#computer project % rbenv local
2.7.1
user#computer project % ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
user#computer project % which ruby
/Users/user/.rbenv/shims/ruby
(I've also tried switching the ruby version in the gemfile from 2.7.1 to 2.6.3, but when I do, it gives me the opposite message (that I have 2.6.3 specified but I'm running 2.7.1).
Update: Turns out this problem is specific to running in zsh. Using bash works fine.

rails invokes the global binary. You can try:
bundle exec rails instead, or
gem install rails in your Ruby 2.7.1 environment.

Related

Your Ruby version is 2.7.0, but your Gemfile specified 2.6.3 but I have ruby 2.6.3 installed

So my gemfile specifies ruby '2.6.3' and I used rbenv to install ruby 2.6.3. However, when I try to run rake db:create, it gives me an "Your Ruby version is 2.7.0, but your Gemfile specified 2.6.3" error. I even check my ruby version using ruby -v and it even tells me I have 2.6.3. Can someone explain why this is occurring?

Project selected ruby version does not match ruby -v using asdf-ruby

I switched to a new computer and set up a whole development environment from start. One of the changes was trying to use asdf instead of rvm. Sadly when trying to run rails s or rails c on one of the projects I have im running into:
Your Ruby version is 2.7.1, but your Gemfile specified 2.6.3
2.6.3 is the version specified by Gemfile indeed, the same is in .tool-versions file and .ruby-version.
My lack of understanding comes from me not having ruby 2.7.1.
asdf list =>
ruby
2.6.3
ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
which ruby
/home/kkp/.asdf/shims/ruby
Any help would be appreciated.
Just as I posted I suddenly remembered to run
gem install bundler
and off we go

Just installed Rails 6 and am getting an odd error

installed ruby 2.6.4 and rails 6.0.0 using rbenv on a mac running Mojave 10.14.6 to evaluate upgrading a legacy app. rails -v returns `
Rails 6 requires Ruby 2.5.0 or newer.
You're running
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Please upgrade to Ruby 2.5.0 or newer to continue.`
however ruby -v returns ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18]
I currently have the following versions of ruby installed
ruby-2.2.6
ruby-2.3.8
* ruby-2.6.4
which ruby returns
/Users/jerryzornes/.rubies/ruby-2.6.4/bin/ruby
and my bundler version is 2.0.2
So I have no idea as to what's going on.
In the root folder of your Rails app make sure you have a file named .ruby-version that contains the text ruby-2.6.4. This is used by rbenv to make sure the right version of ruby is used.
You can also run which ruby to see where it is loading ruby from. If this isn't running from /Users/jerryzornes/.rubies/..., then the issue is with your rbenv install. I would check you path variable to make sure it has the rbenv shims in place, ie looks like ~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin

Mismatched ruby version after downgrade from 2.4.1 to 2.3.3 while running bundle install

While attempting to solve another issue identified in this thread:
Error while trying to load the gem 'devise. ActiveSupport: Duration can't be coerced into Integer, I followed the suggested solution and changed my ruby version from 2.4.1 to 2.3.3 using rbenv. I also made similar changes in my Gemfile to reflect the new ruby version. However, when I tried to bundle install again, it throws an error saying that my ruby version is 2.4.1, when my Gem specified 2.3.3. However, running ruby -v shows my ruby version is on 2.3.3.
$ bundle install
Your Ruby version is 2.4.1, but your Gemfile specified 2.3.3
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
Any help here would be appreciated. Thank you!
Gem installation is specific to ruby version, so the bundler you're using is likely installed to your old ruby. Try installing bundler again:
gem install bundler
That should fix your problem.

Ruby version is not updated in the applications enviroment

I updated ruby to 2.2.2 with rbenv
$ruby -v
$ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]
After I created a new rails application by rails new xxx and then rails server,
Why the ruby version is still 2.0.0. How to fix this? Thanks
You need to freeze Ruby version in two files:
.ruby-version
2.2.2
This file created automatically if you type rbenv local 2.2.2. The other file require to lock specific Ruby version is the following:
Gemfile
ruby '2.2.2'
...
Afterwards bundle install will fail in case of different Ruby version set as active.

Resources