Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects


I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.


What if we had an ecosystem of fabulous Ruby managers that all understood the semantics of a generic dotfile such as .ruby-version? The file's contents would be nothing more than a string representing a version of Ruby.

Perhaps We Can

Without a more thorough investigation (here be dragons?), the project-level updates might be:

  • rvm: A modification to scripts/functions/rvmrc to check for .rvmrc and then .ruby-version (invoking something like rvm use $(cat $working_dir/.ruby-version)). If the user requires a customized .rvmrc they can wire in .ruby-version themselves (i.e. environment_id="$(cat .ruby-version)@gemset").
  • rbenv: A modification to libexec/rbenv-version-file to check for .rbenv-version and then .ruby-version.
  • rbfu: A modifcation to bin/rbfu to first check for .rbfu-version and then .ruby-version.

In all 3 cases, it seems reasonable to prefer an implementation-specific file over the generic version--no loss of default behavior.


Feedback? Ideas? Questions?

#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="$(cat .rbenv-version)@myapp"
# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1

mpapis commented Feb 26, 2012

that's very nice, would it be possible to make it more repeatable process ? there are things like ruby configuration/flags that might be project specific.

how about:


or for jruby:


the main idea is to keep ruby name in ruby=... and allow additional params, I do not hide that would be also useful for naming gemset for rvm.

We could make a list of standard options - that are most useful.

mpapis commented Feb 26, 2012

and here is how would you read ruby version of it:

sed -n '/ruby=/ {s/ruby=//;p;}' < .ruby-version

although other ways, including sourcing could work too

hmans commented Feb 26, 2012

Well, there you go:


I believe the format of the file should be kept as simple as possible -- ie, a Ruby version, nothing else -- otherwise there's going to be too much fragmentation across the various different tools.


fnichol commented Feb 27, 2012

@hmans Sweet! About as tough as I hoped it'd be.

@mpapis I agree that sometimes additional configuration is nice (even required), but I hope that we could hit the 80 of 80/20 for most people's use cases.

mpapis commented Feb 27, 2012

my only concern is that to simple format makes it very limited, it can not be extended because of it's simplicity, this makes it required to duplicate files to provide customization.

what issues do you see in a format like this:


it's very simple to parse and provides a lot more flexibility, also could provide additional details related to project ... it's extensible

mpapis commented Feb 27, 2012

I see this as possibility to improve the world by including extensions like:


after thinking we are close to allow something more, especially with projects like


just need to get with a good file name, and use ruby= for ruby switchers, rest is our imagination

ddd commented Feb 27, 2012


All my suggestions for names.

mpapis commented Feb 27, 2012

rvm/rvm@60bdc82 :

  • add support for .ruby-version / .rbfu-version / .rbenv-version, can be generated with --ruby-version, will save gemset name to the file ...
  • add support for .versions.conf, can be generated with --versions-conf

example config:

#ruby-gem-install=bundler rake

it will install gems listed in ruby-gem-install=... separated with spaces/comas
will run bundle install if ruby-bundle-install=true or bundle install Gemfile.x if ruby-bundle-install=Gemfile.x


fnichol commented Feb 27, 2012

@mpapis So if I read scripts/functions/rvmrc correctly, this implements the simplest case of including a bare Ruby string in .ruby-version (among others)? This is great!

mpapis commented Feb 27, 2012

yes it does, the only missing thing is support for sanitizing env. variables so I could read in env.*=... from .versions.conf and .rbenv-vars

hmans commented Feb 27, 2012

Guys, have you seen autoenv? Consider how this may factor into this discussion. Most teams working on a project will have their toolchain pretty much locked down and may be better off using autoenv to define how the environment is set up for their project.

I'm happy to support .ruby-version in rbfu, but I think anything beyond just mentioning a Ruby version in that file would expand the scope so much that using something like autoenv may be a better solution altogether.

My 2 Eurocents... :)

hmans commented Feb 27, 2012

Speaking of which, I'm seriously considering removing the "automatic mode" from rbfu and just referring people to autoenv instead. This would go along nicely with rbfu's design goal to pretty much do as little as possible. It will still happily read .rbfu-version and .ruby-version files, of course; just not automatically after cd'ing into a new directory.

mpapis commented Feb 27, 2012

