- A+
关于rails启动Web服务出现Could not find a JavaScript runtime的解决方案
之前在其它服务器上安装rails一切正常,今天在新服务器上安装后,执行bin/rails server出现如下报错:
[root@_fly_birth_192.168.2.210:~/rails/tickets]# bin/rails server
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:85:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
Backtrace for gem load error is:
/usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
/usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:5:in `require'
/usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:5:in `<top (required)>'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:82:in `require'
/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
主要提示execJs ‘Could not find a JavaScript runtime’,缺少JavaScript runtime,所以需要安装一个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)
解决方案