M1 Mac 安装 rbenv 管理 ruby 多版本

4,072 阅读1分钟

M1 mac 真香

前置条件: 请参考Mac Arm 安装 macport安装 macports

  1. 安装 rbenv 和 ruby-build
sudo port install rbenv ruby-build
  1. 配置环境变量
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.profile
source ~/.profile
  1. 列出可用 ruby 列表
rbenv install --list
  1. 安装 ruby, 这里我用的是最新的2.7.2
rbenv install 2.7.2

这里可能会遇到以下报错, 需要指定下 openssl

Last 10 log lines:
  "_write$UNIX2003", referenced from:
      _conn_write in bss_conn.o
      _conn_puts in bss_conn.o
      _dgram_write in bss_dgram.o
      _fd_write in bss_fd.o
      _sock_write in bss_sock.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libcrypto.dylib] Error 1
make: *** [all] Error 2

再重新能装下ruby

RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/local --with-gdbm-dir=/opt/local"  rbenv install -v 2.7.2
  1. 切换版本
rbenv global 2.7.2
rbenv shell 2.7.2

查看下版本

rbenv versions