5 月 4, 2009 • Posted in: Centos5, Ruby, Ruby on Rails

CentOS5.2にRuby on Rails を導入

rails サーバ管理ツール作成用にRuby on Railsに挑戦してみることにする。
先ずは、導入から。

Rubyは導入済みなので、先ずは最新化

# yum update ruby

Loading “fastestmirror” plugin
Loading mirror speeds from cached hostfile
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
* base: www.ftp.ne.jp
* addons: www.ftp.ne.jp
* adobe-linux-i386: linuxdownload.adobe.com
Setting up Update Process
Resolving Dependencies
–> Running transaction check
—> Package ruby.i386 0:1.8.5-5.el5_2.6 set to be updated
   :
Updated: ruby.i386 0:1.8.5-5.el5_2.6 ruby-libs.i386 0:1.8.5-5.el5_2.6
Dependency Updated: ruby-devel.i386 0:1.8.5-5.el5_2.6 ruby-irb.i386 0:1.8.5-5.el5_2.6 ruby-rdoc.i386 0:1.8.5-5.el5_2.6
Complete!


インストール済みパッケージを確認

# gem list

*** LOCAL GEMS ***

rmagick (2.7.0)
Ruby binding to ImageMagick

sources (0.0.1)
This package provides download sources for remote gem installation

Railsをインストール

# gem install rails –include-dependencies
Successfully installed rails-2.3.2
Successfully installed rake-0.8.4
Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Installing ri documentation for rake-0.8.4…
Installing ri documentation for activesupport-2.3.2…
  :
Installing RDoc documentation for actionmailer-2.3.2…
Installing RDoc documentation for activeresource-2.3.2…

SQLite3を導入

# gem install sqlite3-ruby
Select which gem to install for your platform (i386-linux)
1. sqlite3-ruby 1.2.4 (ruby)
2. sqlite3-ruby 1.2.3 (x86-mingw32)
3. sqlite3-ruby 1.2.3 (mswin32)
4. sqlite3-ruby 1.2.3 (ruby)
5. Skip this gem
6. Cancel installation
> 1
Building native extensions. This could take a while…
Successfully installed sqlite3-ruby-1.2.4
Installing ri documentation for sqlite3-ruby-1.2.4…
Installing RDoc documentation for sqlite3-ruby-1.2.4…

テスト

$ mkdir ror
$ cd ror
$ rails myapp
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
:
create log/server.log
create log/production.log
create log/development.log
create log/test.log
$ cd myapp
$ script/server
Rails requires RubyGems >= 1.3.1 (you have 0.9.4). Please `gem update –system` and try again.

RubyGems が古いといわれたので、更新

# gem update –system
Updating RubyGems…
Attempting remote update of rubygems-update
Successfully installed rubygems-update-1.3.2
Updating version of RubyGems to 1.3.2
Installing RubyGems 1.3.2
  :
——————————————————————————

RubyGems installed the following executables:
/usr/bin/gem

RubyGems system software updated

再度起動してみる

$ ./script/server
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-05-04 10:40:42] INFO WEBrick 1.3.1
[2009-05-04 10:40:42] INFO ruby 1.8.5 (2006-08-25) [i386-linux]
[2009-05-04 10:40:42] INFO WEBrick::HTTPServer#start: pid=26566 port=3000

今度は正常に起動したので、WEBブラウザから接続してみる。

http://192.168.xxx.xxx:3000/

ws0000021
以上で、セットアップは完了。
後は、実際のアプリケーションを作ってみよう。

Leave a Reply