启动Rails服务器时ExecJS :: RuntimeUnavailable错误

时间:2013-03-20 04:12:03

标签: ruby-on-rails execjs

我创建了一个新的Rails应用程序。当我尝试启动服务器时,出现以下错误:

[bathakarai@Project1-CO samp]$ rails server
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/script_rails_loader.rb:11: warning: Insecure world writable dir /usr in PATH, mode 040777
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /usr in PATH, mode 040777
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/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/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
    from /home/bathakarai/gold/Ruby/Practice/Rails/samp/config/application.rb:7:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

如何解决此错误?

3 个答案:

答案 0 :(得分:9)

如果您刚刚生成了一个新应用程序,则可以在注释gem therubyracer时出现。需要编译您的资产。您可以取消注释或安装nodejs之类的内容,这样您就不需要在所有项目中使用gem。

brew install nodejs
# or
sudo apt-get install nodejs

答案 1 :(得分:3)

尝试

sudo gem install therubyracer

gem install therubyracer

希望这有帮助

答案 2 :(得分:1)

最流行的JavaScript运行时是therubyracer,它是一个宝石。作为 @muttonlamb said,安装它运行:

gem install therubyracer

然后,作为 Bathakarai mentioned,将下一行添加到文件底部的Gemfile中:

gem 'therubyracer'

现在再次运行rails server,一切正常。

为了简化流程,您可以运行a script来生成应用程序并自动添加JS运行时。