ruby-build: Ruby 2.2.2 build fail error on macOS 11.1

Hello there! (And, Happy New Year!) I hope I am posting this in the right place! 🙏

I am trying to install Ruby 2.2.2 on macOS 11.1 for a project, but am running into the following error when running:

rbenv install 2.2.2

Error:

Downloading openssl-1.0.2u.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16
Installing openssl-1.0.2u...
Installed openssl-1.0.2u to /Users/findum/.rbenv/versions/2.2.2

Downloading ruby-2.2.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.bz2
Installing ruby-2.2.2...

WARNING: ruby-2.2.2 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201225)

Inspect or clean up the working tree at /var/folders/x8/g8yqvrh55gq0wds4hny1t94r0000gn/T/ruby-build.20210101111906.42540.uFRvAN
Results logged to /var/folders/x8/g8yqvrh55gq0wds4hny1t94r0000gn/T/ruby-build.20210101111906.42540.log

Last 10 log lines:
compiling ../.././ext/psych/yaml/parser.c
linking shared-object json/ext/parser.bundle
linking shared-object pathname.bundle
installing default psych libraries
linking shared-object json/ext/generator.bundle
linking shared-object bigdecimal.bundle
linking shared-object psych.bundle
linking shared-object nkf.bundle
linking shared-object date_core.bundle
make: *** [build-ext] Error 2

I have tried the workarounds in issue #1353 and have downloaded OpenSSL 1.0 on my system, but still no luck! Has anyone had a similar issue that they were able to resolve? Many thanks 🙏

UPDATE

Solution:

$ CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.2.2

https://github.com/rbenv/ruby-build/issues/1489#issue-741155490

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 28 (2 by maintainers)

Most upvoted comments

Thank you @eveevans and @mrmanc the following worked for me:

export optflags="-Wno-error=implicit-function-declaration"
rbenv install 2.1.2

I know that this is a rbenv post. But I want to comment that I was able to install an old Ruby (2.3.8) on my M1 with Big Sur 11.1, running XCode 12.3 with RVM using the following commands:

rvm pkg install openssl
export optflags="-Wno-error=implicit-function-declaration"
rvm install ruby-2.3.8 --with-openssl-dir=$HOME/.rvm/usr --rubygems ignore
  1. This install old openSSL as independent dependency (not used for the system)
  2. Change a flag that (I think) was changed on XCode 12
  3. Install Ruby using the openSSL dependency from RVM (not from the system)

This is interesting. It seems to have gotten pretty far and perhaps is just failing in some final symlinking step due to a badly named file -darwin20-fake.rb?

On Ruby 2.6 I’m seeing RUBY_PLATFORM return -darwin21 instead of arm64-darwin21 – it’s otherwise building successfully with arm64 (after I add RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC):

$ file $(rbenv which ruby)
[...]/.rbenv/versions/2.6.5/bin/ruby: Mach-O 64-bit executable arm64

But then:

$ ruby -e "puts RUBY_PLATFORM"
-darwin21

So the the “badly named file” (-darwin20-fake.rb) is likely because the architecture is showing up blank somewhere and leads to a platform string like -darwin20. Anyone know how that string gets set and if it can be fixed at build time (or at runtime even)?

It isn’t exactly the same issue, but I wanted to share that the solution shared by @eveevans which set optflags solved the problem I was having running rbenv install 2.7.1. Setting CFLAGS did not work for me.

But if i’m understanding your code you’re actually building for x86 using rosetta, no?

 arch -x86_64

The following worked for me:

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS='--with-readline-dir=/usr/local/opt/readline/' arch -x86_64 rbenv install 2.2.2

I know that this is a rbenv post. But I want to comment that I was able to install an old Ruby (2.3.8) on my M1 with Big Sur 11.1, running XCode 12.3 with RVM using the following commands:

rvm pkg install openssl
export optflags="-Wno-error=implicit-function-declaration"
rvm install ruby-2.3.8 --with-openssl-dir=$HOME/.rvm/usr --rubygems ignore
  1. This install old openSSL as independent dependency (not used for the system)
  2. Change a flag that (I think) was changed on XCode 12
  3. Install Ruby using the openSSL dependency from RVM (not from the system)

thanks a lot, worked for me.

Is there a consensus here on whether 2.2.2 can indeed be built on M1 Silicon with ARM? I’m seeing the following error on install:

config.status: creating -darwin20-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20-fake.rb
make: *** [-darwin20-fake.rb] Error 64

after trying https://github.com/rbenv/ruby-build/issues/1700#issuecomment-799541819

brew install readline rbenv
arch -arm64 brew install rbenv/tap/openssl@1.0

# add the following to ~/.zshrc
eval "$(rbenv init -)"
# rbenv install recommends this with ruby-build
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)"

optflags="-Wno-error=implicit-function-declaration" rbenv install 2.2.2

Are we just not able to build this version of ruby for ARM and have to use Rosetta?