Ruby on Rails,环境安装和Gems

边晓宇 2012-06-08 12:20:18
加精
http://blog.csdn.net/abbuggy/article/details/7400848
如果你的电脑上没有安装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就是一个最著名的RubyGem。RubyGems是标准的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)
mini<span class="searchword2b864a" id="test">test</span> (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-<span class="searchword2b864a" id="test">test</span> (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
...全文
3514 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
isurprise 2012-08-10
  • 打赏
  • 举报
回复
感谢分享!
LAONINGA098 2012-06-27
  • 打赏
  • 举报
回复
感谢分享!~~
insist3 2012-06-24
  • 打赏
  • 举报
回复
多谢分享啊 ,入门新手啥都看不懂。。
qqsega 2012-06-20
  • 打赏
  • 举报
回复
谢谢!!
morris88 2012-06-17
  • 打赏
  • 举报
回复
哎,貌似 CSDN 的编程语言高亮显示都不支持 ruby
iam_song 2012-06-17
  • 打赏
  • 举报
回复
非常感谢楼主分享~
haitao 2012-06-16
  • 打赏
  • 举报
回复
命令行太难用,看fxri不错,好不容易下载、安装了
一运行,报错:
r:\>fxri
d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/fxri-0.3.7/fxri:4:in `load'
: cannot load such file -- fxri.rb (LoadError)
from d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/fxri-0.3.7/fxr
i:4:in `<top (required)>'
from d:/RailsInstaller/Ruby1.9.3/bin/fxri:23:in `load'
from d:/RailsInstaller/Ruby1.9.3/bin/fxri:23:in `<main>'

好像d:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\fxri-0.3.7\fxbi文件
#!/bin/env ruby

#Dir.chdir(File.dirname(File.expand_path(__FILE__))) //这一句不应该注释?
load 'fxri.rb'

于是,取消这行注释,不再很快退出了,但是cpu高负荷运行几秒钟后,还是报错了:
D:\RailsInstaller>fxri
d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:
36:in `require': cannot load such file -- lib/RiManager (LoadError)
from d:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
from fxri.rb:41:in `<top (required)>'
from d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/fxri-0.3.7/fxr
i:4:in `load'
from d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/fxri-0.3.7/fxr
i:4:in `<top (required)>'
from d:/RailsInstaller/Ruby1.9.3/bin/fxri:23:in `load'
from d:/RailsInstaller/Ruby1.9.3/bin/fxri:23:in `<main>'

——不知道是不是fxbi的版本太低?它最新的版本都是 2008-09-20 13:24 的。。。。。。。
fankun6157 2012-06-15
  • 打赏
  • 举报
回复
谢谢 楼主··
youhao1999 2012-06-14
  • 打赏
  • 举报
回复
多谢楼主分享
haitao 2012-06-14
  • 打赏
  • 举报
回复
搜了一下ruby的中文手册和入门示例,都没找到满意的
安装了运行环境,想写个8皇后练练手,都不知道怎么开始。。。。。。

这一点,远远不如python了
z546900841 2012-06-14
  • 打赏
  • 举报
回复
感谢共享信息,还是常常用到
pinglj2008 2012-06-14
  • 打赏
  • 举报
回复
谢谢分享
qq261781640 2012-06-13
  • 打赏
  • 举报
回复
支持,感谢分享
支持,感谢分享
  • 打赏
  • 举报
回复
支持,感谢分享
mcrobebush8 2012-06-13
  • 打赏
  • 举报
回复
thank you very much!
wwqwwf 2012-06-13
  • 打赏
  • 举报
回复
感谢共享信息,还是常常用到
ycproc 2012-06-13
  • 打赏
  • 举报
回复
Lan的csdn 2012-06-13
  • 打赏
  • 举报
回复
多谢分享了哈
nvwang4444 2012-06-13
  • 打赏
  • 举报
回复
太好了 哇咔咔
taito 2012-06-13
  • 打赏
  • 举报
回复
感谢分享!~~
加载更多回复(7)

2,763

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ruby/Rails
社区管理员
  • Ruby/Rails社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