Ruby: BUILD FAILED (macOS 11.2 using ruby-build 20210119) Mac Big Sur
Asked Answered
M

7

20

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? πŸ€¦β€β™‚οΈ

Militarism answered 9/2, 2021 at 23:17 Comment(9)
You access that log file the same way you access any file; are you having issues with the shell? – Pinniped
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 – Militarism
It's an absolute path. – Pinniped
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 – Militarism
Towards the end. – Pinniped
yeah, you say that but there's nothing out of the ordinary, no error messages or warnings. How many lines should I show? The last 10 lines are printed in the output above, the other 50 are about the same – Militarism
Somewhere towards the end will be the cause of the error. – Pinniped
I face the same problem – Muckworm
Dave, here is a gist of the log gist.github.com/redferret/a0f08d1ee3704ad35d9e19964442351d – Militarism
M
21

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.

Militarism answered 17/2, 2021 at 23:8 Comment(8)
I tried all these steps but got the same error unfortunately. – Obadiah
It seems you need to put arch -x86_64 before every command for utilities installed this way. – Rebirth
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 – Anele
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 – Ottinger
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. – Ellora
@Ellora deleted their post, but it was the right answer for me: 2.7.3 on M1 Mac builds (and works). Thanks! – Bred
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 – Patterson
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 – Crossindex
A
25

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

Axletree answered 8/2, 2022 at 5:53 Comment(7)
Thanks - this worked for me on a M1 with MacOS 12.2.1 and Ruby 2.6.6. – Forenamed
Thanks, worked like a charm. Monterey 12.3.1 installing ruby 2.4.2 (M1 mac). – Smalls
Also worked to install 2.7.0 on M1 mac running Monterey 12.3.1 – Aksoyn
ah, scratch that, using Enumerator::Lazy causes a segmentation fault :'< – Aksoyn
Thanks. Where do people find solutions such as this. – Sera
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))) : \ – Idel
The solution that worked for me was installing openssl via brew and linking to it as per: github.com/rbenv/ruby-build/issues/377#issuecomment-21014365 – Geehan
M
21

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.

Militarism answered 17/2, 2021 at 23:8 Comment(8)
I tried all these steps but got the same error unfortunately. – Obadiah
It seems you need to put arch -x86_64 before every command for utilities installed this way. – Rebirth
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 – Anele
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 – Ottinger
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. – Ellora
@Ellora deleted their post, but it was the right answer for me: 2.7.3 on M1 Mac builds (and works). Thanks! – Bred
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 – Patterson
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 – Crossindex
S
8

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

brew install readline openssl
rbenv install 2.7.2
Swee answered 17/3, 2021 at 17:8 Comment(4)
are you able to install other versions of Ruby? – Militarism
Works really well, other options and conversation on github didn't work for me – Correll
I got the same error on macos Monterey when running rbenv install 2.5.1 – Patterson
Tried this, did not work for me. Monterey 12.3.1 installing ruby 2.4.2 (M1 mac). @abhinandan answer worked though. – Smalls
B
2

This worked for me

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3
Boldt answered 24/3, 2023 at 0:40 Comment(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. – Append
O
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

Orgeat answered 9/5, 2021 at 23:48 Comment(0)
B
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

Brawner answered 13/11, 2023 at 13:31 Comment(1)
I tried but got error BUILD FAILED (macOS 14.0 using ruby-build 20221025) – Debtor
N
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
Nashville answered 29/2 at 15:59 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.