<aside> 😭 前前后后折腾了好几天啊,前后试过了好几次 rvm 和 rbenv,最后还是用rbenv安装成功了,目前还没测试项目能不能跑起来,后面测试会再来更新。

P.S. 本文主要参考了:在M1 Macbook上优雅地安装Rbenv+Ruby

</aside>

0. 确保 Homebrew(ARM版本) 已经可用

brew --version

Untitled

1. 使用 Homebrew 安装rbenv、readline和openssl

# 安装
brew install rbenv readline openssl

# 如果提示已经安装,就重装一下
brew reinstall rbenv readline openssl

2. 修改 ~/.zshrc

将下面的内容加入到 ~/.zshrc 文件的末尾

# rbenv
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
# Use native openssl libraries for building
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"

命令行中输入以下命令刷新,使环境变量生效

source ~/.zshrc

3. 安装 Ruby

3.0 修改源为 Ruby-china 源

能稍微快一点

git clone <https://github.com/andorchen/rbenv-china-mirror.git> "$(rbenv root)"/plugins/rbenv-china-mirror

Untitled

3.1 安装 ≥ 2.7.2 版本