LoginSignup
25
25

More than 5 years have passed since last update.

UbuntuでRailsを実行すると「Could not find a JavaScript runtime.」エラーが発生する

Last updated at Posted at 2012-12-26

環境

OS Rails Version
Ubuntu 12.04 3.2.9

事象

$ bundle exec rails server
/home/kyamada/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/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/kyamada/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
    from /home/kyamada/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
    from /home/kyamada/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/kyamada/.rbenv/versions/1.9.3-p194/
・・・

解決策

NodeJsをインストール

$ sudo apt-get install nodejs

Gemfileに以下を追加

Gemfile
gem 'libv8'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby

bundle installして、再実行

$ bundle install
$ bundle exec rails server
=> Booting WEBrick
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
25
25
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
25
25