关于rails的 Could not find a JavaScript runtime.错误

下载 《Agile Web Development with Rails》的源代码

在迁移数据库时 遇到了 如下错误:


Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/www/.gem/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect'
/home/www/.gem/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `'
/home/www/.gem/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:4:in `'
/home/www/.gem/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
/home/www/.gem/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `'
/home/www/.gem/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
/home/www/.gem/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `'
/home/www/.gem/ruby/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
/home/www/.gem/ruby/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `'
/home/www/rails32/depot_rr/config/application.rb:15:in `'
/home/www/rails32/depot_rr/Rakefile:5:in `'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `raw_load_rakefile'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `block in load_rakefile'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `block in run'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'

execJS 可以在ruby里运行JavaScript代码,他自动选择最好的js runtime 程序,linux需要安装一个Javascript引擎才运行。

execJS 支持如下的runtime:

  • therubyracer - Google V8embedded within Ruby
  • therubyrhino - MozillaRhino embedded within JRuby
  • Johnson - MozillaSpiderMonkey embedded within Ruby
  • Mustang - Mustang V8embedded within Ruby
  • Node.js
  • Apple JavaScriptCore - Included with Mac OS X
  • Mozilla SpiderMonkey
  • Microsoft Windows Script Host (JScript)


也就是说linux系统里需要安装一个JavaScript引擎 这里我们安装therubyracer

在Gemfile中添加

gem 'execjs'

gem 'therubyracer'


执行


bundle install

问题解决

我试着直接用gem install therubyracer 但还是会出现那个错误,只有在Gemfile中添加之后,执行bundle install 命令,才不会出错。


或者 直接在root用户下运行

yum install nodejs 也可以解决问题





你可能感兴趣的:(Rails学习)