Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a default Ruby version for a specific directory (RVM)

How can I use RVM to set a default ruby version for a certain directory? So that every time I cd into that directory, it switches to my preferred version of Ruby.

like image 735
Marco Prins Avatar asked Feb 10 '15 14:02

Marco Prins


2 Answers

Directly from the RVM documentation:

RVM supports multiple files allowing to configure a project for automated ruby switching. In any case make sure to add those files to your version control systems as it is part of the project configuration.

Listed in order of precedence:

  • .rvmrc - shell script allowing full customization of the environment,
  • .versions.conf - key=value configuration file
  • .ruby-version - single line ruby-version only
  • Gemfile" - comment: #ruby=1.9.3 and directive: ruby "1.9.3"
like image 148
DGM Avatar answered Sep 22 '22 10:09

DGM


One way is to use a Gemfile and set the ruby version in it. like so:

ruby '2.2.0'

then when you enter the directory you will see the following message from rvm

RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/danmanstx/rails_projects/app/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
like image 24
danmanstx Avatar answered Sep 22 '22 10:09

danmanstx