# Support Ruby version in Gemfile

**URL:** <https://travis-ci.community/t/support-ruby-version-in-gemfile/6898>\
**Category:** Ruby\
**Created:** [January 17, 2020, 10:34am UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898 "2020-01-17T10:34:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [January 17, 2020, 10:34am UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/1 "2020-01-17T10:34:24Z")

</div>

RVM can read required Ruby version from `Gemfile`.

[https://rvm.io/workflow/projects#project-file-gemfile](https://rvm.io/workflow/projects#project-file-gemfile)

But Travis ignores it.

[https://travis-ci.org/minsk-hackerspace/hackerspace.by/builds/637122932#L190](https://travis-ci.org/minsk-hackerspace/hackerspace.by/builds/637122932#L190)

Is it possible to add the support for it?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 17, 2020, 1:11pm UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/2 "2020-01-17T13:11:11Z")

</div>

We do not fetch `Gemfile` when we receive the build request, only `.travis.yml`. So `.travis.yml` has to instruct us which Ruby version to use.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 17, 2020, 1:13pm UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/3 "2020-01-17T13:13:28Z")

</div>

Well, this is not entirely accurate. You can use [`.ruby-version`](https://docs.travis-ci.com/user/languages/ruby#using-ruby-version).

---

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [January 18, 2020, 4:06pm UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/4 "2020-01-18T16:06:04Z")

</div>

Actually I discovered that I can add Ruby version to `Gemfile` while troubleshooting [the problem with `.ruby-version`](https://travis-ci.community/t/travis-cannot-find-a-ruby-2-5-0-from-ruby-version/6853).

If Ruby version is not specified explicitly, why not let RVM choose Ruby version [like it does locally](https://rvm.io/workflow/projects)? Then it will not be necessary to maintain additional integration code.

I believe this default command prevents `rvm` from looking into `Gemfile`.

```auto
$ rvm use default

```

If it can be replaced with command that triggers default `rvm` behavior, then in presence of `.ruby-version` the following will be unnecessary too.

```auto
rvm use $(< .ruby-version) --install --binary --fuzzy

```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [January 18, 2020, 6:45pm UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/5 "2020-01-18T18:45:32Z")

</div>

> [@abitrolly](#):
>
> I believe this default command prevents `rvm` from looking into `Gemfile` .
> 
> ```auto
> $ rvm use default
> 
> ```

No, RVM shell integration is responsible for automatic version switch when you work locally. It overrides `cd`:

```auto
$ git clone https://github.com/travis-ci/dpl
<...>
$ cd dpl/
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 /home/vmuser/dpl/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

Unknown ruby interpreter version (do not know how to handle): >=2.2.
$ declare -f cd
cd () 
{ 
    __zsh_like_cd cd "$@"
}
$ grep ~ -rFe __zsh_like_cd
<...>
/home/vmuser/.rvm/src/rvm/scripts/extras/bash_zsh_support/chpwd/function.sh:function __zsh_like_cd()
<...>

```

---

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [January 20, 2020, 11:14am UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/6 "2020-01-20T11:14:30Z")

</div>

Is it possible to call `rvm` to just detect the version?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [January 22, 2020, 8:57am UTC](https://travis-ci.community/t/support-ruby-version-in-gemfile/6898/7 "2020-01-22T08:57:30Z")

</div>

[From what I can see](https://travis-ci.org/native-api/test_travis/jobs/640328646), you can

```auto
source "$(dirname "$(which rvm)")/../scripts/rvm"

```

and it will autodetect the version.
