Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLUTION: Ruby 2.6.3 compilation error on OSX 14 (Sonoma) #5408

Open
igordelorenzi opened this issue Nov 16, 2023 · 10 comments
Open

SOLUTION: Ruby 2.6.3 compilation error on OSX 14 (Sonoma) #5408

igordelorenzi opened this issue Nov 16, 2023 · 10 comments

Comments

@igordelorenzi
Copy link

igordelorenzi commented Nov 16, 2023

Description

I went through a situation where I spent several hours understanding and resolving it. That's why I'm opening this issue as a public utility. (Solution is the last topic.)

Steps to reproduce

export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
rvm install ruby-2.6.3 --with-openssl-dir=$(brew --prefix openssl@1.1)

Expected behavior

It should compile and install for the arm64 architecture (Apple M1 Pro).

Actual behavior

For some reason that I'm not aware of, the compilation insists on using the openssl@3 library as you can see an excerpt from the make.log below. Giving more context, I have both openssl@1.1 and openssl@3 installed through HomeBrew as a dependency on several other packages.

...

compiling ossl_asn1.c
ossl.c:311:14: error: 'ERR_get_error_line_data' is deprecated [-Werror,-Wdeprecated-declarations]
        while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
                    ^
/opt/homebrew/Cellar/openssl@3/3.1.4/include/openssl/err.h:424:1: note: 'ERR_get_error_line_data' has been explicitly marked deprecated here
OSSL_DEPRECATEDIN_3_0

...

Full make.log: https://gist.github.com/igordelorenzi/236abb28c9e439f1890b8804d2df081a

Environment info


ruby-2.6.3:

  system:
    uname:        "Darwin Igors-MacBook-Pro.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 arm64"
    name:         "OSX"
    version:      "14.0"
    architecture: "arm64"
    bash:         "/bin/bash => GNU bash, version 3.2.57(1)-release (arm64-apple-darwin23)"
    zsh:          "/bin/zsh => zsh 5.9 (x86_64-apple-darwin23.0)"
    remote_path:  "osx/14.0/arm64"
    xcode:        "15.0.1"

  rvm:
    version:      "1.29.12-next (master)"
    updated:      "8 minutes 10 seconds ago"
    path:         "/Users/igordla/.rvm"
    autolibs:     "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."

  ruby:
    interpreter:  "ruby"
    version:      "2.6.3p62"
    date:         "2019-04-16"
    platform:     "-darwin23"
    patchlevel:   "2019-04-16 revision 67580"
    full_version: "ruby 2.6.3p62 (2019-04-16 revision 67580) [-darwin23]"

  homes:
    gem:          "/Users/igordla/.rvm/gems/ruby-2.6.3"
    ruby:         "/Users/igordla/.rvm/rubies/ruby-2.6.3"

  binaries:
    ruby:         "/Users/igordla/.rvm/rubies/ruby-2.6.3/bin/ruby"
    irb:          "/Users/igordla/.rvm/rubies/ruby-2.6.3/bin/irb"
    gem:          "/Users/igordla/.rvm/rubies/ruby-2.6.3/bin/gem"
    rake:         "/Users/igordla/.rvm/rubies/ruby-2.6.3/bin/rake"

  environment:
    PATH:         "/Users/igordla/.rvm/gems/ruby-2.6.3/bin:/Users/igordla/.rvm/gems/ruby-2.6.3@global/bin:/Users/igordla/.rvm/rubies/ruby-2.6.3/bin:/Users/igordla/.rvm/bin:/Users/igordla/.local/share/bin:/opt/homebrew/opt/php@7.4/sbin:/opt/homebrew/opt/php@7.4/bin:/Users/igordla/.yarn/bin:/Users/igordla/.nvm/versions/node/v18.18.0/bin:/Users/igordla/.local/bin:/Users/igordla/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/igordla/.local/share/bin:/opt/homebrew/opt/php@7.4/sbin:/opt/homebrew/opt/php@7.4/bin:/Users/igordla/.yarn/bin:/Users/igordla/.nvm/versions/node/v18.18.0/bin:/Users/igordla/.local/bin:/Users/igordla/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/igordla/.orbstack/bin:/Users/igordla/.orbstack/bin"
    GEM_HOME:     "/Users/igordla/.rvm/gems/ruby-2.6.3"
    GEM_PATH:     "/Users/igordla/.rvm/gems/ruby-2.6.3:/Users/igordla/.rvm/gems/ruby-2.6.3@global"
    MY_RUBY_HOME: "/Users/igordla/.rvm/rubies/ruby-2.6.3"
    IRBRC:        "/Users/igordla/.rvm/rubies/ruby-2.6.3/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

