Ruby version is not updated in the applications enviroment - ruby-on-rails

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.

Related

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

Rails Seeing Incorrect Ruby Version

I've built a Rails 5 app and it's working great but I'd like to change the Ruby version I'm running it on. I'm using RVM 1.27.0 on Ubuntu 16.04. I copied the app folder to a different path and changed the versions on .ruby_version and my Gemfile:
Gemfile:
source 'https://rubygems.org'
ruby "2.2.2"
.ruby_version:
ruby-2.2.2
Once I updated these I moved out and back into the folder and ran a ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
I then ran a bundle install and everything installed without error.
However, when I ran rake -T I get this:
Your Ruby version is 2.3.1, but your Gemfile specified 2.2.2.
My $PATH looks good:
/home/ken/.rvm/gems/ruby-2.2.2/bin:/home/ken/.rvm/gems/ruby-2.2.2#global/bin:/home/ken/.rvm/rubies/ruby-2.2.2/bin:/home/ken/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
What am I missing? Where is Rails pulling the Ruby version from? How can I fix this?
You're using a system bundler which is why you're seeing a different version of ruby. All you need to do is install bundler under your current ruby version:
gem install bundler
bundle install
Once you do a bundle install you'll get the gem's built for the correct ruby version.
The file name should be .ruby-version, not .ruby_version.
And you also should have file .ruby-gemset with content
gemset
check this link, Create .ruby-version and .ruby-gemset with rvm
You can also try spring stop and gem install bundler

Rails won't use my version of Ruby on my environment [Windows, using uru not rvm]

Problem: I needed use ruby 2.3.1 from what I currently use which is ruby 2.2.4. When I do ruby -v, it shows ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32]. I use uru as an alternative for rvm.
However, when I do rails s, it tells me Your Ruby version is 2.2.4, but your Gemfile specified 2.3.1. bundle tells me the same thing.
uru ls shows:
224p230 : ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
231p112 : ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32]
I've gone through every thread before posting. I have the latest version of Rails and Ruby from RailsInstallers.
Here's what I've tried:
Delete the Ruby folder from RailsInstaller directory. => rails s is not recognized as an internal or external command, operable program or batch file.
Delete and replace the old Ruby with the new Ruby directory => same thing
Contemplating that this is a RailsInstaller error.
Edit: I've changed the Gemfile to use my version of Ruby. It's a sloppy solution for now, but I'm gonna reinstall Rails altogether when I'm finished with this project.

Rbenv Version 2.1.1, but Error Says Ruby Version is 2.0.0 [duplicate]

This question already has answers here:
How to fix "Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0"
(21 answers)
Closed 8 years ago.
I'm on Mac/Mavericks, using rbenv and this rail 4 repo. My rbenvs version is set to 2.1.0, I uninstalled RVM, but when I type in ruby -v it says ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0] what do I need to do to make rbenv the default service for my ruby version?
However, the annoyance is working with my rails app. When I change ruby in my Gemfile to 2.1.1 and bundle install, it says my ruby version is 2.0.0. When I change my version to 2.1.1, it says my Ruby version is 2.0.0.
What do I need to do to set my ruby version to 2.1.0 so the Gemfile can recognize it?
Bash_profile:
export PATH=/usr/local/bin:$PATH
PS1='\W \u\$ '
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/shims:$PATH"
Bundler is trying to tell you that the version of Ruby you have loaded is not matching the one you specified in your Gemfile.
rbenv install 2.1.0 && rbenv local 2.1.0
Was it Spring, maybe? Try spring stop
See How to fix "Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0" for details.
I've actually noticed that message showing up if you don't install bundler right off the bat in the new ruby version before trying to perform a bundle update.
Your Ruby version is 2.0.0, but your Gemfile specified x.x.x
In my case I was moving from the Ruby 2.0 that comes with Mavericks to Ruby 1.9.3p125 with rbenv. I believe the shell will try using whatever bundle binary that is available. My solution was just:
gem install bundler

Resources