Ruby1.9.3 + Rails3.2.3 プロジェクト作成からWEBrickの起動まで。
前回の「RVMでRubyとGem環境を切り替え。Railsのインストールまで。」の続き。
環境をおさらい。
$ rvm -v rvm 1.13.4 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/] $ ruby -v ruby 1.9.3p203 (2012-05-04 revision 35536) [i686-linux] $ gem -v 1.8.24 $ rails -v Rails 3.2.3
サンプルプロジェクトを作ります。
$ rails new sampleapp create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/images/rails.png create app/assets/javascripts/application.js create app/assets/stylesheets/application.css 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 app/mailers/.gitkeep create app/models/.gitkeep 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/initializers/wrap_parameters.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 lib/assets create lib/assets/.gitkeep create log create log/.gitkeep 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 script create script/rails create test/fixtures create test/fixtures/.gitkeep create test/functional create test/functional/.gitkeep create test/integration create test/integration/.gitkeep create test/unit create test/unit/.gitkeep create test/performance/browsing_test.rb create test/test_helper.rb create tmp/cache create tmp/cache/assets create vendor/assets/javascripts create vendor/assets/javascripts/.gitkeep create vendor/assets/stylesheets create vendor/assets/stylesheets/.gitkeep create vendor/plugins create vendor/plugins/.gitkeep run bundle install Fetching gem metadata from https://rubygems.org/......... Using rake (0.9.2.2) Using i18n (0.6.0) Using multi_json (1.3.4) Using activesupport (3.2.3) Using builder (3.0.0) Using activemodel (3.2.3) Using erubis (2.7.0) Using journey (1.0.3) Using rack (1.4.1) Using rack-cache (1.2) Using rack-test (0.6.1) Using hike (1.2.1) Using tilt (1.3.3) Using sprockets (2.1.3) Using actionpack (3.2.3) Using mime-types (1.18) Using polyglot (0.3.3) Using treetop (1.4.10) Using mail (2.4.4) Using actionmailer (3.2.3) Using arel (3.0.2) Using tzinfo (0.3.33) Using activerecord (3.2.3) Using activeresource (3.2.3) Using bundler (1.1.3) Installing coffee-script-source (1.3.1) Installing execjs (1.3.1) Installing coffee-script (2.2.0) Using rack-ssl (1.3.2) Using json (1.7.0) Using rdoc (3.12) Using thor (0.14.6) Using railties (3.2.3) Installing coffee-rails (3.2.2) Installing jquery-rails (2.0.2) Using rails (3.2.3) Installing sass (3.1.17) Installing sass-rails (3.2.5) Installing sqlite3 (1.3.6) with native extensions Installing uglifier (1.2.4) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
でぎだぞ。
rails serverを立ち上げてみる。
$ cd sampleapp $ rails s /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/execjs-1.3.1/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/execjs-1.3.1/lib/execjs.rb:5:in `<module:ExecJS>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/execjs-1.3.1/lib/execjs.rb:4:in `<top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `each' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `block in require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/bundler-1.1.3/lib/bundler.rb:119:in `require' from /home/username/sampleapp/config/application.rb:7:in `<top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/railties-3.2.3/lib/rails/commands.rb:53:in `require' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/railties-3.2.3/lib/rails/commands.rb:53:in `block in <top (required)>' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap' from /home/username/.rvm/gems/ruby-1.9.3-head@rails3/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
ガッツリどやされるが、落ち着いていこうじゃないか。
プロジェクト内のGemfileに以下の2行を追加。
gem 'execjs' gem 'therubyracer'
んで、bundle installする。
$ bundle install Fetching gem metadata from https://rubygems.org/......... Using rake (0.9.2.2) Installing i18n (0.6.0) Installing multi_json (1.3.4) Installing activesupport (3.2.3) Installing builder (3.0.0) Installing activemodel (3.2.3) Installing erubis (2.7.0) Installing journey (1.0.3) Installing rack (1.4.1) Installing rack-cache (1.2) Installing rack-test (0.6.1) Installing hike (1.2.1) Installing tilt (1.3.3) Installing sprockets (2.1.3) Installing actionpack (3.2.3) Installing mime-types (1.18) Installing polyglot (0.3.3) Installing treetop (1.4.10) Installing mail (2.4.4) Installing actionmailer (3.2.3) Installing arel (3.0.2) Installing tzinfo (0.3.33) Installing activerecord (3.2.3) Installing activeresource (3.2.3) Using bundler (1.1.3) Installing coffee-script-source (1.3.1) Installing execjs (1.3.2) Installing coffee-script (2.2.0) Installing rack-ssl (1.3.2) Installing json (1.7.1) with native extensions Installing rdoc (3.12) Installing thor (0.14.6) Installing railties (3.2.3) Installing coffee-rails (3.2.2) Installing jquery-rails (2.0.2) Installing libv8 (3.3.10.4) Installing rails (3.2.3) Installing sass (3.1.17) Installing sass-rails (3.2.5) Installing sqlite3 (1.3.6) with native extensions Installing therubyracer (0.10.1) with native extensions Installing uglifier (1.2.4) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay!
もう一度、立ち上がーれーと唱える。
$ rails s => Booting WEBrick => Rails 3.2.3 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-05-08 11:42:21] INFO WEBrick 1.3.1 [2012-05-08 11:42:21] INFO ruby 1.9.3 (2012-05-07) [i686-linux] [2012-05-08 11:42:21] INFO WEBrick::HTTPServer#start: pid=6360 port=3000
無事に立ち上がったようです。
http://localhost:3000でプロジェクトのトップページが確認できればOK。
「Could not find a JavaScript runtime」の対応については、以下のパッケージをインストールすることでも対応可。
この場合Gemfileには手を加えなくてOK。
$ sudo apt-get install nodejs