Bundle says gem is missing - but it's not?

2020-07-30 02:36发布

问题:

Background

I am maintaining the content of a Ruby On Rails site, but I really have no experience with Rails.

When trying to run the Rails server: rails s I get this:

Could not find activesupport-3.2.0 in any of the sources

Run bundle install to install missing gems

I run bundle install

Gem::InstallError: factory_girl requires Ruby version >= 1.9.2. An error occured while installing factory_girl (3.2.0), and Bundler cannot continue.

Make sure that gem install factory_girl -v '3.2.0' succeeds before bundling.

Okay, I install factory_girl as per the instructions:

Successfully installed factory_girl-3.2.0 1 gem installed

Run bundle install again:

Gem::InstallError: factory_girl requires Ruby version >= 1.9.2. An error occured while installing factory_girl (3.2.0), and Bundler cannot continue. Make sure that gem install factory_girl -v '3.2.0' succeeds before bundling.

Do you have any idea?

Info

Yesterday I got a cross-tread error when trying to run rails server. So as per this SO advice I advice I've nuked RVM and installed rbenv and bundler instead of RVM.

I have tried with both Ruby 1.9.3-p125 and 1.9.3-rc1

Output of gem list shows factory_girl as installed.

  • ...
  • factory_girl (3.2.0)
  • ...

Output of gem environmentshows the problem might has something todo with ruby 1.9.1 being installed also?

RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.3 (2011-09-23 patchlevel -1) [x86_64-darwin11.3.0]
- INSTALLATION DIRECTORY: /Users/andreas/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /Users/andreas/.rbenv/versions/1.9.3-rc1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/andreas/.rbenv/versions/1.9.3-rc1/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/andreas/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1
- /Users/andreas/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- REMOTE SOURCES:
- http://rubygems.org/

回答1:

@jdoe answered in the comments. And it worked. Apparently I needed to delete Gemfile.lock.

I don't know why or how though. I am just posting this here, until @jdoe shows up and collects his points with a real answer.



回答2:

Try reinstalling all the gems with the following command

bundle install --force


回答3:

Have you tried this?

bundle exec rails s


回答4:

First things first - I have no experience with rbenv.

One of the nice things with RVM is that it helps make fairly explicit what the moving parts of your Ruby environment are.

rvm list will give you a list of Rubies rvm gemset list will give you a list of gemsets (this should not be necessary if using bundler)

Now, here are a few tricky things:

  • Gemfile is used by Bundler to determine what to install
  • If nothing is specified, Bundler will try to install the latest version of a gem
  • If the latest version of a gem is not compatible with your current Ruby, then ...
    • You can change version of Ruby (rvm install 1.9.3 for instance)
    • You can tell the Gemfile to specify which version of the gem you want, with varying degrees of strictness.
      • Can you tell I like indenting bullet points?
      • gem "vcr", "~> 1.11.3" # => this will say you prefer 1.11.3 but anything within 1.11 range is acceptable
      • gem 'factory_girl', '3.2.0' # => this says, only install version 3.2.0 of factory_girl, nothing else

In addition, before anything else, you should run bundle check to see what bundler has to say about your gems.



回答5:

Make sure all the gems you are installing is in the Gemfile, because if the gem is not added to the Gemfile, even if you installed it manually, your Rails app is not getting it.

Sample Gemfile would be

gem 'rails', '3.0.0'

gem 'mysql2', '< 0.3'
gem 'rails3-jquery-autocomplete'

#authorization
gem 'authlogic'
gem 'hoptoad_notifier'

#reporting
gem 'lazy_high_charts'

group :test do
  gem 'rspec', '2.0.0'
  gem 'rspec-rails', '2.0 '
  gem "test-unit"
end