ruby-install fails when installing ruby 2.6.x and 3.0.x on mac osx 11.6
Asked Answered
P

4

17

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!
Pancreatin answered 30/9, 2021 at 14:46 Comment(3)
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 do not suggest that these tools should be configured, implying that these tools should come from the standard Xcode installation.Witting
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 finePancreatin
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.Pancreatin
P
25

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 [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)"

# install ruby via ruby-install
ruby-install ruby 2.6.8

a couple more steps if it fails

# 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
Pancreatin answered 30/9, 2021 at 14:46 Comment(6)
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 [email protected]. 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 scopeAllcot
can you try removing openssl and just ensure you use [email protected]Pancreatin
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.Pancreatin
updated solution but kudos to Herk who posted the right solution of using [email protected] 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 github.com/rbenv/ruby-build/issues/1489Pancreatin
Just wanted to thank you for the answer. Just an addition works with the rvm (other than ruby-install) as well.Wyatan
In addition to this I had to do this suggestion: github.com/postmodern/ruby-install/issues/… export CFLAGS="-DUSE_FFI_CLOSURE_ALLOC" export PKG_CONFIG_PATH="$(brew --prefix [email protected])/lib/pkgconfig" ruby-install 2.6.8 -- --with-openssl-dir=$(brew --prefix [email protected]) instead of the last stepSauger
H
11

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!

Hardback answered 5/10, 2021 at 19:22 Comment(1)
Thanks. After spending over 2 days this worked for me. Might have been a combo of downgrading OpenSLL to 1.1 and then your steps to install Ruby 2.6.10 on a new MacBook with M2 processor running Sonoma 14.1.Welton
I
1
export warnflags=-Wno-error=implicit-function-declaration
export optflags="-w"
rvm install "ruby-2.6.3" --with-out-ext=fiddle

Perform normal installation

Incongruous answered 2/2, 2023 at 14:3 Comment(0)
S
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.

Septivalent answered 3/12, 2021 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.