How to Specify Rvm Gemsets for Rails Gem Whenever

How to specify rvm gemsets for Rails gem whenever?

use wrapper:

job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/wrappers/ruby-1.9.3-p448@rails-3.2/bundle exec rails runner ':task' :output"

this will load proper rvm environment and run bundle in its context, bundler only adds environment variables for using gems from Gemfile without modifying the loaded ruby environment.

a similar situation is described here http://rvm.io/integration/init-d

rails 4.2.0 with whenever gem in development env, not working

Using output in schedule help me to find a problem.

I used specific gemset and not specify it in my schedule.
That's why I got error. Whenever gem trying to use default gemset which was different from gemset that I use for my project.

So there are two options for solving problem, use default gemset or specify yours in schedule.

Sample of setting gemset and env:

set :environment, :development

Rake:

job_type :rake, "cd :path && $HOME/.rvm/scripts/rvm && rvm use
2.2.0@somename && rake ':task' :output"

Runner:

job_type :runner, "cd :path && $HOME/.rvm/scripts/rvm && rvm use 2.2.0@somename && bin/rails runner ':task' :output"

Why does rvm switch gemsets when I cd into my rails project directory?

The Gemfile in the rails project directory will tell RVM to switch rubies if the Gemfile specifies a ruby version (something like ruby="1.9.3" or #ruby=1.9.3@gemset).

This is because RVM supports more then just .rvmrc => https://rvm.io/workflow/projects/#ruby-versions a full list can be found here: https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/rvmrc#L743-L744

Note that RVM will check the following files before the Gemfile: .rvmrc .versions.conf .ruby-version .rbfu-version .rbenv-version. So creating a .rvmrc file with the line "rvm use ruby-1.9.3-p362@ruby-1.9.3" would make RVM ignore the Gemfile.

Whats the command to let rvm use default (like global) gemset for every new rails application I create?

You can specify a "default" gemset for a given ruby interpreter, by doing:

rvm use ruby-1.9.2-p0@gemsetname --default

See: http://beginrescueend.com/gemsets/using/ and http://beginrescueend.com/gemsets/basics/

it's probably a better idea to use a specific gemset for each of your projects, together with it's specific Gemfile. Problems could happen if you require '>= x.y.z' in your Gemfiles, and you do a bundle update in one project, but not in the other...

cd ProjectA
rvm gemset create projecta
rvm gemset use projecta

cd ProjectB
rvm gemset create projectb
rvm gemset use projectb

This way, although you update the gems in ProjectA via bundle update to the latest and greatest, they still don't get modified for ProjectB -- eliminating the possibility for interference between projects.


you can also add a .rvmrc file to a directory, e.g. your project directory. RVM will then use the ruby-version and gem set listed in the .rvmrc file as the default for all sub-directories.

e.g. assuming that you have ruby 1.9.3 installed, and a gem set "rails_3.2" for that ruby version:

# cat .rvmrc
rvm use ruby-1.9.3-p0@rails_3.2

where go gems installed by rails command when i create a specified gemset later

You could create the gemset before you create the rails app if you want:

rvm gemset create new_gemset_name

Then BEFORE you create the app w/ rails, run:

rvm use @new_gemset_name

That way when you run "rails create" the gems will be installed in the new gemset you just created. Afterward you can create a .rvmrc file

How to set the default gemset in RVM with Rails & Heroku

Only way you could do it is to add two files to your application: .ruby-version and .ruby-gemset and add 2.1.1 in the .ruby-version file and rails4 in the .ruby-gemset file.

You can also do this on your command line with:

echo 2.1.1 > .ruby-version

and

echo rails4 > .ruby-gemset

And that will create the files for you with the version 2.1.1 and the gemset rails4

So whenever you open a new terminal, rvm will use ruby 2.1.1 and gemset rails 4

Check out more on rvm documentation

Hope this helps

Is there a difference between using RVM local gemset and using Bundle exec?

If you're an RVM fan like myself, I would go with creating my own gemset for every rails project I start. This will make it easier for me to just use rake and rails commands without specifying bundle exec every time.

Put in mind when sharing your code that some developers might be using rbenv or maybe not using a ruby version manager at all. One way you can make sure that everyone is happy and working with the same version of ruby, is to provide two additional files in your project directory (.ruby-version and .ruby-gemset) and track them in your project.

The .ruby-version file would contain the version of ruby you're using for example 2.4.1. Note that this is compatible with both RVM and rbenv and will switch to the correct ruby version.

The .ruby-gemset file is identified only by RVM; thus, switching to the correct gemset you have setup for the project.

This will make your project compatible with developers using rbenv while still making those of us using RVM happy :)

Putting all these considerations in mind, now you should care less wither people use bundle exec or not!

rvm gemsets with Bundler

It's redundant to use RVM's gemsets if you're using bundler.

Conflicts when using Bundler arise primarily for two reason:

  1. Using gems that require other gems without precise version specifications.
  2. Executable conflicts: you have both rails v3 and v4 installed, so where do we go to when calling rails g migration or calling rake?

The first issue can be resolved if you're careful about specifying your gem versions more explicitly in your Gemfile.

When working within a project with a Gemfile, the second issue can be resolved by prefixing executable calls with bundle exec, which will run the command within the context of the current bundle (e.g. bundle exec rake db:migrate).

When you want to specify a gem version outside of a Gemfile's context (e.g. rails new fancy_app), you can specify any gem's version by providing it as the first argument surrounded by underscores.

rake --version
rake _10.3.1_ --version
rails new rails_latest_app
rails _3.2.12_ new rails_3_app
rails _4.0.4_ new rails_4_app

RubyGems handles all of this for you by creating version-aware wrappers for any gem's executables. Just run cat `which gem_executable` (with gem_executable being something like rake, rails, foreman, pry, etc.) and have a look.

Stephen Ball has a good blog post about how to use Bundler instead of RVM gemsets, which explores the overlaps in further detail.

While RVM's gemsets are not necessary, RVM provides other conveniences:

  • Automatically adding bundler binstubs to the PATH, so you can avoid typing bundle exec. Note the bundler plugin for oh-my-zsh provides the same feature
  • Managing multiple Ruby versions

The ruby version manager rbenv provides similar features as well.



Related Topics



Leave a reply



Submit