CentOS5.6へRuby on Rails3をインストール(3)

では目的のRials3.0.5をインストールします。

1.gemのバージョンを確認する。

[sourcecode language="bash"]

gem -v

1.3.7 [/sourcecode]

2.Ruby on Railsをgemを利用してインストールする。

今回はRuby on Railsのバージョンを3.0.5としたいためオプションでバージョンを指定します。(-v 3.0.5)

[sourcecode language="bash"]

gem install rails -v 3.0.5

Successfully installed activesupport-3.0.5 Successfully installed builder-2.1.2 Successfully installed i18n-0.6.0 Successfully installed activemodel-3.0.5 Successfully installed rack-1.2.4 Successfully installed rack-test-0.5.7 Successfully installed rack-mount-0.6.14 Successfully installed tzinfo-0.3.30 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.5 Successfully installed arel-2.0.10 Successfully installed activerecord-3.0.5 Successfully installed activeresource-3.0.5 Successfully installed mime-types-1.17.2 Successfully installed polyglot-0.3.3 Successfully installed treetop-1.4.10 Successfully installed mail-2.2.19 Successfully installed actionmailer-3.0.5 Successfully installed thor-0.14.6 Successfully installed railties-3.0.5 Successfully installed bundler-1.0.21 Successfully installed rails-3.0.5 23 gems installed Installing ri documentation for activesupport-3.0.5... Installing ri documentation for builder-2.1.2... Installing ri documentation for i18n-0.6.0... Installing ri documentation for activemodel-3.0.5... Installing ri documentation for rack-1.2.4... Installing ri documentation for rack-test-0.5.7... Installing ri documentation for rack-mount-0.6.14... Installing ri documentation for tzinfo-0.3.30... Installing ri documentation for abstract-1.0.0... Installing ri documentation for erubis-2.6.6... Installing ri documentation for actionpack-3.0.5... Installing ri documentation for arel-2.0.10... Installing ri documentation for activerecord-3.0.5... Installing ri documentation for activeresource-3.0.5... Installing ri documentation for mime-types-1.17.2... Installing ri documentation for polyglot-0.3.3... Installing ri documentation for treetop-1.4.10... Installing ri documentation for mail-2.2.19... Installing ri documentation for actionmailer-3.0.5... Installing ri documentation for thor-0.14.6... Installing ri documentation for railties-3.0.5... Installing ri documentation for bundler-1.0.21... Installing ri documentation for rails-3.0.5... Installing RDoc documentation for activesupport-3.0.5... Installing RDoc documentation for builder-2.1.2... Installing RDoc documentation for i18n-0.6.0... Installing RDoc documentation for activemodel-3.0.5... Installing RDoc documentation for rack-1.2.4... Installing RDoc documentation for rack-test-0.5.7... Installing RDoc documentation for rack-mount-0.6.14... Installing RDoc documentation for tzinfo-0.3.30... Installing RDoc documentation for abstract-1.0.0... Installing RDoc documentation for erubis-2.6.6... Installing RDoc documentation for actionpack-3.0.5... Installing RDoc documentation for arel-2.0.10... Installing RDoc documentation for activerecord-3.0.5... Installing RDoc documentation for activeresource-3.0.5... Installing RDoc documentation for mime-types-1.17.2... Installing RDoc documentation for polyglot-0.3.3... Installing RDoc documentation for treetop-1.4.10... Installing RDoc documentation for mail-2.2.19... Installing RDoc documentation for actionmailer-3.0.5... Installing RDoc documentation for thor-0.14.6... Installing RDoc documentation for railties-3.0.5... Installing RDoc documentation for bundler-1.0.21... Installing RDoc documentation for rails-3.0.5... [/sourcecode]

3.インストールしたバージョンを確認する。

ここまででRuby on Rails3のインストールは完了です。

[sourcecode language="bash"]

rails -v

Rails 3.0.5 [/sourcecode]

4.SQLite3に関連するドライバをインストールする。

Ruby on Rails3で使用するデータベースのドライバを取得します。

[sourcecode language="bash"]

gem install sqlite3

Building native extensions. This could take a while... Successfully installed sqlite3-1.3.4 1 gem installed Installing ri documentation for sqlite3-1.3.4... Installing RDoc documentation for sqlite3-1.3.4... [/sourcecode]

5.Railsプロジェクトを作成しWEBrickが起動するか確認します。

プロジェクトの作成はrootではなく一般ユーザーで行います。(今回はymanabeユーザー)

[sourcecode language="bash"]

su ymanabe

$ cd $ mkdir railbook $ cd railbook/ $ rails new railbook 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/mailers create app/models create app/views/layouts/application.html.erb 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/fixtures create test/functional create test/integration create test/performance/browsing_test.rb create test/test_helper.rb create test/unit create tmp create tmp/sessions create tmp/sockets create tmp/cache create tmp/pids create vendor/plugins create vendor/plugins/.gitkeep [/sourcecode]

6.WEBrickを起動してアプリケーションが動作していることを確認する。

[sourcecode language="bash"] rails server => Booting WEBrick => Rails 3.0.5 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-11-06 22:05:13] INFO WEBrick 1.3.1 [2011-11-06 22:05:13] INFO ruby 1.9.2 (2011-02-18) [x86_64-linux] [2011-11-06 22:05:13] INFO WEBrick::HTTPServer#start: pid=7035 port=3000 [2011-11-06 22:06:07] INFO going to shutdown ... [2011-11-06 22:06:07] INFO WEBrick::HTTPServer#start done. [/sourcecode]

この通り画面が表示されれば動作しています!

とりあえず、Ruby on Rails3がインストールできた訳ですが、実際にはこの後apatchのインストールとPassengerとの連携など様々な事を行う必要があります。また、アプリケーションで使用するプラグインがあればそちらも必要になるのかな?

とりあえず、今回は環境作成ということでここまでとします。あとは、繰り返し環境構築してなれることで次への足がかりにしたいと思います。

ちなみに、環境構築にかかった時間(CentOSのインストールからRailsのWEBrick動作確認まで)は3時間程度です。調べながら行ったのですが、それほど時間はかかりませんでした。CentOSのインストールで失敗したため1.5時間ほどかかったのが一番いたかったですねぇw