UbuntuでRails3のexecjsが例外を投げたら

どんなエラー?

こんな具合に例外を投げます。

$ ./script/rails server
/usr/lib/ruby/gems/1.8/gems/execjs-1.2.7/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
	from /usr/lib/ruby/gems/1.8/gems/execjs-1.2.7/lib/execjs.rb:5
	from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
	from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1
	from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
	from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1
	from /usr/lib/ruby/gems/1.8/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require'
	from /usr/lib/ruby/gems/1.8/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `require'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
	from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
	from /home/shingo/Aptana RadRails Workspace/twitter_bot/config/application.rb:7
	from /usr/lib/ruby/gems/1.8/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'
	from /usr/lib/ruby/gems/1.8/gems/railties-3.1.0/lib/rails/commands.rb:52
	from /usr/lib/ruby/gems/1.8/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
	from /usr/lib/ruby/gems/1.8/gems/railties-3.1.0/lib/rails/commands.rb:49
	from ./script/rails:6:in `require'
	from ./script/rails:6
$

どう対処するの?

エラーメッセージにある https://github.com/sstephenson/execjs を見れば、8つある"ExecJS supports these runtimes"のどれかを入れれば良いらしい。最初、therubyracerを入れたがダメだった。

それで、Node.jsを入れてあげる。

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs

これで平和に動きます。

$ ./script/rails server
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-09-20 11:51:40] INFO  WEBrick 1.3.1
[2011-09-20 11:51:40] INFO  ruby 1.8.7 (2010-08-16) [i686-linux]
[2011-09-20 11:51:45] INFO  WEBrick::HTTPServer#start: pid=9112 port=3000