Ruby:构建失败(macOS 11.2 使用 ruby​​-build 20210119)Mac Big Sur

Ric*_*ard 6 ruby macos

在 macOS Big Sur 中查看了此Ruby 安装 (2.2.2) 失败

我的 macOS 是 Big Sur,我拥有的版本是 11.2,它是我能找到的最接近我的操作系统问题的版本,我尽我所能尝试

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3
Run Code Online (Sandbox Code Playgroud)

并且

RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.3
Run Code Online (Sandbox Code Playgroud)

这是我终端中的输出:

Downloading openssl-1.1.1i.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
Installing openssl-1.1.1i...
Installed openssl-1.1.1i to /Users/richard/.rbenv/versions/2.5.3

Downloading ruby-2.5.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.bz2
Installing ruby-2.5.3...

WARNING: ruby-2.5.3 is nearing its end of life.
It only receives critical security updates, no bug fixes.

ruby-build: using readline from homebrew
/opt/homebrew/bin/ruby-build: line 1121: 31528 Killed: 9               "$RUBY_BIN" -e '
    manager = ARGV[0]
    packages = {
      "apt-get" => Hash.new {|h,k| "lib#{k}-dev" }.update(
        "openssl" => "libssl-dev",
        "zlib" => "zlib1g-dev"
      ),
      "yum" => Hash.new {|h,k| "#{k}-devel" }.update(
        "yaml" => "libyaml-devel"
      )
    }

    failed = %w[openssl readline zlib yaml].reject do |lib|
      begin
        require lib
      rescue LoadError
        $stderr.puts "The Ruby #{lib} extension was not compiled."
      end
    end

    if failed.size > 0
      $stderr.puts "ERROR: Ruby install aborted due to missing extensions"
      $stderr.print "Try running `%s install -y %s` to fetch missing dependencies.\n\n" % [
        manager,
        failed.map { |lib| packages.fetch(manager)[lib] }.join(" ")
      ] unless manager.empty?
      $stderr.puts "Configure options used:"
      require "rbconfig"; require "shellwords"
      RbConfig::CONFIG.fetch("configure_args").shellsplit.each { |arg| $stderr.puts "  #{arg}" }
      exit 1
    end
  ' "$(basename "$(type -p yum apt-get | head -1)")" 1>&4 2>&1

BUILD FAILED (macOS 11.2 using ruby-build 20210119)

Inspect or clean up the working tree at /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210209143521.94730.xfFT9O
Results logged to /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210209143521.94730.log

Last 10 log lines:
installing bundled gems:            /Users/richard/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0 (build_info, cache, doc, extensions, gems, specifications)
                                    power_assert 1.1.1
                                    net-telnet 0.1.1
                                    did_you_mean 1.2.0
                                    xmlrpc 0.3.0
                                    rake 12.3.0
                                    minitest 5.10.3
                                    test-unit 3.2.7
installing rdoc:                    /Users/richard/.rbenv/versions/2.5.3/share/ri/2.5.0/system
installing capi-docs:               /Users/richard/.rbenv/versions/2.5.3/share/doc/ruby
Run Code Online (Sandbox Code Playgroud)

对于上面提到的两个命令,我都收到此错误,并且都给出了相同的输出。Ruby 的版本似乎也无关紧要,我也尝试过 3.0.0 并得到相同的结果。

此外,这是我尝试安装 ruby​​ 时的原始输出 rbenv install

Downloading openssl-1.1.1i.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
Installing openssl-1.1.1i...
Installed openssl-1.1.1i to /Users/richard/.rbenv/versions/2.5.3
Downloading ruby-2.5.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.bz2
Installing ruby-2.5.3...
WARNING: ruby-2.5.3 is nearing its end of life.
It only receives critical security updates, no bug fixes.
ruby-build: using readline from homebrew
BUILD FAILED (macOS 11.2 using ruby-build 20210119)
Inspect or clean up the working tree at /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210209143107.60561.YqaRpk
Results logged to /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210209143107.60561.log
Last 10 log lines:
compiling ../.././ext/psych/yaml/reader.c
compiling ../.././ext/psych/yaml/emitter.c
compiling ../.././ext/psych/yaml/parser.c
linking shared-object json/ext/generator.bundle
5 warnings generated.
linking shared-object date_core.bundle
linking shared-object zlib.bundle
1 warning generated.
linking shared-object psych.bundle
make: *** [build-ext] Error 2
Run Code Online (Sandbox Code Playgroud)

