使用 ruby​​-install 安装 ruby​​ 会导致 Mac M1 上出现构建错误

Jim*_*Lim 26 ruby homebrew apple-m1

在 mac M1 上使用 ruby​​-install 安装 ruby​​ 2.6.6 或 2.7.2 时,出现以下错误。Ruby 3.0.0 工作正常,但是任何较旧的版本都会出现 readline 错误,并且不允许安装 ruby​​。

readline.c:1905:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    rl_username_completion_function
readline.c:79:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/opt/homebrew/opt/readline/include/readline/readline.h:485:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function PARAMS((const char *, int));
Run Code Online (Sandbox Code Playgroud)

ben*_*sop 21

我终于在 m1 芯片 macbook pro 上安装了旧版本的 ruby​​,包括 2.6.6,步骤如下:

首先,我必须使用以下命令重新安装 rbenv、ruby-build 和 readline:

brew reinstall rbenv ruby-build readline
Run Code Online (Sandbox Code Playgroud)

其次,使用CONFIGURE_OPTS破坏了我的 OpenSSL 构建。RUBY_CONFIGURE_OPTS代替使用。我正在使用 hombrew,并且必须使用以下标志:

RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`"
Run Code Online (Sandbox Code Playgroud)

第三,设置以下内容以允许 make 命令中出现警告而不停止构建:

RUBY_CFLAGS="-Wno-error=implicit-function-declaration"
Run Code Online (Sandbox Code Playgroud)

第四,确保在通过 rbenv 安装时设置 arch 标志:

arch -x86_84
Run Code Online (Sandbox Code Playgroud)

第五,确保您的自制程序路径设置正确:

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt:$PATH"
Run Code Online (Sandbox Code Playgroud)

成功安装 ruby​​ 2.6.6 的最终命令是:

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt:$PATH"
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" sudo arch -x86_64 rbenv install --verbose 2.6.6
Run Code Online (Sandbox Code Playgroud)

我使用 sudo 授予脚本 mkdir 权限。

  • 我遇到了这个错误,并设法使用 `arch -x86_64 rvm install 2.4.4 -- CFLAGS=-DUSE_FFI_CLOSURE_ALLOC` 简单地安装 Ruby,而无需执行您提到的额外步骤(注意:这是针对版本 2.4.4 的) (2认同)

ali*_*ikk 15

这对我有用:

\n
\xe2\x9d\xaf arch -x86_64 rvm install 3.1.2 --with-openssl-dir=/usr/local/opt/openssl@3\n
Run Code Online (Sandbox Code Playgroud)\n

所以我必须指定架构(arch -x86_64)和openssl的版本/usr/local/opt。就我而言,我已经安装了几个版本的 openssl,我只是选择了最新的版本。在其他情况下,您可能需要自己下载并编译

\n


Sco*_*erg 5

我已经能够安装 x86_64 代码和 3.0.1 作为 arm64 代码。我使用 rvm 但这应该可以与其他东西一起使用。

  1. 我使用 iTerm2 并制作了 2 份。我使用“获取信息”将一个应用程序更改为使用 Rosetta。我什至在某个地方找到了 x86 应用程序的蓝色图标。

在此输入图像描述

  1. 我有 2 个版本的 Homebrew。一个在 /opt/homebrew/bin/brew 中,另一个在 /usr/local/bin/brew 中。

  2. 我的 .zshrc 配置文件中有 2 组导出。我使用该体系结构为 shell 选择正确的体系结构。

alias abrew="/opt/homebrew/bin/brew"

alias i="arch -x86_64"
alias ibrew="arch -x86_64  /usr/local/bin/brew"
alias irvm="arch -x86_64 rvm"

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

_ARCH=$(arch)
PROMPT="$_ARCH $PROMPT"

# Requires iterm2
if [[ "$_ARCH" == "i386" ]]; then
  echo -ne "\033]1337;SetColors=bg=000FC5\007"
  #usr/local is X_86
  export PATH="/usr/local/bin:$PATH"
  export PATH="/usr/local/opt:$PATH"
fi

if [[ "$_ARCH" == "arm64" ]]; then
  #usr/local is X_86
  export PATH="/opt/homebrew/bin:$PATH"
  export PATH="/opt/homebrew/opt:$PATH"
fi

Run Code Online (Sandbox Code Playgroud)

有了这个,我可以在 x86 shell 中编译 2.6.6(我假设是 2.7.2),并在 arm64 shell 中单独编译 3.0.1。

我的 rvm 列表如下所示:

   ruby-2.4.6 [ x86_64 ]
   ruby-2.4.9 [ x86_64 ]
 * ruby-2.6.5 [ x86_64 ]
   ruby-2.6.6 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]
   ruby-2.7.2 [ x86_64 ]
=> ruby-3.0.1 [ arm64 ]
Run Code Online (Sandbox Code Playgroud)

PS 有时我仍然无法让 Rails 正确链接到 mysql。ruby / Rails / mysql 似乎都必须是相同的架构。还在追那个人。


Faw*_*waz 5

对于M1用户来说,架构是arm64. 启用 Rosetta 后,它默认会x86_64导致兼容性问题。使用 rvm install 命令添加内联 arch:

arch -arm64 rvm install "ruby-2.7.5"
Run Code Online (Sandbox Code Playgroud)