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 found
in
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:
- rvm get head
followed by:
- rvm requirements
If you don't get any errors you can finally install Ruby 2.0.0:
- rvm install 2.0.0
To set as your current version of Ruby run the following command:
- rvm use 2.0.0
To make it the default Ruby:
- rvm default 2.0.0
or
- 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:
- ruby -v
and where it's located executing the command:
- 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:
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