Solution

brew unlink openssl@3
rvm cleanup all
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
rvm install ruby-2.6.3 --with-openssl-dir=$(brew --prefix openssl@1.1)
brew link openssl@3
@igordelorenzi
Copy link
Author

igordelorenzi commented Nov 16, 2023

One caveat: for some reason the rvm list command is showing the 2.6.3 installation as broken (see below). However, I can use ruby normally (so far).

➜ rvm list
=> ruby-2.6.3 [ broken ]
 * ruby-3.0.0 [ arm64 ]
   ruby-3.0.6 [ arm64 ]
   ruby-3.2.0 [ arm64 ]

# => - current
# =* - current && default
#  * - default

Is there any way to know if the installation is really broken?

@mathieujobin
Copy link
Contributor

Curious, did you experience the same behavior with 2.6.9, 2.6.10 and 2.6.3 ?

@igordelorenzi
Copy link
Author

Curious, did you experience the same behavior with 2.6.9, 2.6.10 and 2.6.3 ?

@mathieujobin Same thing when installing 2.6.10.

@mathieujobin
Copy link
Contributor

Oh... You are trying to build ruby 2.6 with OpenSSL 3

You can't

There are patches but it's best to get OpenSSL 1.1
And tell the compiler to use that. I don't have the exact syntax right now but it's easy to find.

@mathieujobin
Copy link
Contributor

Oh, I just noticed the solution was already written in the updated description.

I guess you are all good then?

@igordelorenzi
Copy link
Author

Yeah, everything is fine! 👍

@nanego
Copy link

nanego commented Jan 3, 2024

I had to use different paths to make it work on my M1 laptop:

export LDFLAGS="-L/usr/local/opt/libffi/lib"
export CPPFLAGS="-I/usr/local/opt/libffi/include"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"

With these variables set, it finally works. Thank you!

@nivvyart
Copy link

nivvyart commented Apr 2, 2024

Felt like I tried 100 different things today and this finally worked, was able to install 2.6.3 and 2.6.6 via rvm.

M1 + Sonoma 14.3.1 (23D60)

Thanks so much!

@monfresh
Copy link

monfresh commented Apr 2, 2024

For anyone else trying to install Ruby 2.6.x where the "x" is less than 10, the first thing I always recommend is to update your Ruby project to at least 2.6.10. There is rarely a good reason to use a Ruby version where the patch version (the 3rd digit) is less than the latest one. In the 2.6.x series, the latest one is 2.6.10.

This is especially important on Apple Silicon Macs, which don't support versions older than 2.6.8 using the native arm64 architecture. Yes, there are hacks to get older Ruby versions to install on arm64, but they are dangerous hacks that can cause other issues.

One safe workaround is to use Rosetta, but that defeats the purpose of buying an Apple Silicon Mac because you won't be taking advantage of the faster arm64 chip. Also, installing things with and without Rosetta can cause all kinds of issues if you're not an expert at setting up a proper Ruby dev environment.

Here's a step-by-step guide I wrote that explains how and why to upgrade the Ruby version in your project. I hope it helps!

Also, keep in mind that RVM is not the only version manager out there. Others include asdf, chruby, frum, and rbenv. Some are more reliable than others, so give them a try if RVM doesn't work for you.

@igordelorenzi
Copy link
Author

igordelorenzi commented Apr 25, 2024

@monfresh Good point! Better keep patch version as recent as possible since it rarely breaks something, quite the opposite.

Ps: Very good article by the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants