Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When changing into Rails folder, have rvm pick ruby and gemset?

For my different Rails folders, I would like to have rvm automatically load the correct gemset when running anything from 'bundle install' to doing my 'autotest' or rails console or server. Is this possible? Currently I have to manually do 'rvm use' which is getting a bit tedious as I am working on multiple Rails projects at the same time.

like image 709
Etienne Avatar asked Mar 19 '11 17:03

Etienne


People also ask

What is Gemset in RVM?

If you are using RVM(Ruby Version Manager) then using a gemset for each project is a good idea. A gemset is just a container you can use to keep gems separate from each other. Creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects.

How do I remove Gemset from RVM?

You need to "rvm gemset empty [gemset_name]". I suppose if you have many gems, it could take a while to uninstall them all. Incidentally right now I am able to run rvm gemset empty and it clears the current gemset.

How do I create a Gemset in RVM?

Step 1: rvm gemset create [name of gemset] Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console. Step 3: Refresh your directory. # You can simply do this by checking out of your directory and going back to that directory again.

What is Rbenv and RVM?

rbenv vs. RVM. Both rbenv and RVM are Ruby version management tool. RVM is more resourceful but rbenv is lightweight which makes it a strong contender for RVM. RVM is used to manage and install different versions of Ruby and gemsets on system where Rbenv is a lightweight Ruby version management tool.


6 Answers

Create a .rvmrc file in your rails directory, and rvm will automatically load it. An example .rvmrc that loads Ruby 1.9.2 and a gemset named "rails3":

.rvmrc

rvm 1.9.2@rails3

You can do a lot more too, described in detail here: https://rvm.io/workflow/rvmrc/

like image 187
Dominic Avatar answered Oct 01 '22 23:10

Dominic


For current versions of RVM, using two files is best practice:

.ruby-version
.ruby-gemset

http://rvm.io/workflow/projects

like image 44
dangerousdave Avatar answered Oct 01 '22 21:10

dangerousdave


You can also use this in Gemfile

ruby '2.2.0'
ruby-gemset=significa

This way rvm will automatically pick the configured version

like image 45
Simonini Avatar answered Oct 01 '22 23:10

Simonini


Yaw just create two plain-text files and put into your project folder: .ruby-gemset and .ruby-version

.ruby-gemset should contain only gemset alias name and nothing else

.ruby-version follows the same rules, put your ruby version or alias there

like image 26
Anton Semenichenko Avatar answered Oct 01 '22 21:10

Anton Semenichenko


For current RVM version 1.29.1, the recommended way is

rvm --ruby-version use <ruby-version>@<gemset>

Exmaple

rvm --ruby-version use 2.4.0@rails5
cat .ruby-version  # 2.4.0
cat ruby-gemset # rails5

this will generate two file .ruby-version and .ruby-version in your porject directory. This will compatible with other Ruby Versions Managers

like image 26
fangxing Avatar answered Oct 01 '22 21:10

fangxing


You can easily do that by placing an .rvmrc file at the base of your project.

like image 37
picardo Avatar answered Oct 01 '22 23:10

picardo