Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Ruby version for Homebrew in macOS in Travis CI?

Trying to run

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi

in before_install, I end up with

/usr/local/Homebrew/Library/Homebrew/brew.rb:12:in \`<main>': Homebrew must be run under Ruby 2.3! (RuntimeError)  

The command "if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi" failed and exited with 1 during .

Your build has been stopped.

/Users/travis/.travis/job_stages: line 166: shell_session_update: command not found  

So I assume the issue here is that ruby is on version 2.0, which I confirmed with ruby --version. The funny thing is, my builds just stopped working all of the sudden, without any change to .travis.yml.
So how do I actually change Ruby versions?

Might be important to not, that before git clone is run I get this:

$ rvm use

Warning! PATH is not properly set up, '/Users/travis/.rvm/gems/ruby-2.0.0-p648/bin' is not at first place,

         usually this is caused by shell initialization files - check them for 'PATH=...' entries,

         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',

         to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p648'.
like image 485
One Normal Night Avatar asked Oct 10 '17 15:10

One Normal Night


4 Answers

Your choices seem to be to either use

brew update
brew install whatever

or

HOMEBREW_NO_AUTO_UPDATE=1 brew install whatever

The advice in travis documentation to not do a brew update if it doesn't seem to be needed seems to leave you at risk of random breakage when brew's ruby requirement is changed...

like image 62
jturney Avatar answered Oct 02 '22 16:10

jturney


running brew update before brew install package_name

like image 27
venna Avatar answered Oct 02 '22 15:10

venna


  • brew update
  • brew install ruby-build
  • brew install rbenv
  • rbenv install [version_required]
  • rbenv global [version_required]
like image 23
lexisvar Avatar answered Oct 02 '22 15:10

lexisvar


For .NET Core projects: you can avoid using brew by not using Travis' default .NET Core but installing it using the Microsoft's .NET core sh script. I used to have mono and dotnet version definitions set which I've found were not needed after switching to the sh script. I was able to fix the Homebrew must be run under Ruby 2.3! error by removing those two definitions (although I then had to update libunwind8 on Linux before doing the .NET core install).

Here's the complete .travis.yaml for running .NET core project test on osx and linux.

language: csharp

before_install:
  - if [ "$OS" = "linux" ]; then sudo apt-get install libunwind8; fi

script:
  - wget https://dot.net/v1/dotnet-install.sh && chmod +x dotnet-install.sh
  - ./dotnet-install.sh --version 1.1.4 --install-dir $HOME/.dotnet
  - $HOME/.dotnet/dotnet restore
  - $HOME/.dotnet/dotnet test YOUR_CSPROJ_FILE_PATH

matrix:
  include:
    - os: linux
      dist: trusty
      env: OS=linux
    - os: osx
      osx_image: xcode9
      env: OS=osx

branches:
  only:
    - master
like image 32
Rok Povsic Avatar answered Oct 02 '22 15:10

Rok Povsic