简体   繁体   English

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

[英]Installing ruby with ruby-install causes error out on Mac M1

When installing ruby 2.6.6 or 2.7.2 using ruby-install on mac M1, the following error occurs.在mac M1上使用ruby-install安装ruby 2.6.6或2.7.2时出现如下错误。 Ruby 3.0.0 works fine however anything older will error out with readline and not allow ruby to install. 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));

You can use Rbenv RUBY_CFLAGS="-w" rbenv install 2.6.6您可以使用 Rbenv RUBY_CFLAGS="-w" rbenv install 2.6.6

I have been able to install both as x86_64 code and 3.0.1 as arm64 code.我已经能够安装为 x86_64 代码和 3.0.1 作为 arm64 代码。 I use rvm but this should work with other things.我使用 rvm 但这应该适用于其他事情。

  1. I use iTerm2 and have made 2 copies.我使用 iTerm2 并制作了 2 个副本。 One I used Get Info to change one application to use Rosetta.一个我使用 Get Info 将一个应用程序更改为使用 Rosetta。 Somewhere I even found a blue icon for the x86 app.我什至在某个地方找到了 x86 应用程序的蓝色图标。

在此处输入图像描述

  1. I have 2 versions of Homebrew.我有 2 个版本的 Homebrew。 One in /opt/homebrew/bin/brew and the other in /usr/local/bin/brew.一个在 /opt/homebrew/bin/brew 中,另一个在 /usr/local/bin/brew 中。

  2. I have 2 sets of exports in my.zshrc profile.我在 my.zshrc 配置文件中有 2 组导出。 I use the architecture to select the correct ones for the shell.我使用 select 的架构,正确的是 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

With this I can compile 2.6.6 (and I presume 2.7.2) in the x86 shell and separately 3.0.1 in the arm64 shell.有了这个,我可以在 x86 shell 和 arm64 Z2591C98B701244562481ZB1E 中分别编译 2.6.6(我假设是 2.7.2)和 3.0.1

My rvm list looks like:我的 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 ]

PS I still have trouble sometimes getting rails to link correctly to mysql. PS 我有时仍然无法让导轨正确链接到 mysql。 ruby / rails / mysql seem to all have to be the same architecture. ruby / rails / mysql 似乎都必须是相同的架构。 Still chasing that one down.还在追那个。

I finally got the older versions of ruby installed, including 2.6.6, on the m1 chip macbook pro with the following steps:我终于在m1芯片macbook pro上安装了旧版本的ruby,包括2.6.6,步骤如下:

First, I had to reinstall rbenv, ruby-build and readline with:首先,我必须重新安装 rbenv、ruby-build 和 readline:

brew reinstall rbenv ruby-build readline

Second, using CONFIGURE_OPTS was breaking my OpenSSL build.其次,使用CONFIGURE_OPTS破坏了我的 OpenSSL 构建。 Use RUBY_CONFIGURE_OPTS instead.请改用RUBY_CONFIGURE_OPTS I was using hombrew and had to use the following flags:我正在使用 hombrew 并且必须使用以下标志:

RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`"

Third, set the following to allow warnings in the make commands to not halt the build:第三,设置以下内容以允许 make 命令中的警告不停止构建:

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

Fourth, ensure you set the arch flag when installing via rbenv:第四,确保在通过 rbenv 安装时设置了 arch 标志:

arch -x86_84

Fifth, ensure your homebrew paths are correctly set:第五,确保您的自制程序路径设置正确:

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt:$PATH"

The final command that successfully installed ruby 2.6.6 was:成功安装 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

I used sudo to give mkdir permissions to the scripts.我使用 sudo 为脚本授予 mkdir 权限。

This worked for me:这对我有用:

❯ arch -x86_64 rvm install 3.1.2 --with-openssl-dir=/usr/local/opt/openssl@3

So I had to specify the architecture ( arch -x86_64 ) and a version of openssl under /usr/local/opt .所以我必须在/usr/local/opt下指定架构( arch -x86_64 )和 openssl 的版本。 In my case I already had a couple of versions of openssl installed there, I just picked the latest I had.就我而言,我已经在那里安装了几个版本的 openssl,我只是选择了我拥有的最新版本。 In other cases you may have to download and compile it yourself在其他情况下,您可能需要自己下载和编译

For M1 users, the architecture is arm64 .对于 M1 用户,架构是arm64 With Rosetta enabled it defaults to x86_64 which causes compatibility issues.启用 Rosetta 后,它默认为x86_64 ,这会导致兼容性问题。 Add arch inline with rvm install command:使用 rvm install 命令内联添加 arch:

arch -arm64 rvm install "ruby-2.7.5"

Duplicate terminal and name it something I put Terminal Ros复制终端并将其命名为 Terminal Ros

Terminal Ros > Right Click > Get Info > Check Open using Rosetta终端 Ros > 右键单击 > 获取信息 > 检查使用 Rosetta 打开

Open Terminal Ros > Run install "ruby-2.7.2"打开终端 Ros > 运行install "ruby-2.7.2"

And then run rvm use 2.7.2 --default然后运行rvm use 2.7.2 --default

罗塞塔终端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM