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.
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.
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.
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.
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.
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/
For current versions of RVM, using two files is best practice:
.ruby-version
.ruby-gemset
http://rvm.io/workflow/projects
You can also use this in Gemfile
ruby '2.2.0'
ruby-gemset=significa
This way rvm will automatically pick the configured version
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
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
You can easily do that by placing an .rvmrc file at the base of your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With