How can I get bundler to use the Ruby version set by chruby and .ruby-version?
Asked Answered
L

3

1

I have the pleasure of setting up a development environment for an application running Ruby 1.8.7. Unfortunately bundler is not using the version of Ruby set in .ruby-version by chruby.

Also, I have ruby "1.8.7" included in the Gemfile

Whereas the local version is ruby-1.8.7-p374, the bundler environment is using ruby-2.5.0p0.

$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.3.0]

$ bundle env | grep Ruby
Ruby          2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]

This results in the following message:

$ bundler
Your Ruby version is 2.5.0, but your Gemfile specified 1.8.7

This issue contains some helpful comments but so far I haven't been able to resolve the issue. I do have Ruby 2.5.0 installed in /usr/local/opt as a result of installing vim via brew install vim. This would appear to the version that the Ruby 1.8.7 bundle script is using, as evidenced by:

$ which bundle
/Users/keithpitty/.gem/ruby/1.8.7/bin/bundle

$ head -n1 $(which bundle)
#!/usr/local/opt/ruby/bin/ruby

This problem is proving to be quite frustrating. I would very much appreciate any suggestions.

Lowtension answered 25/1, 2018 at 3:50 Comment(2)
Do you still have this issue? If yes, did you tried re-install Bundler?Viridissa
Thanks for your comment. I now realise I forgot to provide the solution here. I'll add it now.Lowtension
L
0

I fixed this by installing RubyGems 1.6.2. See How to set correct Ruby version in gem environment for more.

Lowtension answered 4/7, 2018 at 13:45 Comment(0)
S
0

Have you mentioned the ruby version in Gemfile you are planning to use, if not trying adding the ruby version in your Gemfile, more info here.

ruby '~> 2.3.0'

Also on a side note, if you have multiple ruby versions in you machine, ideally you can make use RVM or rbenv to manage multiple Ruby versions. ( makes your life easy :) )

Sim answered 25/1, 2018 at 4:56 Comment(1)
Yes, as already noted, I have specified ruby "1.8.7" in the Gemfile and I use chruby rather than rvm or rbenv to manage multiple Ruby versions.Lowtension
L
0

I fixed this by installing RubyGems 1.6.2. See How to set correct Ruby version in gem environment for more.

Lowtension answered 4/7, 2018 at 13:45 Comment(0)
S
0

I followed these instructions https://gist.github.com/andrewroycarter/6815905

In short, I have a project using 2.5.8 and my local version is 2.7.2, so bundle install says

Your Ruby version is 2.7.2, but your Gemfile specified 2.5.8

What I did was to go to my home directory (or at least leave the project directory), activate chruby 2.5.8 and install the bundle gem

cd
chruby 2.5.8
gem install bundler

Now, when I go back to the project directory I can do bundle install.

Sebaceous answered 31/5, 2021 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.