用Rbenv在Mac M1 Apple Silicon上安装Ruby的方法

601 阅读1分钟

在与各种Ruby版本的编译错误作斗争中浪费了很多时间后,我发现这个命令可以持续地使用Rbenv安装Ruby版本(应该也适用于RVM)。

你可能会遇到像这样的错误

Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...
Installed openssl-1.1.1l to /Users/braga/.rbenv/versions/2.5.3
Downloading ruby-2.5.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.bz2
Installing ruby-2.5.3...
WARNING: ruby-2.5.3 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
BUILD FAILED (macOS 11.6 using ruby-build 20210928)
Inspect or clean up the working tree at /var/folders/4j/g8yy4pbj1szfvwvywmcxdsgr0000gn/T/ruby-build.20211015190726.89354.qL8MAu
Results logged to /var/folders/4j/g8yy4pbj1szfvwvywmcxdsgr0000gn/T/ruby-build.20211015190726.89354.log
Last 10 log lines:
    ^
objspace.c:942:45: note: ')' token is here
    rb_mObjSpace = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
                                            ^~~~~~~~~~~~~~~~~~~~~~~~
../.././include/ruby/ruby.h:1755:56: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \

为了缓解这种情况,通过设置这两个变量来安装。感谢Antony Amirtha Raj提供的这个。

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS='--with-readline-dir=/usr/local/opt/readline/' arch -x86_64 rbenv install 2.4.2