如何在Travis CI中更改macOS中的Homebrew Ruby版本?

One*_*ght 10 ruby macos homebrew travis-ci

试着跑

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi
Run Code Online (Sandbox Code Playgroud)

before_install,我最终

/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  
Run Code Online (Sandbox Code Playgroud)

所以我认为这里的问题是ruby版本2.0,我确认了ruby --version.有趣的是,我的构建突然停止工作,没有任何改变.travis.yml.
那么我该如何实际更改Ruby版本呢?

可能重要的是,在git clone运行之前,我得到这个:

$ 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'.
Run Code Online (Sandbox Code Playgroud)

jtu*_*ney 11

您的选择似乎要么使用

brew update
brew install whatever
Run Code Online (Sandbox Code Playgroud)

要么

HOMEBREW_NO_AUTO_UPDATE=1 brew install whatever
Run Code Online (Sandbox Code Playgroud)

如果看起来似乎不需要,travis文档中的建议brew update如果不做,那么当brew的ruby需求发生变化时,这会让你面临随机破损的风险......


小智 9

  • brew更新
  • brew install ruby​​-build
  • brew安装rbenv
  • rbenv install [version_required]
  • rbenv global [version_required]