簡體   English   中英

在 mac osx 11.6 上安裝 ruby 2.6.x 和 3.0.x 時,ruby 安裝失敗

[英]ruby-install fails when installing ruby 2.6.x and 3.0.x on mac osx 11.6

運行 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

它導致以下錯誤

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!

當我運行以下命令時,我遇到了同樣的問題: ruby-install ruby 2.6.8 -- --with-openssl-dir=$(brew --prefix openssl@1.1)

我用brew install bison@2.7更新了bison並運行export PATH="$(brew --prefix bison@2.7)/bin:$PATH"來修復開膛手。 然后,重新運行初始的 ruby​​ 命令起作用了!

似乎是編譯器的問題。 首先確保正確安裝了 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

我無法通過在 Big Sur 上編譯來安裝任何紅寶石。 我明白了:

在 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32 包含的文件中,來自 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System /Library/Frameworks/Security.framework/Headers/Security.h:42,來自random.c:342:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/Authorization .h:193:14: 錯誤:在文件范圍 193 處可變地修改了“字節”| 字符字節[kAuthorizationExternalFormLength]; | ^~~~~ make: *** [random.o] 錯誤 1 ​​!!! 編譯ruby 2.7.4失敗!

這是我在 ruby​​-install 上的設置:

xcode 選擇版本 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(自制 GCC 11.2.0)11.2.0

我的同事用下面的腳本幫助我解決了這個問題:

#!/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

希望它可以幫助某人。

export warnflags=-Wno-error=implicit-function-declaration
export optflags="-w"
rvm install "ruby-2.6.3" --with-out-ext=fiddle

執行正常安裝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM