Homebrew
# 查看是否安装过
brew -v
# 傻瓜式安装, 按提示操作就行
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# 卸载
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
安装完成执行brew -v,如果发现报以下错误
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
按提示执行对应的命令 git config --global --add即可
Ruby
ruby可以通过两种方式,rvm 和 rbenv,相对来讲rbenv 比较方便管理版本,也是傻瓜式使用,这里主要介绍下rbenv的使用方式。
# homebrew 直接安装
brew install rbenv
# 查看帮助
rbenv --help
安装ruby
# 列出所有可安装版本,3.0版本很稳定了
rbenv install --list
# 安装 3.0.5
rbenv install 3.0.5
# 安装 jruby-9.4.0.0
rbenv install jruby-9.4.0.0
配置并初始化shell
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
注意:如果用bash,就用~/.bashrc 替换 ~/.zshrc
然后执行source ~/.zshrc或者重启终端让配置生效
版本查询
# 所有安装的版本
rbenv versions
# 正在使用的版本
rbenv version
设置版本
# 默认使用3.0.5版本
rbenv global 3.0.5
# 当前的 shell 使用 jruby-9.4.0.0, 会设置一个 `RBENV_VERSION` 环境变量
rbenv shell jruby-9.4.0.0
# 当前目录使用 jruby-9.4.0.0, 会生成一个 `.rbenv-version` 文件
rbenv local jruby-9.4.0.0
其他
# 每当切换 ruby 版本和执行 bundle install 之后必须执行这个命令
rbenv rehash
# 列出 irb 这个命令的完整路径
rbenv which irb
# 列出包含 irb 这个命令的版本
rbenv whence irb