このあいだ Windows7 64bit で Rails が動いてくれない話を書いた。Ubuntu ではうまくいくかと思ったら話はそう簡単じゃなかった。
このあいだと同じように、書籍を管理するアプリを作ることにする。
takatoh@nightschool:~/w/$ rails new Librarian
本来ならこれだけで Rails サーバを起動できるようになるはず。ところが、
takatoh@nightschool:~/w/$ cd Librarian takatoh@nightschool:~/w/Librarian$ rails server /home/takatoh/.rvm/gems/ruby-2.1.1/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/execjs-2.2.1/lib/execjs.rb:5:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/execjs-2.2.1/lib/execjs.rb:4:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/uglifier-2.5.1/lib/uglifier.rb:3:in require' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/uglifier-2.5.1/lib/uglifier.rb:3:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in require' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in block (2 levels) in require' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in each' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in block in require' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in each' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in require' from /home/takatoh/.rvm/gems/ruby-2.1.1@global/gems/bundler-1.6.3/lib/bundler.rb:132:in require' from /home/takatoh/w/Librarian/config/application.rb:7:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in require' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in vblock in server' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in tap' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in server' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in run_command!' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/railties-4.1.4/lib/rails/commands.rb:17:in ' from /home/takatoh/w/Librarian/bin/rails:8:in require' from /home/takatoh/w/Librarian/bin/rails:8:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in load' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in call' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/client/command.rb:7:in call' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/client.rb:26:in run' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/bin/spring:48:in ' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/binstub.rb:11:in load' from /home/takatoh/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/binstub.rb:11:in ' from /home/takatoh/w/Librarian/bin/spring:16:in require' from /home/takatoh/w/Librarian/bin/spring:16:in ' from bin/rails:3:in load' from bin/rails:3:in main'
こんな具合にエラーになってしまう。
エラートレースの最初の方に「Could not find a JavaScript runtime.」と書いてある。これが原因らしいので、ググってみるとそのものズバリのページが見つかった。
cf. rails server 時に `autodetect’: Could not find a JavaScript runtime が出たら。
これによると、therubyracer という gem をインストールするための記述が Gemfile でコメントアウトされているのを、修正してインストールしてやればいいらしい。
gem 'therubyracer', platforms: :ruby
これで bundle install
。
takatoh@nightschool:~/w/Librarian$ bundle install (略)
さあ、うまくいくかな?
takatoh@nightschool:~/w/Librarian$ rails server => Booting WEBrick => Rails 4.1.4 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server [2014-07-06 06:31:57] INFO WEBrick 1.3.1 [2014-07-06 06:31:57] INFO ruby 2.1.1 (2014-02-24) [x86_64-linux] [2014-07-06 06:31:57] INFO WEBrick::HTTPServer#start: pid=21228 port=3000
うまくいった!