2

I have a Rails app. My collaborator updated the app's Ruby version and added Gems. I had to update my local version of Ruby to 2.3.1.

Now it seems that rails s looks for gems in a different location than where bundle install puts them. What do I have to do to get both to put and look for gems in the same place?

Concretely, when I try to start the Rails server with

rails s

I get the message

/Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'railties' (>= 0) among 5 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/Falk/.gem/ruby/2.3.0:/Users/Falk/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0', execute `gem env` for more information
 from /Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
 from /Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
 from /usr/local/bin/rails:22:in `<main>'

This happens even though I have already run

bundle install

and all the required gems are included in the gem file. I was able to make progress by manually uninstalling and reinstalling individual gems through

gem uninstall <gem_name>
gem install <gem_name>

but it kept on complaining about one missing gem after another. Then I uninstalled all gems using

for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done

After that, bundle install still acts as if all gems were already installed. But rails s still does not work and complains about missing gems. What should I do now?

Falk
  • 325
  • 1
  • 3
  • 10

2 Answers2

2

I was able to solve this problem by following the steps outlined here: bundle uses wrong ruby version

Community
  • 1
  • 1
Falk
  • 325
  • 1
  • 3
  • 10
1

Go to the service/repository that you are trying to run, and go to bin/bundle file. open the file and you will find a code snippet like this :

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

Change the path to your gemfile as is mentioned here, after which in your service/repository you will find your gemfile. By checking its source provide the right directory path. After which include all your gems into the gem file, like this:

gem 'protobuf'
gem 'grpc'
gem 'protobuf-activerecord'

Finally use

bundle list

to check if the bundler has all the gems initialised in it.

susheel
  • 36
  • 6