Mac OS - m1:由于配置错误而无法安装 ruby​​ 2.7.5

Cin*_*ndy 1 ruby macos rvm react-native apple-m1

我需要为我的 React Native 应用程序安装 ruby​​ 2.7.5,但无法通过 rvm 安装 2.7.5。我尝试了很多方法来安装任何 ruby​​ 版本,最终出现此配置错误。

Error running './configure --prefix=/Users/myname/.rvm/rubies/ruby-2.1.1 --disable-install-doc --enable-shared',
please read /Users/myname/.rvm/log/1672107647_ruby-2.1.1/configure.log
There has been an error while running configure. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

这是配置日志

configure: WARNING: you should use --build, --host, --target
checking for ruby... /usr/bin/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... arm-apple-darwin22.2.0
checking host system type... arm-apple-darwin22.2.0
checking target system type... arm-apple-darwin22.2.0
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/Users/myname/.rvm/src/ruby-2.7.1':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

我试过...

  1. 删除rvm并重新安装
  • rvm install 2.7.5
  • rvm install ruby-2.7.5
  1. 使用 rbenv

  2. 安装openssl

  • brew install openssl
  • rvm install 2.6.7 --with-openssl-dir=/usr/local/opt/openssl
  1. 使用 rvm implode 删除 rvm

所有这些都会抛出相同的错误消息。尝试4.后,所有ruby版本都被删除,但仍然无法安装任何ruby版本。

请帮忙!!!

编辑我尝试过 CFLAGS="-Wno-error=implicit-function-declaration" rvm install 2.7.5

并得到这个错误

Error running './configure --prefix=/Users/myname/.rvm/rubies/ruby-2.7.5  --with-opt-dir=/opt/homebrew/opt/libyaml:/opt/homebrew/opt/libksba:/opt/homebrew/opt/readline:/opt/homebrew/opt/zlib:/opt/homebrew/opt/openssl@1.1 --disable-install-doc --enable-shared',
please read /Users/myname/.rvm/log/1672116807_ruby-2.7.5/configure.log
There has been an error while running configure. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

编辑 - - -

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

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

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" 
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
rvm install 2.7.5
Run Code Online (Sandbox Code Playgroud)

这返回相同的错误,但我得到了这个配置日志

checking for ruby... /usr/bin/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... aarch64-apple-darwin22.2.0
checking host system type... aarch64-apple-darwin22.2.0
checking target system type... aarch64-apple-darwin22.2.0
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/Users/myname/.rvm/src/ruby-2.7.5':
configure: error: cannot run C compiled programs. // <---- new!
If you meant to cross compile, use `--host'.
See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

------ 编辑 -------- 2 天后,我尝试安装 2.7.6 并再次收到此消息。

checking for ruby... /Users/myname/.rvm/rubies/ruby-2.7.5/bin/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... aarch64-apple-darwin22.2.0
checking host system type... aarch64-apple-darwin22.2.0
checking target system type... aarch64-apple-darwin22.2.0
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/Users/myname/.rvm/src/ruby-2.7.6':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

Pay*_*yal 8

添加命令行工具:

Ensure the command line tools are correctly installed. We might need to reinstall Xcode after OS upgrades.
Run Code Online (Sandbox Code Playgroud)

假设我们已经安装了 openssl,请遵循以下具体步骤

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

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

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" 
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
rvm install 2.7.5
Run Code Online (Sandbox Code Playgroud)