快速搭建你的Ruby On Rails环境
July 21, 2010发表在 Ruby On Rails
Ruby On Rails 3
最近项目逼近,需要迅速搭建一个Ruby On Rails的环境,于是有了这篇Tutorial,主要以Mac平台为主。
在大部分的Unix based的操作系统都有Ruby的包,可以直接安装或者已经预装好了,这里要介绍一种比较容易管理的方法。使用RVM,Ruby Version Management,这样可以在一个系统下安装不同版本的Ruby,并且可以随时更改环境。
首先,你要确保你已经在Mac下安装了Development Tools,这样你才可以编译源码。如果没有安装,拿出你的系统安装盘,找到XCode,安装文件,直接装好就行了。
下面,我们就进入RVM的安装了。更多细节可以参考 http://rvm.beginrescueend.com/
如果你没有git的话,就用下面的命令吧,在Terminal中输入:(检查有没有git?在Terminal输入,如果返回路径就是有git了)
which git
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
如果有git的话,用这条命令:
mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install
安装好之后,在Terminal中输入which rvm应该会返回类似于
/Users/xxxxxxx/.rvm/bin/rvm
那么恭喜你,RVM已经安装完成。
那么下面我们来安装Ruby,目前Ruby流通的版本很多,1.8.x – 1.9.x都有,考虑到我们要使用Rails 3.0的框架,所以,1.8.7一下的版本就不需要考虑了。推荐用Ruby Enterprise Edition (ree),这个版本的Ruby是在MRI Rubies的基础上进行开发的,基于1.8.x版本的,然后也打了了GC补丁例如MBARI,在运行效率上面有显著的提高,推荐的生产环境中使用。为了和生产环境保持一致,我们在自己的开发环境也使用这个版本就行了。在Terminal中输入:
rvm install ree
经过一系列的编译,你将完整的得到REE
ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.3.1], MBARI 0x6770, Ruby Enterprise Edition 2010.01
这个时候,你系统默认的ruby还是在
/usr/bin/ruby下面的,在Terminal中输入如下命令
rvm use ree --default
which ruby
最后返回的结果是:
/Users/xxxxxxx/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
那么这个时候1.8.7版本的Ruby已经安装好,并且成为了你这个用户下面默认的版本,如果你要查询rvm其他的命令,你直接输入rvm就能获得帮助。
下一步,我们需要安装RubyGems,是一个Ruby gem的包管理软件,在 http://rubygems.org/pages/download 下载最新的 1.3.7版本。解压缩后,进入目录,在Terminal中输入:
ruby setup.rb
就应该很快安装好,依然输入which gem,能够返回/Users/xxxxxx/.rvm/rubies/ree-1.8.7-2010.01/bin/gem的路径就可以了。
最后,我们来安装Rails 3.0。到目前为止,Rails 3.0还是在beta中,所以直接在Terminal中输入:
gem install rails --pre
经过一段时间,Rails 3.0 beta4就安装好了。
测试一下环境,在随意的目录中,输入
rails new TestApp --database=mysql
就能获得下面生成的文件
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/views/layouts/application.html.erb
create app/models
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/fixtures
create test/functional
create test/integration
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
Okay,快速的搭建Ruby On Rails环境已经好了。
如果你还要安装Mysql数据库,请参考另外的文章:安装本地WordPress测试环境
-
http://cheap--uggs.us Cheap UGGS
-
Aksoft
-
http://allenchan.org/ Allen Chan