2017-10-10 52 views
9

試圖在before_install運行如何在Travis CI中的MacOS中更改Homebrew的Ruby版本?

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

,我結束了

/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 

所以我認爲這裏的問題是,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'. 
+0

我有一個類似的問題安裝mutt。我正在閱讀以下內容,不知道是否相關https://discuss.circleci.com/t/homebrew-must-be-run-under-ruby-2-3-runtimeerror/17232/6 –

+0

看起來像你正在使用rvm來管理Ruby的版本。是對的嗎? – zee

回答

10

您的選擇似乎是要麼使用

brew update 
brew install whatever 

HOMEBREW_NO_AUTO_UPDATE=1 brew install whatever 

的在travis documentation的建議不要做brew update如果它似乎不是ne當brew的ruby需求發生變化時,eded似乎給你帶來了隨機破壞的風險...

2

對於.NET Core項目:您可以避免在不使用Travis的默認.NET Core的情況下使用brew,而應使用Microsoft安裝它。 NET核心sh腳本。我曾經有monodotnet版本定義集,我發現在切換到sh腳本後不需要。我可以通過刪除這兩個定義來修復Homebrew must be run under Ruby 2.3!錯誤(雖然在安裝.NET核心之前,我必須在Linux上更新libunwind8)。

下面是完整的.travis.yaml,用於在osx和linux上運行.NET核心項目測試。

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 
+1

我可以用--version 2.0.0來證實這一點,因爲我的項目需要2.0 .NET Core SDK。感謝分享這個解決方案。 –

7
  • 釀造更新
  • 沖泡安裝紅寶石打造
  • 釀造安裝rbenv
  • rbenv安裝[version_required]
  • rbenv全球[version_required]