x-yuri x-yuri - 4 months ago 38
Ruby Question

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.

Answer

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.

Comments