Ruby on Rails,环境安装和Gems

如果你的电脑上没有安装Ruby,还等什么,我们去官方网站下载安装程序吧。对于运行Rails3.0,最低需要Ruby1.8.7,现在最新的稳定版应该是1.9.3。在Ruby的官方网站http://www.ruby-lang.org/有为不同操作系统安装Ruby使用的程序连接。如果使用的是windows,直接下载RubyInstaller并像安装普通软件一样安装就可以。我们安装Ruby是为了使用Rails,人家还给咱专门提供了同样基于RubyInstaller的RailsInstaller,能够将一些其他的开发工具一并安装,方便省力。最新版本的RailsInstaller是2.1.0,我们就用这个。这个版本附带有:   

  • Ruby 1.9.3-p125
  • Rails 3.2
  • Bundler 1.0.18
  • Git 1.7.6
  • Sqlite 3.7.3
  • TinyTDS 0.4.5
  • SQL Server support 3.3.3
  • DevKit


安装RailsInstaller时,最好选上“Add executables for Ruby,Git and DevKit to the PATH”,将Ruby,Git,DevKit的bin目录加入PATH环境变量中,方便直接在命令行中使用。当然你也可以不选则这个选项,改为每次执行命令时键入全路径。我没有测试过如果有中文或空格会不会出错,但为了避免不必要的麻烦还是谨慎为好。


如此一来安装工作完毕,测试一下是否工作正常。通过“开始-所有程序-RailsInstaller-Command Prompt with Ruby and Rails”启动命令行工作环境。

查看Ruby版本:

E:\greensoft\RailsInstaller>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

查看Rails版本:

E:\greensoft\RailsInstaller>rails -v
Rails 3.2.1

查看Gems版本:

E:\greensoft\RailsInstaller>gem -v
1.8.19

一切正常!

使用Rails的过程中你经常需要RubyGems(gem)工具来管理以及升级依赖的库(RubyGem)。RubyGem,就是一个个用Ruby语言编写的程序软件包,Rails就是一个最著名的RubyGemRubyGems是标准的Ruby包管理器,它的功能类似于Linux下的apt-get。

我们来使用gem查看一下RailsInstaller已经安装好的gem包:

E:\greensoft\RailsInstaller>gem list

*** LOCAL GEMS ***

actionmailer (3.2.1)
actionpack (3.2.1)
activemodel (3.2.1)
activerecord (3.2.1)
activerecord-sqlserver-adapter (3.2.1)
activeresource (3.2.1)
activesupport (3.2.1)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.0)
bundler (1.0.22)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
erubis (2.7.0)
execjs (1.3.0)
hike (1.2.1)
i18n (0.6.0)
io-console (0.3)
journey (1.0.3, 1.0.2)
jquery-rails (2.0.1)
json (1.6.5, 1.5.4)
mail (2.4.4, 2.4.1)
mime-types (1.18, 1.17.2)
minitest (2.5.1)
multi_json (1.1.0)
mysql2 (0.3.11 x86-mingw32)
pg (0.13.1 x86-mingw32)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2, 1.1)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.1)
railties (3.2.1)
rake (0.9.2.2)
rb-readline (0.4.2)
rdoc (3.12, 3.9.4)
rubygems-update (1.8.19)
rubyzip (0.9.6.1)
sass (3.1.15)
sass-rails (3.2.5)
sprockets (2.1.2)
sqlite3 (1.3.5 x86-mingw32)
sqlite3-ruby (1.3.3)
thor (0.14.6)
tilt (1.3.3)
tiny_tds (0.5.1 x86-mingw32)
treetop (1.4.10)
tzinfo (0.3.32, 0.3.31)
uglifier (1.2.3)


将gem工具升级到最新版本:

E:\greensoft\RailsInstaller>gem update --system
Updating rubygems-update
Fetching: rubygems-update-1.8.21.gem (100%)
Successfully installed rubygems-update-1.8.21
Installing RubyGems 1.8.21
RubyGems 1.8.21 installed

== 1.8.21 / 2012-03-22

* 2 bug fixes:

  * Add workaround for buggy yaml output from 1.9.2
  * Force 1.9.1 to remove it's prelude code. Fixes #305


------------------------------------------------------------------------------

RubyGems installed the following executables:
	E:/greensoft/RailsInstaller/Ruby1.9.3/bin/gem

RubyGems system software updated

使用gem安装gem包:gem会访问internet,获取你希望安装的gem以及这个gem所依赖的其他gems。

E:\greensoft\RailsInstaller>gem install rake
Successfully installed rake-0.9.2.2
1 gem installed
Installing ri documentation for rake-0.9.2.2...
活动代码页: 936
Installing RDoc documentation for rake-0.9.2.2...

有关查看gem工具使用的更多信息:

E:\greensoft\RailsInstaller>gem --help
RubyGems is a sophisticated package manager for Ruby.  This is a
basic help message containing pointers to more information.

  Usage:
    gem -h/--help
    gem -v/--version
    gem command [arguments...] [options...]

  Examples:
    gem install rake
    gem list --local
    gem build package.gemspec
    gem help install

  Further help:
    gem help commands            list all 'gem' commands
    gem help examples            show some examples of usage
    gem help platforms           show information about platforms
    gem help <COMMAND>           show help on COMMAND
                                   (e.g. 'gem help install')
    gem server                   present a web page at
                                 http://localhost:8808/
                                 with info about installed gems
  Further information:
    http://rubygems.rubyforge.org
posted on 2012-03-27 23:53  边晓宇  阅读(2411)  评论(0编辑  收藏  举报