陈斌彬的技术博客

Stay foolish,stay hungry

Mac 安装最新版的 Ruby

Install The Latest Ruby

执行命令:brew install ruby

➜ /Users/apple git:(master) ✗> brew install ruby
==> Downloading https://homebrew.bintray.com/bottles/ruby-2.2.2.yosemite.bottle.

curl: (6) Could not resolve host: d29vzk4ow07wi7.cloudfront.net
Error: Failed to download resource "ruby"
Download failed: https://homebrew.bintray.com/bottles/ruby-2.2.2.yosemite.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.bz2
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/ruby/2.2.2 --enable-shared --disable-
==> make
==> make install
🍺  /usr/local/Cellar/ruby/2.2.2: 1080 files, 20M, built in 8.8 minutes

设置环境变量

系统原始版本的 /usr/bin/ruby 我们并不删除,只是更改 PATH 环境变量,且将 /usr/local/bin 添加到 PATH 的前面,这样系统就会首先用 /usr/local/bin 下面找到我们用 brew 安装的 ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] 版本的了。

执行命令:

➜ /Users/apple git:(master) ✗>  vim ~/.bash_profile

在文件的末尾加入

# for brew install
export PATH=/usr/local/bin:$PATH

然后重启终端,就可以用到了新的 ruby 了

检验一下

➜ /Users/apple git:(master) ✗> ruby --version
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

$ which ruby
/usr/local/bin/ruby              

注意:系统的是 /usr/bin/ruby

如果要用回旧版本,就把 export PATH=/usr/local/bin:$PATH注释掉。

# for brew install
#export PATH=/usr/local/bin:$PATH