Should I check in `.ruby-gemset` and/or `.ruby-version`?
For standard projects
Check in .ruby-version
if your project depends on a ruby like ruby-2.0.0
.
Check in .ruby-gemset
only if your team agreed on it.
Add .rvmrc
to .gitignore
so anyone can override .ruby-*
files settings with .rvmrc
.
For gems
Check in .ruby-version
with ruby-1.8.7
only if your project still targets ruby 1.8.7
, otherwise check it in only if your gem requires it.
Do not check in .ruby-gemset
.
Use rvmrc or ruby-version file to set a project gemset with RVM?
If your .rvmrc
file contains custom shell code, continue using .rvmrc
as it allows you to include any shell code.
If your only aim is to switch Ruby versions, then use .ruby-version
which is supported by other Ruby version switchers such as rbenv or chruby. This file also does not require trusting as it is just the name of a Ruby version and will not be executed in any way.
If you use .ruby-version
you can include @gemset
in the file but this will not be compatible with other switchers. To maintain compatibility use the gemset name in a separate file .ruby-gemset
which is ignored by other tools (it works only together with .ruby-version
).
For example, if you have a simple .rvmrc
:
rvm use 1.9.3@my-app
It can be transformed to .ruby-version
:
1.9.3
And .ruby-gemset
:
my-app
Be sure to remove the .rvmrc
file as it takes precedence over any other project configuration files:
rm .rvmrc
Set a default Ruby version for a specific directory (RVM)
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'.
How to change ruby version
There is lots of advise in the comments to your question, some of it is advanced-ish rbenv or rvm usage.
My advice: Decide on how to manage multiple rubies - either use your OS package manager (in your case the apt-get
/PPA stuff) OR rvm OR rbenv.
For the OS package manager, there should be a way to call ruby with version explicitely (e.g. /usr/bin/ruby1.9.3
), or research on and call update-alternative
. As bundler comes with a gem, you might get the interpreters confused here.
For rvm, change ruby version with rvm use 2.5.1
(once it is installed).
For rbenv I actually do not know but it should be trivial, too (and people are happy with it; it just happens that I tried rvm first and it worked like a charm, never evaluated rbenv).
I usually install one "system" ruby (apt-get install ruby1.9.3) and use rvm afterwards. You can still switch to the packaged "production" ruby with rvm use system
.
Update 2017: Most distros ship with a ruby version installed already, so you probably don't have to install it manually. Run ruby -v
or which ruby
to see if a ruby interpreter is already installed.
In your case I would probably deinstall all system rubys (apt-get purge ...
), remove the PPAs, remove your ~/.rvm and rbenv and start from scratch (install packaged stable ruby, then rvm and use rvm (r.g. rvm install 2.3.1
) from there on).
Safely deleting .ruby-version and .ruby-gemset
Yes, since the rvm observes the current dir for the .ruby-gemset, .ruby-version, or .rvmrc.
Yes, you can, and it will lead to that rvm will not do actions required for the found out the config files. You have to just place the files into the proper folder, and touch not the gemsets themselves. i.e. it will not affect on placement of the gemset inside the rvm.
Related Topics
Ruby - How to Retrieve Sum in Array Group by Multiple Keys with Condition Max
Error When Pushing to Heroku - ...Appear in Group - Ruby on Rails
Utc Time Resets to 2000-01-01 (Ruby). How to Prevent the Time from Resetting
Don't the Ruby Methods Instance_Eval() and Send() Negate the Benefits of Private Visibility
Rails 4 Order by Virtual Attribute
Count Overlapping Regex Matches in Perl or Ruby
How to Ignore Irrelevant Methods When Profiling Ruby Applications
Instagram Ruby Gem - Unable to Reach Callback Url
Enter & Ioerror: Byte Oriented Read for Character Buffered Io
Connection Refused Using Sunspot and Solr in Rails
Rails 4 Use Application Helpers Inside Initializers
How to Capture Terminal Arrow Keys in Ruby
What's the Differences Between Ruby on Rails and Ruby
Using Devise for More Than One Models in Rails App
Complete Web Apps in Ruby Without Using Any Frameworks - How Difficult? Pitfalls