x-yuri
x-yuri

Reputation: 18843

Why `bundle exec` is needed when using gemsets?

rvm current says I've switched to some particular gemset, gem list lists only one rake gem, so why do I need to prepend bundle exec?

$ rvm current
ruby-2.3.0@rm

$ gem list rake

*** LOCAL GEMS ***

rake (10.4.2)

$ rake
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 11.1.2. Prepending `bundle exec` to your command may solve this.
/home/rm/.rvm/gems/ruby-2.3.0@rm/gems/bundler-1.12.5/lib/bundler/runtime.rb:35:in `block in setup'
/home/rm/.rvm/gems/ruby-2.3.0@rm/gems/bundler-1.12.5/lib/bundler/runtime.rb:20:in `map'
/home/rm/.rvm/gems/ruby-2.3.0@rm/gems/bundler-1.12.5/lib/bundler/runtime.rb:20:in `setup'
/home/rm/.rvm/gems/ruby-2.3.0@rm/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
/home/rm/.rvm/gems/ruby-2.3.0@rm/gems/bundler-1.12.5/lib/bundler/setup.rb:9:in `<top (required)>'
/home/rm/app/releases/20160707125838/config/boot.rb:3:in `<top (required)>'
/home/rm/app/releases/20160707125838/config/application.rb:1:in `<top (required)>'
/home/rm/app/releases/20160707125838/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/rm/app/releases/20160707125838/config/boot.rb:3:in `<top (required)>'
/home/rm/app/releases/20160707125838/config/application.rb:1:in `<top (required)>'
/home/rm/app/releases/20160707125838/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

UPD Let me make myself more clear. rm gemset is active, I see only one rake gem there (10.4.2). But rake-11.1.2 was installed with bundler. And when I run bundle exec rake, rake-11.1.2 is invoked. So why don't I see it in the list of gems, reported by gem? Aren't gemsets supposed to isolate sets of gems one from another.

Oh, and forgot to mention that it's a production machine.

Upvotes: 0

Views: 371

Answers (3)

x-yuri
x-yuri

Reputation: 18843

On development machines bundler installs gems where gem does. And you can see them in the gem list's output. On production servers though, they are usually installed into separate directory. That's what --deployment option particularly does. Or you can change gem's location with --path option.

Upvotes: 0

cris
cris

Reputation: 17

Maybe you are not setting the gemset properly. If a single gemset have multiple versions of the same gem, you should use the bundle exec. Try by creating and using an specific gemset for your project, if you didn't make it explicit rvm uses a default one that will be overcrowded of gems

Upvotes: 0

Will Sheehan
Will Sheehan

Reputation: 25

As you can see in your error your rake call needs to use rake 11.1.2 but your local machines default is rake 10.4.2 so by not prepending the call with bundle exec the default (10.4.2) is used. What bundle exec does is always use the gem version specified in a projects gemfile, therefore is it always best practice to use bundle exec

Upvotes: 1

Related Questions