简体   繁体   中英

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?

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

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.

I referred this CircleCI docs and created a file .ruby-version that explicitly stated the version to be used ie 2.4.4 and it works. The content was

2.4.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM