I have the gist of the difference between rvm and bundler. On my local machine, I use rvm to manage different rubies and different gemsets for those rubies. For example I have a ruby 2.1.2 with a gemset called core:
$ rvm-prompt
ruby-2.1.2@core
$ rvm gemdir
/Users/donato/.rvm/gems/ruby-2.1.2@core
$ cd /Users/donato/.rvm/gems/ruby-2.1.2@core/gems
$ ls
actionmailer-4.1.10
...
As you can see, I have a ruby 2.1.2 and a gemset core for that ruby. When I run my project, rails looks for the gems located in /Users/donato/.rvm/gems/ruby-2.1.2@core/gems
. It DOES NOT look for the gems at shared/bundle
. In fact, I don't even have a shared directory at my Rails root in my local machine.
So on my local machine, while bundler manages gem dependencies and adds gems if new ones found in Gemfile, it does not manage the LOCATION of the gems' installation. It installs the gems in rvm gemdir
. In fact, when you run bundle install
and a new gem exists in Gemfile, then bundler actually installs the gem in rvm's gem directory.
What's confusing is that this is not how it works in staging or production deploy. It appears bundler looks for gems in the location shared/bundle
. So apparently in production, bundler not only wants to install the gems, but it wants to manage the location of the gems as well, and let rvm just worry about rubies, but not gem locations.
This has caused an issue for me. I am using capistrano for deployment. When I run cap staging deploy
, It is installing gems in the wrong ruby.
The capistrano script runs this line:
Running /usr/local/rvm/bin/rvm ruby-2.1.2@core do bundle install --path /var/www/mysite_staging/shared/bundle --without development test --deployment --quiet
You can see that it installs the gems in shared/bundle.
When I go to shared/bundle/ruby
after a successful deployment, I see the following directory:
/shared/bundle/ruby/2.1.0
Wait a second! In my capistrano 3 script, which is using capistrano-rvm, I specified the following:
set :rvm_type, :system
set :rvm_ruby_version, 'ruby-2.1.2@core'
If it is recommended to use bundler to manage gem locations in staging and production, at shared/bundle directory, then how should I resolve this issue? Why is bundler installing gems in the wrong ruby version for this project?
so, what would you say the major the difference between your machine and the server you are deploying on?
Look at: http://bundler.io/v1.9/deploying.html See different behaviour beween dev and deployment and also read note on capistrano.
hope this helps