Ruby for mac10.8


1. Install Xcode and the Command Line Tools

If you don't have it installed I suggest you install Xcode from the Mac App Store and install the command line tools in Xcode Preferences -> Downloads.

Xcode是苹果推出的开发工具,它是免费的,可以在Mac Store中下载。如果你已经安装了,那么可以打开,在菜单栏中选择Xcode -> Preference -> Download,然后点击Command Line Tools对应的install即可。

之所以需要安装Xcode,是因为其中包含了一些安装Rails所需要的编译包,如果你没有安装Command Line Tools的话,在利用RVM安装Ruby 时,会报出如下错误,原因是缺少autoreconf和automake包。

rvm requires autoreconf to install the selected ruby interpreter however autoreconf was not foundin the PATH.


如果安装了Xcode,那么git就已经安装了,可以确认一下:

1
2
$ git --version
git version 1.7.7.5 (Apple Git-26)

这些都确认以后,就可以开始安装RVM(Ruby Version Manager)了。RVM是学习Rails的人必须了解的一样工具。因为Mac本身自带了Ruby,但版本比较老,而我们开发所需要的一般都是最新的Ruby。由于Mac相关环境可能会用到Ruby的旧版本,直接删除旧版本会影响系统相关特性,所以RVM可以很灵活地帮我们管理不同版本。

2. Install RVM

1
2
3
$ bash -s stable < <(curl -s https: //raw .github.com /wayneeseguin/rvm/master/binscripts/rvm-installer )
#或者
$ bash < <( curl -s https: //rvm .beginrescueend.com /install/rvm )

接着需要配置RVM快捷命令,否则你无法在终端里直接使用rvm命令:

1
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" ' >> ~/.bash_profile

很明显,意思就是直接将脚本插入到了.bash_profile中。运行:

1
$ source ~/.bash_profile

或者是直接重启Terminal,然后可以输入如下命令进行验证:

1
2
$ type rvm | head -1
rvm is a function

这样即证明rvm命令配置成功了。有兴趣的还可以运行

1
$ echo $PATH

试一下,也能验证。


3. Install Ruby 2.0.0:

First run the following commands:

 
 
  1. rvm get head

followed by:

 
 
  1. rvm requirements

If you don't get any errors you can finally install Ruby 2.0.0:

 
 
  1. rvm install 2.0.0

To set as your current version of Ruby run the following command:

 
 
  1. rvm use 2.0.0

To make it the default Ruby:

 
 
  1. rvm default 2.0.0

or 

 
 
  1. rvm use 2.0.0 --default

Now every time you open Terminal.app Ruby 2.0.0 will be default. You can always check which version of Ruby you have using the following command:

 
 
  1. ruby -v

and where it's located executing the command:

 
 
  1. which ruby


现在确认Ruby Gems,Gems是Ruby的包管理器(Package Manager)。

1
2
3
4
$ gem - v
1.8.21
#如果不是最新版本,可以
$ gem update --system

4. Install Rails:

1
2
3
4
$ gem install rails
#验证版本
$ rails - v
3.2.2

这样环境就搭建成功了,可以开始Rails开发学习了。



参考资料:

1. 在Mac OS X Lion下安装Ruby on Rails:

http://www.hoowolf.net/2012/03/29/installing-ruby-on-rails-on-mac-os-x-lion/

2. Installing Ruby 2.0.0 with RVM and Homebrew on Mac OS X 10.8 Mountain Lion:
http://www.interworks.com/blogs/ckaukis/2013/03/05/installing-ruby-200-rvm-and-homebrew-mac-os-x-108-mountain-lion



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值