在Mac OS X上安装Ruby on Rails 3.2

苹果开发者软件下载

在这里下载:https://developer.apple.com/downloads/index.action

  • Xcode
  • Command Line Tools(OS X Mountain Lion) for Xcode

并安装。

安装Homebrew

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)

卸载被MacPorts安装的Ruby

sudo port uninstall ruby

卸载RVM

rvm implode

安装rbenv和ruby-build

brew install rbenv
brew install ruby-build
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

安装readline

brew install readline
brew link readline

安装openssl

brew install openssl
brew link openssl

安装ruby

CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=/usr/local" rbenv install 1.9.3-p194
rbenv rehash
rbenv global 1.9.3-p194

确认rbenv版本

rbenv version

确认ruby版本

ruby -v

创建.gemrc文件

vim ~/.gemrc

install: --no-ri --no-rdoc
update: --no-ri --no-rdoc

安装Ruby on Rails 3.2

rbenv exec gem install rails --version="~> 3.2.8"
rbenv rehash
source ~/.bash_profile

确认Ruby on Rails版本

rails -v

创建办公文件夹

cd
mkdir work

创建确认执行的新建应用程序

cd work
rails new foo --skip-bundle
cd foo

安装依赖的版本

bundle install

生成简单的用户管理功能

rails g scaffold user name:string email:string
rake db:migrate

启动应用程序

rails s

确认执行

http://localhost:3000/users

参考资料

Ruby on Rails 3.2 を Mac OS X にインストールする手順