在 Apple Silicon 上安裝 rbenv 會有一些小問題需要處理。
目前環境
- M1 Pro Macbook Pro 14"
- macOS 12.4
- 系統預設 Ruby 版本 2.6.3
安裝步驟
1. 安裝 Homebrew
1
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
2. 安裝 rbenv
3. 安裝 openssl & readline
1
2
3
| # 指定 openssl 1.1版
brew install openssl@1.1
brew install readline
|
4. 增加環境參數
增加以下參數到 ~/.zshrc
1
2
3
4
5
6
7
8
9
10
| # rbenv
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
# openssl
export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
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_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.1"
|
然後重新載入設定檔
5. 安裝 Ruby
1
2
3
4
5
6
7
| # 測試安裝 2.7.2
rbenv install 2.7.2
# 2.7.2 版本只在目前資料夾有效
rbenv local 2.7.2
rbenv rehash
# 檢查 ruby 版本是否正常運作
ruby -v
|
參考