在 mac osx 11.6 上安装 ruby​​ 2.6.x 和 3.0.x 时 ruby​​-install 失败

Jim*_*Lim 17 ruby ruby-install chruby macos-big-sur

运行 ruby​​-install 时,构建失败。rbenv 问题中也报告了这一点(https://github.com/rbenv/ruby-build/issues/1725)。

例如安装 ruby​​ 2.6.8 时

# installing via ruby-install ( https://github.com/postmodern/ruby-install )
ruby-install ruby 2.6.8
Run Code Online (Sandbox Code Playgroud)

它会导致以下错误

ossl_x509store.c:452:30: note: ')' token is here
    result = rb_funcall(ctx, rb_intern("verify"), 0);
                             ^~~~~~~~~~~~~~~~~~~
../.././include/ruby/ruby.h:1826:56: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                                                       ^
../.././include/ruby/ruby.h:2602:20: note: expanded from macro 'rb_funcall'
        rb_funcallv(recv, mid, \
                          ^~~
6 warnings generated.
linking shared-object openssl.bundle
installing default openssl libraries
make[2]: Leaving directory '/Users/xxxxx/src/ruby-2.6.8/ext/openssl'
make[2]: Entering directory '/Users/xxxxx/src/ruby-2.6.8/ext/ripper'
extracting ripper.y from ../.././parse.y
compiling compiler ripper.y
ripper.y:762.9-16: syntax error, unexpected identifier, expecting string
make[2]: *** [Makefile:332: ripper.c] Error 1
make[2]: Leaving directory '/Users/xxxxx/src/ruby-2.6.8/ext/ripper'
make[1]: *** [exts.mk:257: ext/ripper/all] Error 2
make[1]: Leaving directory '/Users/xxxxx/src/ruby-2.6.8'
make: *** [uncommon.mk:286: build-ext] Error 2
!!! Compiling ruby 2.6.8 failed!
Run Code Online (Sandbox Code Playgroud)

Jim*_*Lim 24

看来是编译器的问题。首先确保 Xcode 已正确安装。就我而言,我已经安装了它,但您可以选择重新安装以确保。希望这可以帮助人们节省尝试找出问题的时间,因为编译需要几分钟。

# check xcode, should yield : /Library/Developer/CommandLineTools
xcode-select -p

# check xcode, should yield : xcode-select version 2384
xcode-select -v

# install xcode-select
xcode-select --install

# reinstall openssl and version 3
brew reinstall openssl@1.1

# install build dependancies
brew install openssl readline libyaml zlib bison bison@2.7

# ensure build is using bison
export PATH="$(brew --prefix bison@2.7)/bin:$PATH"

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

# install ruby via ruby-install
ruby-install ruby 2.6.8
Run Code Online (Sandbox Code Playgroud)

如果失败则再执行几个步骤

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

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

# install ruby via ruby-install
ruby-install ruby 2.7.7
Run Code Online (Sandbox Code Playgroud)


小智 11

当我运行以下命令时,我遇到了同样的问题:ruby-install ruby 2.6.8 -- --with-openssl-dir=$(brew --prefix openssl@1.1)

我更新bisonbrew install bison@2.7跑去export PATH="$(brew --prefix bison@2.7)/bin:$PATH"修复裂土器。然后,重新运行最初的 ruby​​ 命令就成功了!