MacでRubyOnRailsの環境構築
ror_mac
Ruby on Rails @ Mac
なんかRoRの案件に放り込まれたので、いそいそと勉強中。とりあえずは、MacでRubyOnRailsの環境構築
1.RubyおよびRailsのインストール
参考サイト:http://www.opentone.co.jp/news/release/article03/article0301.html
とりあえずターミナルで必要そうなコマンドを片っ端から叩いておく。
$ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
$ gem -v
1.8.5
$ sudo gem update --system
Latest version currently installed. Aborting.
$ sudo gem list --local
$ sudo gem install rails
$ rails -v
Rails 3.0.9
$ sudo gem install sqlite3
$ sqlite3 -version
3.7.5
$ sudo gem install sqlite3-ruby
$ sudo gem install heroku
楽ちんだと思っていたら、railsのインストールで怒られた。。。
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
ググったところmacの“Command line tools”がインストールされていないことが原因だそうだ。そんなん知らんがな。。。
参考サイト:http://blog.toshimaru.net/macmkmfrb-cant-find-header-files-for-ruby/
再チャレンジの末、成功。(やったね)
$ sudo gem install rails
...
Done installing documentation for json, rdoc, railties, bundler, rails after 52 seconds
5 gems installed
$ rails -v
Rails 3.2.13
2.aptana studio(eclipseプラグイン)のインストール
今度eclipseのverを挙げる(->4.2)のでその時にもう一度インストール手順をメモろう。
3.サンプルプロジェクト
eclipseからrailsプロジェクトを新規作成。コンソールに以下の表示。
$ rails new .
exist
create README.rdoc
create Rakefile
...
Enter your password to install the bundled RubyGems to your system:
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.4)
...
Using bundler (1.3.5)
Installing coffee-script-source (1.6.2)
Errno::EACCES: Permission denied - /Library/Ruby/Gems/1.8/build_info/coffee-script-source-1.6.2.info
An error occurred while installing coffee-script-source (1.6.2), and Bundler cannot continue.
Make sure that `gem install coffee-script-source -v '1.6.2'` succeeds before bundling.
どうやらrailsの作成は成功したが、bundle install でコケた模様。足りなくてエラーとなったgemをひたすらインストール。(疲れた)
以下、ようやく動いたよ。
$ bundle install
...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ rails server
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-05-27 00:16:13] INFO WEBrick 1.3.1
[2013-05-27 00:16:13] INFO ruby 1.8.7 (2012-02-08) [universal-darwin12.0]
[2013-05-27 00:16:13] INFO WEBrick::HTTPServer#start: pid=21582 port=3000
Started GET "/assets/rails.png" for 127.0.0.1 at Mon May 27 00:16:36 +0900 2013
Served asset /rails.png - 200 OK (17ms)
なにはなくともハローワールド。
$ rails generate controller hello
create app/controllers/hello_controller.rb
invoke erb
create app/views/hello
invoke test_unit
create test/functional/hello_controller_test.rb
invoke helper
create app/helpers/hello_helper.rb
invoke test_unit
create test/unit/helpers/hello_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/hello.js.coffee
invoke scss
create app/assets/stylesheets/hello.css.scss
/test_rails/app/controllers/hello_controller.rb
# coding: utf-8
class HelloController < ApplicationController
def index
render :text => 'Hello, RoR@Mac!!'
end
end
お疲れ様でした。