19

I looked at this Ruby installation (2.2.2) fails in macOS Big Sur

My macOS is Big Sur and the version I have is 11.2 and it was the closest I could find to the issue I'm having with my OS, I followed what I could by trying

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3

and also

RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.5.3

This is the output in my Terminal:

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

I get this error for both commands mentioned above and both give this same output. The version of Ruby also doesn't seem to matter, I've tried 3.0.0 as well and get the same results.

Additionally this is the original output when I try to just install ruby with 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

xcode-select version is 2384.
Homebrew version is 3.0.0 and brew doctor say's I'm ready to brew.

My .zshrc file also contains this line eval "$(rbenv init -)"

At this point I'm not sure where else to turn If there is any specifics you want to see in the log file let me know where from, the log file is too big to share here. Why is this happening and how can I fix this? ‍♂️

Richard
  • 1,057
  • 1
  • 10
  • 22

5 Answers5

20

While installing rbenv, I faced the same issue on MacOS Monterey 12.2 (M1 Pro chip). This solution worked for me-

Instead of running this- rbenv install 2.5.3

run this- RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3

17

This is not an official solution. I'm sure the rbenv devs are working on an actual solution but this workaround should help others who are setting up their ruby environments on the new M1 chips for Mac.

  • Make sure your Terminal is using Rosetta. You can find how to do that using Google.

  • Uninstall your current rbenv following these instructions Removing rbenv. Be sure you also remove all the downloaded versions of ruby if you have any (minus the system default) located in /Users/<your user name>/.rbenv/versions/.

  • Uninstall the ARM version of Homebrew with: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

  • Install the x86_64 version of Homebrew with: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  • If you run brew install rbenv should produce output saying "Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!". This is expected.

  • You want to tell brew to install the older architecture x86_64 arch -x86_64 brew install rbenv

  • Then finally install the version you want using arch -x86_64 rbenv install x.x.x (x = some number i.e. 2.7.2)

From there you just need to remember to tell brew arch -x86_64 when installing other versions of Ruby.

Once an actual fix comes through you'll be able to switch back to the newer architecture and not have to use the arch argument. You also don't have to do this all the time with brew either, just rbenv.

eveevans
  • 4,392
  • 2
  • 31
  • 38
Richard
  • 1,057
  • 1
  • 10
  • 22
  • 2
    I tried all these steps but got the same error unfortunately. – MeV Mar 03 '21 at 17:36
  • It seems you need to put `arch -x86_64` before every command for utilities installed this way. – Dan Engel Mar 11 '21 at 05:15
  • 1
    This worked for me - https://brandur.org/fragments/ruby-3-on-m1 I ended up using `RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)" \ rbenv install 2.7.3` before doing the alias. It complained about the alias, but installed anyway – Joe May 08 '21 at 00:56
  • I have followed these instructions and I am now getting a different error, The Ruby openssl extension was not compiled. It looks for it on .rbenv/versions/3.0.1/openssl – Petran May 12 '21 at 15:04
  • 5
    Just want to point out that according to the rbenv maintainer older Ruby versions (2.5) are not supported by Apple's M1 chip, but Ruby 2.7.2+ and Ruby 3.0.0 are compatible. (SEE [here](https://github.com/rbenv/ruby-build/issues/1705#issuecomment-759195374) and [here](https://github.com/rbenv/ruby-build/issues/1705#issuecomment-759442038)) I'm on an M1, and Ruby 2.6.7 was failing, but Ruby 2.7.3 worked fine. – Yarin May 21 '21 at 22:36
  • 1
    @Yarin deleted their post, but it was the right answer for me: 2.7.3 on M1 Mac builds (and works). Thanks! – epologee May 26 '21 at 09:46
  • FWIW, I did step 1-4 as described. In the 5th step, I didn't get the error and it installed. So I skipped "arch -x86_64" in the 6th step and just ran rbenv install 2.5.1 and it worked. I assume this has to do with the first step as typing in "arch" in the Terminal shows i386 – Marty Dec 01 '21 at 18:46
  • Not sure if it was the command or version. But if you're reading this, try 2.7.3 first. The following command worked for me RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)" rbenv install 2.7.3 – iOS Blacksmith Jul 05 '23 at 13:41
8

I was able to install Ruby 2.7.2 after the readline openssl installation

brew install readline openssl
rbenv install 2.7.2
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49
1

I'm using rvm. I read and tried the solutions discussed here https://github.com/rvm/rvm/issues/5033.

However, the one that worked for me was rvm install "ruby-2.6.3" --with-out-ext=fiddle

In case you're using rbenv you can follow the discussion here

1

This worked for me

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '23 at 00:16