近年来,ruby on rails逐渐火了起来,我想各位码农早就耳闻,特别是那些做B/S项目的童鞋,早就想跃跃一试了。
笔者也是初次接触ruby on rails ,我想,对于初学者来说,最好的学习方式就是,自己搭建一个环境,让程序飞起来先。
在ubuntu上搭建ruby on rails 环境的时候,多数人都只是安装好ruby之后,然后执行
$ gem install rails
这种在线安装,通常是安装官网最新的rais版本(目前发布的最新的版本:4.0.2)
值得注意的是,软件不断在更新,难保有一天我们会遇到更高版本的rails application,我们的调试将变得很麻烦.
庆幸的是,有一个ruby 版本管理器,常称为rvm[RubyVersion Manager].
官方(http://rvm.io/)解释如下:
RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
RVM 允许ruby,gems和irb之间相互独立。
通过以下的场景可以阐明这一点.
比如,我们对ruby 1.9.2-head 测试两种版本的gem.
你可以为 ruby 1.9.2-head安装一个默认的gemset
然后再为之创建一个不同版本的gemset,便于两者之间的切换[ switch between them easily.]。
Example: testing gems
备注;带$的命令行在终端中执行
$ rvm 1.9.2-head@testing
will use a ‘1.9.2-head@testing‘ GEM_HOME (be sure to create it first), whereas:
$ rvm 1.9.2-head
will use the default 1.9.2-head GEM_HOME :)
Example: Rails versions & upgrading apps
To illustrate the point, let‘s talk about a common use case. Assume you are testing out a rails application against a new Rails release. RVM makes such testing very easy, by letting you quickly switch between multiple Rails versions. First, let‘s set up the environments:
$ rvm 1.9.2-head
$ gem install rails -v 2.3.3
$ rvm gemset create rails222 rails126
Gemset ‘rails222‘ created.
Gemset ‘rails126‘ created.
$ rvm 1.9.2-head@rails222
$ gem install rails -v 2.2.2
$ rvm 1.9.2-head@rails126
$ gem install rails -v 1.2.6
$ rvm 1.8.7
$ gem install rails -v 1.2.3
Note that, for each of the ruby installs above, you can have completely separate versions!
Now that your environments are set up, you can simply switch between Rails versions and Ruby versions as follows.
$ rvm 1.9.2-head@rails126 ; rails --version
Rails 1.2.6
$ rvm 1.8.7 ; rails --version
Rails 1.2.3
$ rvm 1.9.2-head@rails220 ; rails --version
Rails 2.2.2
$ rvm 1.9.2-head ; rails --version
Rails 2.3.3
时间仓促,先到这里.