Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundler finds the wrong version of ruby

I'm using OS X 10.10.5 (Yosemite). I'm trying to clone the github repo for MacDown. The instructions in the README say that after cloning one should do

git submodule init
git submodule update
bundle install
bundle exec pod install

I'm not a ruby programmer, so I had to install Bundler. The first two steps ran fine, but when I tried to run bundle install I got the error

activesupport-5.0.0.1 requires ruby version >= 2.2.2, which is incompatible with the current version, ruby 2.0.0p481

So I tried brew install ruby and now I have

saul@miniMac ✓ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]

However, bundle install gives me the same error message as before. It's clear that it's finding the ruby at /usr/bin/ruby instead of the one at /usr/local/bin/ruby. How do I correct this?

I thought that perhaps the problem was that I had installed bundler before upgrading ruby, neither sudo gem uninstall bundler nor sudo gem uninstall bundle has any effect, and I don't know what else to try.

Here is all the output, in case it's relevant:

saul@miniMac ✓ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
activesupport-5.0.0.1 requires ruby version >= 2.2.2, which is incompatible with
the current version, ruby 2.0.0p481

EDIT:

Thanks for the suggestions. I tried gem install bundler again, but it didn't help. I got the same error message. Here's what I get from bundle env

saul@miniMac ✗ bundle env
Environment

    Bundler   1.13.6
    Rubygems  2.0.14
    Ruby      2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
    Git       2.5.4 (Apple Git-61)

Gemfile

    source 'https://rubygems.org'

    gem 'cocoapods', '0.39.0'

Gemfile.lock

<No /Users/saul/Projects/macdown/Gemfile.lock found>

EDIT 2:

saul@miniMac ✓ which -a bundle
/usr/local/bin/bundle
/usr/bin/bundle
like image 202
saulspatz Avatar asked Nov 04 '16 21:11

saulspatz


1 Answers

It seems that your PATH may have an entry that points to your older version of Ruby and despite having a newer version (2.3.1) it gets to use the first ruby binary it finds in one of the entries it finds in your PATH, which happens to be the old version. You could try to add your latest Ruby path as the first entry of your PATH variable, but in case a sub-shell is run and the default PATH is loaded the path to your latest Ruby would be overwritten. That being said, I think the easiest would be to use rvm here to make sure your environment is all set up with the version you intend to use at any given time. RVM can manage multiple versions of ruby in the same system. Read more about RVM here.

Run all the following commands in the same terminal window:

  1. Install rvm: curl -sSL https://get.rvm.io | bash -s stable
  2. Add rvm binary to PATH: export PATH="$PATH:$HOME/.rvm/bin"
  3. Install ruby version you need: rvm install 2.3.1
  4. Configure the current shell to use a specific version of Ruby like so: rvm use 2.3.1
  5. Run bundle install again
like image 198
hmacias Avatar answered Oct 12 '22 16:10

hmacias