LoginSignup
36
34

More than 5 years have passed since last update.

Windows10(64bit) で Ruby 2.2.3 + Rails 4.2.5

Last updated at Posted at 2016-01-15

本記事は
Windows(64bit) で Ruby 2.2.3 + Rails 4.2.4を参考にして、Rubyのインストールに関する情報を少し付け加えたものです。

  • Ruby等をゼロからインストール
  • 動作確認

します。

環境

Windows10/64bitです。
sys.PNG

手順

0. Rubyのインストール

0.1. rubyinstallerのダウンロードとインストール

本当は2.3を入れたかったのですが、rubyinstallerを使わないとうまくDevkitを使えずに詰んでしまったので、rubyinstallerを使います。
http://rubyinstaller.org/downloads/
この記事を書いた時点で最新のRuby 2.2.3 (x64)をダウンロードします。
環境変数Pathにbinを追加することを忘れないようにします。(チェックボックスに注意する)
特に何事もなく完了します。

0.2. devkitのダウンロードとインストール

rubyinstallerと同じ場所にあるdevkitの最新版をダウンロードします。
DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe
でした。これを解凍して、c:\devkitに置き、以下を実行します。

> cd c:\devkit
> ruby dk.rb init
> ruby dk.rb install

実行したときのメッセージはInstallingで終わってしまいますが、これで良いようです。

[INFO] Updating convenience notice gem override for 'C:/Ruby22-x64'
[INFO] Installing 'C:/Ruby22-x64/lib/ruby/site_ruby/devkit.rb'

1. sqlite3 関連

1.1. SQLite3 のビルド

sqlite3.dll だけならば本家サイトからバイナリをダウンロード出来ます。
SQLite Home Page
この記事を書いた時点での安定稼働最新版は
sqlite-dll-win64-x64-3100000.zip
でした。

sqlite3.exe も欲しい場合は自分で作ると良い。
Windows で SQLite3 の 64bit バイナリを自分で作る - Qiita

ただ、これ、結局単純に動かすのには使っていないような。DBを使うと必要になるんでしょうか。

2. nokogiri 関連

2.1. 必要なバイナリのダウンロード

http://xmlsoft.org/sources/win32/64bit/ から

  • iconv-1.14-win32-x86_64.7z
  • libxml2-2.9.3-win32-x86_64.7z
  • libxslt-1.1.28-win32-x86_64.7z

をダウンロードし、適当なフォルダ(仮に C:\temp とする)に展開する。このとき bin, include, lib, share のフォルダは全て統合する。さらに以下を実行。

> cp C:\temp\bin\*.dll C:\temp\lib

libxml2-2.9.3のみバージョンアップしていますが、他のファイルも日付は新しくなっていました。中身は未確認です。

2.2. nokogiri gem のインストール

管理者権限で実行したコマンドプロンプトからgemを実行します。

> gem install nokogiri --platform=ruby -- --use-system-libraries --with-iconv-include=C:/temp/include --with-iconv-lib=C:/temp/lib --with-xml2-include=C:/temp/include/libxml2 --with-xml2-lib=C:/temp/lib --with-xslt-include=C:/temp/include --with-xslt-lib=C:/temp/lib
> gem install nokogiri

2.3. 各種ファイルのコピー

nokogiri.soは既にできていたので、dllのみコピーします。

> cp C:\temp\lib\*.dll C:\Ruby22-x64\bin

2.4. railsのインストール

> gem install rails

"327seconds"ぐらいかかりました。特にエラーは出ませんでした。

3. 動作確認

3.1. Hello World的なプログラムの作成

以下のコマンドを実行すると、新しくgemが入ったりしつつ、ファイルがたくさんできます。

> cd c:\temp\sample
> rails new ./
> rails generate controller sampledesu

generateの実行結果は次のような感じ:

c:\temp\sample>rails generate controller sampledesu
      create  app/controllers/sampledesu_controller.rb
      invoke  erb
      create    app/views/sampledesu
      invoke  test_unit
      create    test/controllers/sampledesu_controller_test.rb
      invoke  helper
      create    app/helpers/sampledesu_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/sampledesu.coffee
      invoke    scss
      create      app/assets/stylesheets/sampledesu.scss

http://d.hatena.ne.jp/yk5656/20140102/1388646091
を参考にしながら適当に作ります。

app\controllers\sampledesu_controller.rb
class SampledesuController < ApplicationController
  def index
    render :text => "Hello, world!にほんご"
  end
end

★重要:このファイルはutf-8で保存します。cp932だと"something went wrong"などと言われてしまいます。。。

config\routes.rb
Rails.application.routes.draw do
  root 'sampledesu#index'
end

3.2. サーバー起動

コマンドプロンプトでrails serverします。

c:\temp\sample>rails server
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server

ブラウザでアクセスしてみます。

hw.PNG

たのしめ!

36
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
34