2

I recently set up Ruby on Rails with rbenv. But for some reason I am getting: "Could not find shoulda-matchers-3.1.1 in any of the sources" when I try to do a rails generate scaffold command. Here is my gem environment:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.4
  - RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY:     /home/username/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: /home/username/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /home/username/.rbenv/versions/2.3.0/bin/ruby
  - EXECUTABLE DIRECTORY: /home/username/.rbenv/versions/2.3.0/bin
  - SPEC CACHE DIRECTORY: /home/username/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/username/.rbenv/versions/2.3.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/username/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
     - /home/username/.gem/ruby/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
 - https://rubygems.org/
  - SHELL PATH:
     - /home/username/.rbenv/versions/2.3.0/bin
     - /home/username/.rbenv/libexec
     - /home/username/.rbenv/plugins/ruby-build/bin
     - /home/username/.rbenv/plugins/ruby-build/bin
     - /home/username/.rbenv/shims
     - /home/username/.rbenv/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /home/username/.rvm/bin
     - /home/username/.rvm/bin
     - /home/username/.rvm/bin

And when I run gem list, it shows:

sass-rails (5.0.4)
sdoc (0.4.1)
shoulda-matchers (3.1.1)
spring (1.7.1)
sprockets (3.6.0)

I've tried gem install shoulda-matchers, bundle install, bundle update, gem install bundler, gem install bundle, gem update --system, etc. It says I have it already but it still keeps giving me that error. Please help. D:

Zyaga
  • 43
  • 3

1 Answers1

1

You might need to prefix your commands with bundle exec each time, like bundle exec rails g.

If you're sick of typing bundle exec you can install the binstubs like

bundle install --binstubs

See https://github.com/rbenv/rbenv/wiki/Plugins#bundler-integration for more detail.

Ryenski
  • 9,582
  • 3
  • 43
  • 47
  • Running my rails generate command with bundle exec before it still didn't change anything. Same message. :( – Zyaga May 18 '16 at 14:58
  • What about installing the binstubs? – Ryenski May 18 '16 at 15:02
  • That worked! Is there anything I need to be aware of though? It seems like that using binstubs is not normally a good idea? – Zyaga May 18 '16 at 15:15
  • The reason is because all the binaries provided by your gems (like the `rails` command) are not automatically available in your PATH when you're using rbenv or rvm. The binstubs command puts `bin/` into your PATH so that you can invoke those commands. Read https://github.com/rbenv/rbenv/wiki/Understanding-binstubs for more info on how it works. – Ryenski May 18 '16 at 15:18
  • The other thing to be aware of is that by using binstubs you could have different versions of gems available in different project directories. For example you could have a Rails 4 project in one dir and a Rails 5 project in another. By using binstubs you'd always invoke the correct bins for the version of Rails that you're currently working in. – Ryenski May 18 '16 at 15:19