ruby-install 无法在 m1 mac pro 上安装旧版本的 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!
问题与openssl的版本有关。旧版本的 ruby 不支持新版本的 openssl
要修复请尝试以下方法
# 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
我对略有不同但相关问题的其他答案可以找到:在 mac osx 11.6 上安装 ruby 2.6.x 和 3.0.x 时,ruby-install 失败