xcode-select 版本是 2384。Homebrew
版本是 3.0.0 并且brew doctor说我准备好了。

我的 .zshrc 文件也包含这一行 eval "$(rbenv init -)"

在这一点上,我不确定还可以在哪里查看如果您想在日志文件中看到任何细节,请告诉我从哪里开始,日志文件太大,无法在此处共享。为什么会发生这种情况,我该如何解决????

Abh*_*aha 24

在安装 rbenv 时,我在MacOS Monterey 12.2(M1 Pro 芯片)上遇到了同样的问题。这个解决方案对我有用 -

而不是运行这个- rbenv install 2.5.3

运行这个- RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3

  • 谢谢 - 这对我在 MacOS 12.2.1 和 Ruby 2.6.6 的 M1 上有效。 (2认同)
  • 谢谢,很有魅力。蒙特雷 12.3.1 安装 ruby​​ 2.4.2 (M1 mac)。 (2认同)

Ric*_*ard 10

这不是官方解决方案。我确信 rbenv 开发人员正在研究一个实际的解决方案,但这种解决方法应该可以帮助其他人在 Mac 的新 M1 芯片上设置他们的 ruby​​ 环境。

  • 确保您的终端正在使用 Rosetta。您可以使用 Google 找到如何做到这一点。

  • rbenv按照这些说明卸载当前的删除 rbenv。如果您有任何(减去系统默认值)位于/Users/<your user name>/.rbenv/versions/.

  • 使用以下命令卸载 ARM 版本的 Homebrew: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

  • 使用以下命令安装 x86_64 版本的 Homebrew: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  • 如果你运行brew install rbenv应该产生输出说“错误:无法在英特尔默认前缀 (/usr/local) 的 ARM 处理器上的 Homebrew 中安装!”。这是预期的。

  • 您想告诉 brew 安装旧架构 x86_64 arch -x86_64 brew install rbenv

  • 然后最后安装您想要使用的版本arch -x86_64 rbenv install x.x.x(x = 某个数字,即 2.7.2)

从那里你只需要记住arch -x86_64在安装其他版本的 Ruby 时告诉 brew 。

一旦实际修复通过,您将能够切换回较新的体系结构,而不必使用该arch参数。您也不必一直使用 brew 执行此操作,只需使用 rbenv。

  • 我尝试了所有这些步骤,但不幸的是遇到了同样的错误。 (2认同)
  • 这对我有用 - https://brandur.org/fragments/ruby-3-on-m1 我最终使用 `RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)" \ rbenv install 2.7.3` 在执行别名之前。它抱怨别名,但还是安装了 (2认同)
  • 只是想指出,根据 rbenv 维护者的说法,Apple 的 M1 芯片不支持较旧的 Ruby 版本(2.5),但 Ruby 2.7.2+ 和 Ruby 3.0.0 是兼容的。(参见[此处](https://github.com/rbenv/ruby-build/issues/1705#issuecomment-759195374)和[此处](https://github.com/rbenv/ruby-build/issues/1705 #issuecomment-759442038)) 我使用的是 M1,Ruby 2.6.7 失败,但 Ruby 2.7.3 工作正常。 (2认同)

Mes*_*NEŞ 8

readline openssl安装后我能够安装 Ruby 2.7.2

brew install readline openssl
rbenv install 2.7.2
Run Code Online (Sandbox Code Playgroud)

  • 你能安装其他版本的 Ruby 吗? (2认同)