Ruby-Install ruby 2.7.x fails on m1 mac pro

171 Views Asked by At

ruby-install fails to install older versions of ruby for example 2.7.7 on an m1 mac pro

ruby-install ruby 2.7.7
...
        11: from ./tool/rbinstall.rb:947:in `<main>'
        10: from ./tool/rbinstall.rb:947:in `each'
         9: from ./tool/rbinstall.rb:950:in `block in <main>'
         8: from ./tool/rbinstall.rb:799:in `block in <main>'
         7: from ./tool/rbinstall.rb:835:in `install_default_gem'
         6: from ./tool/rbinstall.rb:835:in `each'
         5: from ./tool/rbinstall.rb:845:in `block in install_default_gem'
         4: from ./tool/rbinstall.rb:279:in `open_for_install'
         3: from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem'
         2: from /Users/m/src/ruby-2.7.7/lib/rubygems/specification.rb:2430:in `to_ruby'
         1: from /Users/m/src/ruby-2.7.7/lib/rubygems/core_ext/kernel_require.rb:83:in `require'
/Users/m/src/ruby-2.7.7/lib/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- openssl (LoadError)
make: *** [do-install-all] Error 1
!!! Installation of ruby 2.7.7 failed!

1

There are 1 best solutions below

0
On

The issue is to do with the version of openssl. older versions of ruby does not support newer versions of openssl

to fix try the following

# reinstall openssl and version 3
brew reinstall [email protected]

# install build dependancies
brew install openssl readline libyaml zlib bison [email protected]

# ensure build is using bison
export PATH="$(brew --prefix [email protected])/bin:$PATH"

# set ruby compilation flags
export CFLAGS="-Wno-error=implicit-function-declaration"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected]) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml) --with-zlib-dir=$(brew --prefix zlib)"

# ensure that openssl is linked
brew unlink openssl && brew link openssl --force

# load openssl 1.1 for compilation
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"

# install ruby via ruby-install
ruby-install ruby 2.7.7

my other answer for a slightly different but related issue can be found : ruby-install fails when installing ruby 2.6.x and 3.0.x on mac osx 11.6