首页 文章

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

提问于
浏览
10

试着跑

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

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

所以我假设这里的问题是 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'.

5 回答

  • 0
    • brew更新

    • brew install ruby-build

    • brew安装rbenv

    • rbenv install [version_required]

    • rbenv global [version_required]

  • 11

    您的选择似乎要么使用

    brew update
    brew install whatever
    

    要么

    HOMEBREW_NO_AUTO_UPDATE=1 brew install whatever
    

    travis documentation中的建议不要 brew update 如果它没有't seem to be needed seems to leave you at risk of random breakage when brew'的ruby要求被改变了......

  • 8

    对于.NET Core项目:您可以通过不使用Travis ' default .NET Core but installing it using the Microsoft'的.NET核心sh脚本来避免使用brew . 我以前设置了 monodotnet 版本定义,切换到sh脚本后我发现这些定义是不需要的 . 通过删除这两个定义,我能够修复 Homebrew must be run under Ruby 2.3! 错误(尽管我在进行.NET核心安装之前必须在Linux上更新 libunwind8 ) .

    这是在osx和linux上运行.NET核心项目测试的完整.travis.yaml .

    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
    
  • 2

    我成功地在macOS中更改了Homebrew的Ruby版本,在GitHub上创建了一个个人访问令牌,并在我的Mac上将其设置为:

    https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew

    然后设置令牌:

    export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
    

    如果您已经设置了此令牌,则可以使用以下命令清除它们:printf“protocol = https \ nhost = github.com \ n”| git credential-osxkeychain erase

  • 0

    brew install package_name 之前运行 brew update

相关问题