RubyとRubyGemsとrailsのインストール

ruby on railsでアプリケーションを作ってみたいと思うので、環境を構築します。
Windows Vistaにインストールします。
railsをインストールするためにはまずRubyとRubyGemのインストールが必要です。
過程をメモしておきます。

Rubyのインストール

Rubyダウンロード

本日付け(2010/03/29)での最新版を以下のサイトよりダウンロード
http://rubyinstaller.org/download.html
今回はwindows用のRubyInstallerを使用します。
Ruby 1.9.1-p378 (RC2)をダウンロード。

Rubyインストール

ダウンロードしたrubyinstaller-1.9.1-p378-rc2.exeを実行。
インストーラが起動します。

  • インストール指定フォルダを適当に以下のように指定します。
D:\ruby\ruby19
  • インストーラ画面の最後の方で、パスを自動的に設定するオプションがあるので、チェックを入れます。
インストールできているか確認

コマンドプロンプトを起動し、以下のコマンドを実行します。

>ruby -v

以下のように返ってきたらインストール成功です。

ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

RubyGemsインストール

RubyGemsダウンロード

以下のサイトより、RubyGemsをダウンロードします。
http://rubyforge.org/frs/?group_id=126
私の場合は現時点で最新のrubygems-1.3.6.zipを選択。

RubyGemsインストール

ダウンロードしたファイルを解凍した上で、適当なディレクトリに展開します。
私の場合はRubyをインストールしたディレクトリ「D:\ruby\ruby91」の中に展開しました。
rubygems-1.3.6というディレクトリが作成され、その中にインストールに必要なファイルが含まれています。
インストールするためには、rubygems-1.3.6のディレクトリ直下で、setup.rbを以下のように実行します。

D:\ruby\ruby91\rubygems-1.3.6>ruby setup.rb

すると、RubyGemsのインストールが開始されます。
ちなみに以下のようなログが出力されます。

RubyGems 1.3.6 installed

・ソ=== 1.3.6 / 2010-02-17

NOTE:

http://rubygems.org is now the default source for downloading gems.

You may have sources set via ~/.gemrc, so you should replace
http://gems.rubyforge.org with http://rubygems.org

http://gems.rubyforge.org will continue to work for the forseeable future.

New features:

* `gem` commands
  * Added `gem push` and `gem owner` for interacting with modern/Gemcutter
    sources
  * `gem dep` now supports --prerelease.
  * `gem fetch` now supports --prerelease.
  * `gem server` now supports --bind.  Patch #27357 by Bruno Michel.
  * `gem rdoc` no longer overwrites built documentation.  Use --overwrite
    force rebuilding.  Patch #25982 by Akinori MUSHA.
* Captial letters are now allowed in prerelease versions.

Bug fixes:

* Development deps are no longer added to rubygems-update gem so older
  versions can update sucessfully.
* Installer bugs:
  * Prerelease gems can now depend on non-prerelease gems.
  * Development dependencies are ignored unless explicitly needed.  Bug #27608
    by Roger Pack.
* `gem` commands
  * `gem which` now fails if no paths were found.  Adapted patch #27681 by
    Caio Chassot.
  * `gem server` no longer has invalid markup.  Bug #27045 by Eric Young.
  * `gem list` and friends show both prerelease and regular gems when
    --prerelease --all is given
* Gem::Format no longer crashes on empty files.  Bug #27292 by Ian Ragsdale.
* Gem::GemPathSearcher handles nil require_paths. Patch #27334 by Roger Pack.
* Gem::RemoteFetcher no longer copies the file if it is where we want it.
  Patch #27409 by Jakub ナナ・astnテス.

Deprecation Notices:

* lib/rubygems/timer.rb has been removed.
* Gem::Dependency#version_requirements is deprecated and will be removed on or
  after August 2010.
* Bulk index update is no longer supported.
* Gem::manage_gems was removed in 1.3.3.
* Time::today was removed in 1.3.3.


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

RubyGems installed the following executables:
        D:/ruby/ruby19/bin/gem
RubyGemsインストールできたか確認
D:\ruby\ruby19\rubygems-1.3.6>gem -v
1.3.6

これでOKです。

railsインストール

railsをインストールするためには、以下のコマンドを実行します。

D:\ruby\ruby19\rubygems-1.3.6>gem install rails

以下のようなログが出力されました。

Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
Successfully installed rack-1.0.1
Successfully installed actionpack-2.3.5
Successfully installed actionmailer-2.3.5
Successfully installed activeresource-2.3.5
Successfully installed rails-2.3.5
8 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.5...
Installing ri documentation for activerecord-2.3.5...
Installing ri documentation for rack-1.0.1...
Installing ri documentation for actionpack-2.3.5...
Installing ri documentation for actionmailer-2.3.5...
Installing ri documentation for activeresource-2.3.5...
Installing ri documentation for rails-2.3.5...
Updating class cache with 132 classes...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.5...
Installing RDoc documentation for activerecord-2.3.5...
Installing RDoc documentation for rack-1.0.1...
Installing RDoc documentation for actionpack-2.3.5...
Installing RDoc documentation for actionmailer-2.3.5...
Installing RDoc documentation for activeresource-2.3.5...
Installing RDoc documentation for rails-2.3.5...

正常にインストールされたようです。
これでrailsの開発環境が整いました。

追記(2010/3/30)

railsでアプリケーションを作るためには、データベースが必要です。
sqlite3が組み込みで入ってると思っていましたが、違うようです。
次回の記事でやり方をメモしておこうと思います。

そして、sqlite3-ruby(コネクタみたいなものでしょうか)をインストールしますが、インストールできません。
ググってみるとruby1.9.1にはまだsqlite3-rubyの最新バージョンが対応していないとか…?
なにかどうにもこうにもはまってしまったので、とりあえずrubyのバージョンを1.8.7に下げて再度インストールしなおしました。