新手问题 [已解决]Ubuntu 14.04 上使用 Nginx Passenger 部署 Ruby on Rails -“Could not find a JavaScript runtime” 错误

joezhang · 2014年10月30日 · 最后由 joezhang 回复于 2015年04月29日 · 4591 次阅读

使用 vagrant 按照 Wiki 教程在 Ubuntu 14.04 上使用 Nginx Passenger 部署 Ruby on Rails,出现“Could not find a JavaScript runtime”错误,但是我已经安装了 Nodejs 了,请大家指点一下,搞了一天,这个坑实在是迈不过去了。

vagrant@vagrant-ubuntu-trusty-64:~$ sudo add-apt-repository ppa:chris-lea/node.js
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get update
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install nodejs
vagrant@vagrant-ubuntu-trusty-64:~$ nodejs --version
v0.10.33

/var/log/nginx/error.log

[ 2014-10-30 11:02:35.0093 1091/7f942a2f4700 Pool2/Implementation.cpp:287 ]: Could not spawn process for application /vagrant/housing: An error occured while starting up the preloader.
  Error ID: 75e8ef8e
  Error details saved to: /tmp/passenger-error-ATMG0r.html
  Message from application: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in `autodetect'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs.rb:5:in `<module:ExecJS>'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs.rb:4:in `<top (required)>'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `<top (required)>'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'
  /vagrant/housing/config/application.rb:12:in `<top (required)>'
  /vagrant/housing/config/environment.rb:2:in `require'
  /vagrant/housing/config/environment.rb:2:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

[ 2014-10-30 11:02:35.0122 1091/7f941b7fe700 agents/HelperAgent/RequestHandler.h:2306 ]: [Client 20] Cannot checkout session because a spawning error occurred. The identifier of the error is 75e8ef8e. Please see earlier logs for details about the error.

一个多月前 在 VPS 上根据 WiKi 搭过,比较顺利,除了 修改了 Passenger 的 apt 源。是 Rails 起不来,还是启动 Nginx 报错?

在 nginx.conf 顶头加 env PATH;

@springwq 谢谢,启动 Nginx 正常。在浏览器中输入 IP 地址的时候出错: We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly. 查看/var/log/nginx/error.log 发现以上的错误。

vagrant@vagrant-ubuntu-trusty-64:~$ sudo service nginx restart
 * Restarting nginx nginx                                                                                           [ OK ]

@Rei 太感谢了!!!在 nginx.conf 顶头加 env PATH;一切都正常了,昨天搞了一整天!发现没有一篇讲部署的文章是 100% 可用的,每一个都是缺一些东西,搞得新手们好苦闷!

小白问一句。env path 怎么设置?

@alleywind 很简单,运行 sudo vi /etc/nginx/nginx.conf编辑配置文件,在第一行加上:env PATH; 应该就可以了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号