Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the ruby version in circleCI?

I am using circleCI for CI with the following .yml file

version: 2
jobs:
  build:
    machine:
      ruby:
        version: 2.4.4
    steps:
      - checkout
      - run: bundle install
      - run: echo "hello"

The error message is

Your Ruby version is 2.3.3, but your Gemfile specified 2.4.4
Your Ruby version is 2.3.3, but your Gemfile specified 2.4.4

My Gemfile is

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.4.4'

What is the proper way to set ruby version?

like image 450
Harshit Garg Avatar asked Jan 03 '23 09:01

Harshit Garg


2 Answers

It looks like you are using CircleCI 2 but you're setting the ruby version using the CircleCI 1 way.

As stated in this documentation, to set the ruby version in Circle CI 2, you can either create a .ruby-version file in your rails app and commit the file or you can create it from a build step:

run:
  name: Set Ruby Version
  command:  echo "ruby-2.4.4" > ~/.ruby-version
like image 109
e_a_o Avatar answered Jan 04 '23 23:01

e_a_o


disclaimer: I'm a CircleCI Developer Advocate

Your config example is mixing CircleCI 2.0 and 1.0 config syntax and this is causing the issue.

If you want to use Ruby 2.4.4 in a CircleCI 2.0 build and you want to use our premade Docker image, then your config should look like this:

version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.4
    steps:
      - checkout
      - run: bundle install
      - run: echo "hello"

The above example is for the Linux environment. If you're doing macOS builds, then @e_a_o's answer will help you there.

like image 37
FelicianoTech Avatar answered Jan 04 '23 22:01

FelicianoTech