11

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!
mirageglobe
  • 2,446
  • 2
  • 24
  • 30
  • The key error seems to be "ripper.y:762.9-16: syntax error". To me this error indicates incorrectly configured compiler tools, specifically yacc or bison (whichever ruby uses for .y grammar files). The [official docs](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment) do not suggest that these tools should be configured, implying that these tools should come from the standard Xcode installation. – Jared Beck Sep 30 '21 at 19:27
  • Yeah xcode standard was present. Which was weird. I can only suspect latest big Sur changed the complier. I tried it on two different machines each had xcode setup. The solution below works fine – mirageglobe Oct 01 '21 at 20:09
  • 1
    on another note. I wonder why this question was downvoted? its clearly a valid question as people have faced this issue. The various solutions are stated as below. If it helps you, please consider to *upvote* to help peers who have faced similar issue. – mirageglobe Oct 12 '21 at 12:02

4 Answers4

18

Seems to be a compiler issue. First ensure that Xcode is installed appropriately. In my case, I had it installed already 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

# 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
Moot
  • 2,195
  • 2
  • 17
  • 14
mirageglobe
  • 2,446
  • 2
  • 24
  • 30
  • Does not work for me. Getting a totally different error. Seems like it also is not picking up the RUBY_CONFIGURE_OPTS either since the openssl@3 is replaced with openssl@1.1. My error is on compile of random.c: In file included from /Library/Developer/CommandLineTools/.../Security.framework/H.../AuthSession.h:32:0, from /Library/Developer/CommandLineTools/.../Security.framework/H.../Security.h:42, from random.c:342: /Library/Developer/CommandLineTools/.../Security.framework/H.../Authorization.h:193:7: error: variably modified 'bytes' at file scope – GregD Oct 05 '21 at 12:39
  • can you try removing openssl and just ensure you use openssl@1.1 – mirageglobe Oct 06 '21 at 10:31
  • thats seems to be an xcode issue. try running `xcode-select -p` to check if its correctly installed. `xcode-select --install` to install it properly. – mirageglobe Oct 15 '21 at 00:07
  • updated solution but kudos to `Herk` who posted the right solution of using bison@2.7 to compile. The issue seems to be newer apple clang 12 / 13, `clang -v` seems to have issue for older rubys 2.6.x. There is issue on backporting as described here https://github.com/rbenv/ruby-build/issues/1489 – mirageglobe Oct 15 '21 at 00:17
  • 1
    Just wanted to thank you for the answer. Just an addition works with the rvm (other than ruby-install) as well. – rkalra Aug 01 '22 at 15:16
9

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

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

Herk
  • 91
  • 1
  • 3
0

My colleague helped me solving this problem with script below:

#!/usr/bin/env bash

set -e

# ruby-install --latest

OPENSSL_VERSION=1.1
OPENSSL_DIR=/usr/local/opt/openssl@${OPENSSL_VERSION}

function install-ruby-on-mac() {
    PKG_CONFIG_PATH=${OPENSSL_DIR}/lib/pkgconfig \
    ruby-install $(ruby-install-options $1) \
        ruby $1 \
        -- \
        --with-openssl-dir=${OPENSSL_DIR} \
        --with-opt-dir=$(brew --prefix readline) \
        --without-tcl --without-tk
}

install-ruby-on-mac 2.5.8
install-ruby-on-mac 2.6.8
install-ruby-on-mac 2.7.4

Hope it could help someone.

Tam Pham
  • 312
  • 3
  • 4
0
export warnflags=-Wno-error=implicit-function-declaration
export optflags="-w"
rvm install "ruby-2.6.3" --with-out-ext=fiddle

Perform normal installation