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? 🤦‍♂️

9
  • You access that log file the same way you access any file; are you having issues with the shell? Feb 9, 2021 at 23:33
  • no, it's just when I try to find it my terminal says it doesn't exist. I think I'm just not sure where the root of this directory starts from
    – Richard
    Feb 10, 2021 at 0:52
  • It's an absolute path. Feb 10, 2021 at 0:53
  • ok, thanks. The log is very large, ~13000 lines. I don't see anything out of the ordinary though. Then again not sure where to look
    – Richard
    Feb 10, 2021 at 1:04
  • Towards the end. Feb 10, 2021 at 1:17

7 Answers 7

24

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

7
  • 2
    Thanks - this worked for me on a M1 with MacOS 12.2.1 and Ruby 2.6.6.
    – CanuckT
    Mar 12, 2022 at 14:29
  • 2
    Thanks, worked like a charm. Monterey 12.3.1 installing ruby 2.4.2 (M1 mac). Apr 15, 2022 at 11:04
  • Also worked to install 2.7.0 on M1 mac running Monterey 12.3.1 Jun 8, 2022 at 9:20
  • ah, scratch that, using Enumerator::Lazy causes a segmentation fault :'< Jun 8, 2022 at 9:39
  • 1
    Got the "Build failed" error w/ Last 10 log lines: ../.././include/ruby/ruby.h:1755:56: note: expanded from macro 'rb_intern' extension (RUBY_CONST_ID_CACHE((ID), (str))) : \ Oct 8, 2022 at 20:23
19

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.

8
  • 2
    I tried all these steps but got the same error unfortunately.
    – MeV
    Mar 3, 2021 at 17:36
  • It seems you need to put arch -x86_64 before every command for utilities installed this way.
    – Dan Engel
    Mar 11, 2021 at 5:15
  • 2
    This worked for me - 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 8, 2021 at 0:56
  • 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 and here) I'm on an M1, and Ruby 2.6.7 was failing, but Ruby 2.7.3 worked fine.
    – Yarin
    May 21, 2021 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, 2021 at 9:46
8

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

brew install readline openssl
rbenv install 2.7.2
4
  • 2
    are you able to install other versions of Ruby?
    – Richard
    Mar 25, 2021 at 14:36
  • 1
    Works really well, other options and conversation on github didn't work for me
    –  vrnvorona
    Aug 11, 2021 at 8:42
  • I got the same error on macos Monterey when running rbenv install 2.5.1
    – Marty
    Dec 1, 2021 at 18:24
  • Tried this, did not work for me. Monterey 12.3.1 installing ruby 2.4.2 (M1 mac). @abhinandan answer worked though. Apr 15, 2022 at 11:00
2

This worked for me

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3
1
  • 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.
    – Community Bot
    Mar 29, 2023 at 0:16
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

0

BUILD FAILED (macOS 14.0 on arm64 using ruby-build 20231107) I've got this error on MacOS Sonoma running on my Macbook Air M1

instead of using - rbenv install 2.7.4 (I was trying to install version 2.7.4)

Use RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.7.4

then use rbenv global 2.7.4

1
  • 2
    I tried but got error BUILD FAILED (macOS 14.0 using ruby-build 20221025) Nov 15, 2023 at 10:47
0

For me to make it work ( mac m1 Ventura ):

  1. Create alias brew for x86_64 ( edit file .zshrc )
alias ibrew='arch --x86_64 /usr/local/Homebrew/bin/brew'
  1. Run brew install lib ( ibrew is alias for brew of x86_64 intel )
ibrew install readline
ibrew install libyaml
  1. Export path in .zshrc file
export CFLAGS="-Wno-error=implicit-function-declaration"
export RUBY_CONFIGURE_OPTS="--with-readline-dir=$(ibrew --prefix readline) --with-libyaml-dir=$(ibrew --prefix libyaml)"
  1. Install ruby
arch -x86_64 rbenv install 3.1.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.