Home > Software design >  ruby-install fails when installing ruby 2.6.x and 3.0.x on mac osx 11.6
ruby-install fails when installing ruby 2.6.x and 3.0.x on mac osx 11.6

Time:10-06

When running ruby-install, it fails to build. This also reported in rbenv issues (https://github.com/rbenv/ruby-build/issues/1725).

for example when installing ruby 2.6.8

# installing via ruby-install ( https://github.com/postmodern/ruby-install )
ruby-install ruby 2.6.8

it results in the following error

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!

CodePudding user response:

seems to be complier issue. first ensure that xcode is installed appropriately. In my case, I had it installed prior but you can opt to reinstall to be sure. hope this helps people save time trying to figure out the issue as compiling it takes several minutes.

# 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
brew install openssl

# install build dependancies
brew install openssl readline libyaml zlib llvm bison

# ensure build is using LLVM compiler
export PATH="/usr/local/opt/llvm/bin:$PATH"
export CPPFLAGS="-I/usr/local/opt/llvm/include"

# ensure build is using bison
export PATH="/usr/local/opt/bison/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/bison/lib"

# set ruby compilation flags
export CFLAGS="-Wno-error=implicit-function-declaration -Wcompound-token-split-by-macro"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl) --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

CodePudding user response:

I can not install any rubies by compiling on Big Sur. I get this:

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32, from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/Security.h:42, from random.c:342: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:14: error: variably modified 'bytes' at file scope 193 | char bytes[kAuthorizationExternalFormLength]; | ^~~~~ make: *** [random.o] Error 1 !!! Compiling ruby 2.7.4 failed!

Here is my set up on the ruby-install:

xcode-select version 2384

BASERUBY = /usr/local/opt/ruby@2.7/bin/ruby --disable=gems
CC = gcc
LD = ld
LDSHARED = gcc -dynamiclib
CFLAGS = -O2 -fno-tree-dce -fno-optimize-sibling-calls -Wno-error=implicit-function-declaration -pipe
XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -fPIE -DCANONICALIZATION_FOR_MATHN -I. -I.ext/include/x86_64-darwin20 -I./include -I. -I./enc/unicode/12.1.0
CPPFLAGS = -I/usr/local/opt/llvm/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/gdbm/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT
DLDFLAGS = -L/usr/local/opt/bison/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib -fstack-protector-strong -pie -framework Security -framework Foundation
SOLIBS = -lpthread -ldl -lobjc
LANG = en_US.UTF-8
LC_ALL =
LC_CTYPE =
MFLAGS =

gcc (Homebrew GCC 11.2.0) 11.2.0

CodePudding user response:

I had the same issue when I ran the following command: ruby-install ruby 2.6.8 -- --with-openssl-dir=$(brew --prefix [email protected]).

I updated bison with brew install [email protected] and ran export PATH="$(brew --prefix [email protected])/bin:$PATH" to fix ripper. Then, re-running the initial ruby command worked!

  • Related