rbenv和Apple m1,无法安装ruby 3.2、2.7和2.6

3phpmpom  于 2023-01-30  发布在  Ruby
关注(0)|答案(1)|浏览(179)

我无法安装rbenv的ruby版本,我尝试了2.6.10、2.7.7或3.2.0。
这是我在执行时得到的错误:

❯ rbenv install 3.2.0
To follow progress, use 'tail -f /var/folders/4v/kyv3nw1s7lq8s7lz7r6djvsr0000gn/T/ruby-build.20230125170342.85553.log' or pass --verbose
Downloading openssl-3.0.7.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/83049d042a260e696f62406ac5c08bf706fd84383f945cf21bd61e9ed95c396e
Installing openssl-3.0.7...
Installed openssl-3.0.7 to /Users/idanahal/.rbenv/versions/3.2.0

Downloading ruby-3.2.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0.tar.gz
Installing ruby-3.2.0...
ruby-build: using readline from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 13.1 using ruby-build 20221225)

Inspect or clean up the working tree at /var/folders/4v/kyv3nw1s7lq8s7lz7r6djvsr0000gn/T/ruby-build.20230125170342.85553.VSOgmw
Results logged to /var/folders/4v/kyv3nw1s7lq8s7lz7r6djvsr0000gn/T/ruby-build.20230125170342.85553.log

Last 10 log lines:
compiling ossl_x509ext.c
compiling ossl_x509name.c
compiling ossl_x509req.c
compiling ossl_x509revoked.c
compiling ossl_x509store.c
installing default openssl libraries
linking shared-object date_core.bundle
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make: *** [build-ext] Error 2

当用自制软件安装时,它可以正常工作。我不知道该怎么办。rbenv甚至应该在m1电脑上工作吗?
我有MacOS 13.1

64jmpszr

64jmpszr1#

设置以下环境变量可解决此问题:

export RUBY_CONFIGURE_OPTS="--with-zlib-dir=$(brew --prefix zlib) --with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml) --with-gdbm-dir=$(brew --prefix gdbm)"

然后才能为所有版本运行rbenv install
Note:--with-openssl-dir=$(brew --prefix openssl@1.1)配置只在2.6.*2.7.*版本中需要,如果你试图安装ruby 3.*.*,你可以(也应该)删除它。
对于2.6和2.7,有时此环境变量还需要:

export RUBY_CFLAGS="-Wno-error=implicit-function-declaration"

如果以上都不起作用,你可以用Homebrew安装ruby,如果你想从rbenv管理Homebrew安装的版本,请阅读this answer

相关问题