@hmans I helped in implementing parts of autoenv, and it has few issues:

  1. it requires authorization of the file like .rvmrc - which is one of the confusing points and why .rbenv-version was created in first place
  2. it is just an shell script not standardizing anything at all you would need to put there case statements to detect which manager is available.
  3. the tests are not maintained and not connected to - so you can not expect it will be always functional as it should be kennethreitz/autoenv#13

mpapis commented Mar 3, 2012

to keep track of things sstephenson/rbenv#199

mpapis commented Mar 8, 2012

and another proposal ;) carlhuda/bundler#1709

mpapis commented Mar 9, 2012

I just implemented the comment support for Gemfiles, so when there is no other format rvm will try to read:


from Gemfile and if you have in ~/.rvmrc:


rvm will also install bundler if not available and always run bundle install

it's very fast with the new bundler-1.1

It starts to be fun: rvm/rvm@577e53c

hmans commented Mar 9, 2012

Quick update regarding rbfu: I've hardened the support for .ruby-version, added some documentation about it (in fact, suggesting people use .ruby-version instead of .rbfu-version), and will blog about the effort to get this added to RVM and rbenv once I release 0.3.0 (which may be some time this weekend.)

I've sort of lost track, has anyone actually submitted a pull request for this to rbenv yet?

Regarding documenting the Ruby version on Gemfile, I'm sorry to say that I'm not a big fan. Gemfile and Bundler don't need to know about Ruby versions, and I'm pretty sure that the maintainers of Bundler aren't going to make this yet another Ruby version manager, so I'm passing on this idea for now.


fnichol commented Mar 9, 2012

@hmans That's great news indeed! There is an open issue and a pull request for rbenv but I'd bet that the dev team has been slammed getting out the door this week. I'm sure we'll hear from Sam and gang once they're back into GitHub issue triage.

mpapis commented Mar 9, 2012

@hmans so yo uare right and there is no place for ruby-version in Gemfile / bundler

but I was talking with @evanphx and he liked this proposal and it most likely will make it's way to the new format replacement of Gemfile in rubygems 2

my opinion on this is that we can fit the information for the project in one place - so if the new format supports custom fields you can add more information - whatever you need to make it working

as for RVM we have release planned around end of the month and I will have documentation updated for it in the last week of March

trans commented Apr 12, 2012

Could someone explain to me why you would want to nail a project down to a single install of ruby anyway?

When I work on projects I use the default ruby I setup in my home config and that's it. CI testing checks the other versions.


fnichol commented Apr 12, 2012

@trans I agree with you most of the time, although I make an exception for Rails/Sinatra applications. Unless it's an OSS app (like GitLab, Errbit, etc.), I'm most likely targeting a Ruby version in production. If nothing else it's an additional piece of project documentation. Otherwise, yeah I love to target all the rubies!

hmans commented Jun 27, 2012

FWIW, I've just tagged and released rbfu 0.3.0, probably the last 0.x version before I tag a 1.0.0 and have another go at courting the Homebrew guys to include the rbfu formula.

chruby 0.3.0 will support optional auto-switching, which will use the .ruby-version file. However, chruby will allow .ruby-version to contain sub-strings of the fully qualified Ruby name (ex: jruby or ruby-1.9).

chruby 0.3.0 has been released, so chruby now supports .ruby-version as well. 🍰

@fnichol can we add a small section on the contents of .ruby-version. I think .ruby-version may contain a sub-string that is fuzzy-matched against available Rubies. This would allow developers to specify jruby or ruby-1.9, and avoid specifying the exact version.

mislav commented Dec 30, 2012

rbenv is going to support .ruby-version, but definitely without any fuzzy matching. Here's why I think fuzzy matching is a bad idea:

  1. Let's suppose I have 1.9.3-p0 installed.
  2. I put "ruby-1.9" to .ruby-version in my project and all is well.
  3. After some time I install 1.9.3-p300 to try it out and suddenly all my projects marked with "ruby-1.9" automatically upgrade to it. Gems need to be reinstalled, native extensions need to be upgraded, etc. Nightmare.

One of the important reasons why we have version managers is to be precise about versions. rbenv is going to be precise. If you want cute shortcuts & aliases, you can always make symlinks.


fnichol commented Dec 31, 2012

@postmodern Cheers on getting 0.3.0 out the door, one more on board!


fnichol commented Dec 31, 2012

@mislav I can get behind the reasoning for this here and I largely agree with you for the same reasons I would commit a Gemfile.lock to a web application (vs. a gem library).

It looks like the active branch for .ruby-version in rbenv is being tracked in sstephenson/rbenv#302, looks pretty solid and complete to me.

cgriego commented Jan 23, 2013

I'd love to see Heroku adopt this emerging standard.

pedz commented Jan 26, 2013

My approach is to have a per project rc file. I call mine .prvmrc and it is simply sourced e.g. . .prvmrc (kept at the top directory of the project)

This way it can have any shell commands you want. Normally it sets PATH, GEM_HOME, and GEM_PATH but it can also set the postgresql database default, etc. It does not set PATH directly but rather calls some shell functions. So, the weight is a few rather small shell functions added to the shell's profile.

I also have my bundler put the gems and bin in the .bundle subdir of the project so the front of the path becomes the path to the directory plus .bundle/bin. e.g. PATH=/path/to/app/.bundle/bin:/usr/local/bin:/usr/bin:...

There are no shims involved. .bundle/bin is seeded with symlinks to the original commands and the symlinks are over written as the gems (e.g. rake) are updated into the local project.

Is there a convention for comments in a .ruby-version file?

@mpapis Does RVM currently support reading .ruby-version?

I realized you have a commit for this issue wayneeseguin/rvm#786

But I just could not find the docs from

rweng commented Mar 16, 2013

@leomao10 just tested w/ rvm 1.18.20 and it works

Just a note. Seems like RVM 1.18.21 now generates two files when rvm --create --ruby-version use ruby-1.9.3-p392@my_project is run. The files are .ruby-version and .ruby-gemset.

terlar commented Mar 23, 2013

fry (fish ruby switcher) is also supporting this if you enable auto-switching, it comes with fuzzy matching and ruby- prefixed is matched against non-ruby prefixed rubies.

# Fuzzy
ruby-1.9 => 1.9.3-p392
1.9 => 1.9.3-p392
jruby-1.7 => jruby-1.7.3

# Non-fuzzy
ruby-1.9.3-p392 => 1.9.3-p392
1.9.3-p392 => 1.9.3-p392
jruby-1.7.3 => jruby-1.7.3

@terlar nice to see another Ruby switcher supporting fuzzy matching. Specifying the fully qualified version is over-kill in most cases.

Guys, :+1 now only - don't complicated any more, and I certainly don't like the idea of just saying "jruby", will break on updates for granted. ;)

mpapis commented Aug 10, 2013

RVM (head/1.22.0) now supports also .ruby-env for setting environment variables when entering project directory, more details here:

swrobel commented Aug 3, 2014

@fnichol Can this be updated with a clear spec for the agreed-upon .ruby-version file format since all of the version managers seem to link to this page like it provides a spec?

zw963 commented Oct 10, 2014

rbenv is not support specify 2.1 in .ruby-version, But rvm can auto use the latest ruby version which match
2.1 serious.

e.g. if you have ruby 2.1.2 installed, and project root exist .ruby-version, content is 2.1, rbenv is halted,
but rvm can auto use 2.1.2. it you install 2.1.3 with rvm, it auto use 2.1.3 too.

Some user not using MRI may hope that engine version can be specified, like


However, I do not think it wise to save all the environment variables in this file. They should be in some separate file, says, .env. The .ruby-version should only specifies the Ruby version as named.

@mpapis Can we have fuzzy matching in RVM as well? "2.3.0" -> "2.3.0-preview2"? So that I dont have to keep changing the name as it matures. Was this removed recently? I swear it was working until a day or 2 ago. This is for both gemfile and .ruby-version

This is needed because with Gemfile, Bundler checks against RUBY_VERSION if it matches

    Your Ruby version is 2.3.0, but your Gemfile specified 2.3.0-preview2

Right now I have 2.3.0-preview2 to make rvm happy in.ruby-version and 2.3.0 in Gemfile to make bundler happy

@ktaragorn I guess you should specify the patch level with :patchlevel => 'preview2'.

It’s also possible to restrict the patchlevel of the Ruby used by doing the following:

ruby '1.9.3', :patchlevel => '448'

so you can have the exact version in both .ruby-version and Gemfile.

g13013 commented Oct 10, 2016

@mislav your explanation about fuzzy matching upsets me a little bit, developers are adults and they know how to deal with version problems, supporting fuzzy versions will allow teams to chose whatever fits theres needs, if "paranoid" people like you still want to be very careful about the version they use, they still have the possibility to force the exact version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment