Rails: 无法找到 JavaScript 运行时,请参见 https://github.com/sstephenson/ExecJS 中可用运行时的列表

自从几周前 Dreamhost 升级了他们的服务器我的网站就瘫痪了。我一直在揪头发,试图把它修好,并取得了一些进展,但困在什么是希望最后的问题。

我在 Ruby1.8.7上使用 Rails 3.1.1,得到了一个“ Ruby (Rack)应用程序无法启动错误”的结果。它声明“无法找到 JavaScript 运行时”。有关可用运行时的列表,请参见 https://github.com/sstephenson/execjs。(ExecJS: : RuntimeUnable)’。在 Dreamhost 的 wiki 上搜索这个问题,提供了一个安装“ therubyracer”gem 的解决方案。

所以我用推荐的 gem 更新了我的 gem 文件,如下所示:

Gem‘ therubyracer’,’~ > 0.9.9’

编辑: 我还尝试用以下方法添加文件:

Gem‘ therubyracer’,: Platform = > : Ruby

但是没什么区别。

然后捆绑安装在我的 Macbook (运行 OS X 10.5.8)顺利。但是,当我运行“ cap dept”将其放到 Dreamhost 上时,这种方法失败了; 当它尝试安装 thubyracer 所依赖的 libv8时,我看到了一个错误。

有人知道如何正确安装它或其他工作解决方案吗?

任何其他信息可以根据要求提供。

Full error feedback from Terminal:

  • 执行「 cd/home/future-proof/ abunchofletters.co.uk/releases/20111118003703 & & 捆绑安装—— gemfile /家/未来/ abunchofletters.co.uk/releases/20111118003703/gemfile --path /home/futureproof/.gems/bundle --deployment --quiet --without development test" 服务器: [“ abunchofletters.co.uk”] [ abunchofletters.co.uk ]执行命令 * * [ out: : abunchofletters.co.uk ]不幸的是,发生了一个致命错误。 请将此错误报告给 Bundler 问题跟踪器 https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks! ** [out :: abunchofletters.co.uk] /usr/lib/ruby/1.8/rubygems/installer.rb: 483: 错误: 未能构建 gem 本机扩展。 (Gem: : Installer: : ExtensionBuildError) * * [ out: : Abunchofletters.co.uk abunchofletters.co.uk /usr/bin/ruby1.8 extconf.rb ** [out :: abunchofletters.co.uk] *** Extcon.rb 失败 * * * * [ out: : abunchofletters.co.uk ]无法执行 由于某种原因,可能缺少 * * [ out: : Abunchofletters.co.uk 所需的库及/或标题 Mkmf.log 文件了解更多 * * [ out: : abunchofletters.co.uk ]详细信息。 您可能需要配置选项。 * * [ out: : abunchofletters.co.uk ] * * [ out: : abunchofletters.co.uk ]提供配置选项: * * [ out: : abunchofletters.co.uk ]—— with-opt-dir * * [ out: : Abunchofletters.co.uk : Abunchofletters.co.uk ]—— with-opt-include * * [ out: Abunchofletters.co.uk ]-without-opt-include = ${ opt-dir }/include * * [ out: : abunchofletters.co.uk ]—— with-opt-lib * * [ out: : 返回 abunchofletters.co.uk 页面没有-opt-lib = ${ opt-dir }/lib * * [出局: 返回文章页面 abunchofletters.co.uk : 返回文章页面 abunchofletters.co.uk : * * [ out: : abunchofletters.co.uk abunchofletters.co.uk ] —— curdir * * [ out: : abunchofletters.co.uk ]—— ruby =/usr/bin/ruby1.8 * * [ out: : abunchofletters.co.uk ] extcon.rb: 13: 未初始化常量 Gem (NameError) * * [ out: : abunchofletters.co.uk ]检查 for Python... ** [out :: abunchofletters.co.uk] ** [out :: [ abunchofletters.co.uk ] Gem 文件将继续安装在 /home/futureproof/.gems/bundle/ruby/1.8/gems/libv8-3.3.10.4 for 检查 * * [输出: : abunchofletters.co.uk ]结果记录在 /home/future//. gems/bundle/ruby/1.8/gems/libv8-3.3.10.4/ext/libv8/gem _ make. out * * [ out: : abunchofletters.co.uk ] from/usr/lib/ruby/1.8/rubygems/installer.rb: 446: in each’* * [ out: : Abunchofletters.co.uk /usr/lib/ruby/1.8/rubygems/installer.rb: 446: in < code > build _ tended’* * Abunchofletters.co.uk /usr/lib/ruby/1.8/rubygems/installer.rb: 198: in install’* * [ out: : Abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/source. rb: 90: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/source. rb: 90: in Install’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/rubygems _ Integration. rb: 78: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/rubygems _ Integration. rb: 78: in 保存 _ path’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/source. rb: 89: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/source. rb: 89: in Install’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 73: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 73: in Install _ gem _ from _ spec’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/rubygems _ Integration. rb: 93: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/rubygems _ Integration. rb: 93: in 用 _ build _ args’* * [ out: : abunchofletters.co.uk ]从 /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 72: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 72: in Install _ gem _ from _ spec’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 56: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 56: in 逃离 abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 55: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 55: in 逃离 abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 12: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/installer.rb: 12: in Install’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/cli.rb: 219: in/home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/cli.rb: 219: in Install’* * [ out: : abunchofletters.co.uk ] /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/owner/thor/task.rb: 22: in 发送 abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/owner/thor/task.rb: 22: in 逃离 abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/owner/thor/invocation.rb: 118: in invoke_task' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor.rb:263:in 调度 abunchofletters.co.uk /home/future-proof/. gems/gems/bundler-1.1. rc/lib/bundler/owner/thor/base.rb: 386: in 从 abunchofletters.co.uk 开始 /home/futureproof/.gems/gems/bundler-1.1.rc/bin/bundle:13 ** [out :: Abunchofletters.co.uk /home/future/. gems/bin/bundle: 19: in load' ** [out :: abunchofletters.co.uk] from /home/future proof/. gems/bin/bundle: 19 command finished in 13170ms 执行“ rm-rf/home/future/proof/ abunchofletters.co.uk/releases/20111118003703; true;” 服务器: [“ abunchofletters.co.uk”] [ abunchofletters.co.uk ]执行命令 command finished in 563ms failed: "sh -c 'cd /home/futureproof/abunchofletters.co.uk/releases/20111118003703 && bundle install --gemfile /home/futureproof/abunchofletters.co.uk/releases/20111118003703/Gemfile --path /home/futureproof/.gems/bundle --deployment --quiet --without development test'" on abunchofletters.co.uk
87356 次浏览

我刚看了一个关于这个的报告。

我以前用过红宝石赛车,显然不怎么样,而且很大。

但是您可以使用任何 javascript 运行时。

The other two recommended are execjs and node.js (which is very hot right now).

确保选中的 gem 为 gem install,然后为应用程序选择 bundle installbundle update

另一个注意事项是您也应该切换到1.9.2。
安装 RVM(bash < < (curl-shttps://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)) 你可以同时拥有1.8.7和1.9.2。

i use this gems on Dreamhost with Rails 3.1 for the Asset Pipeline

group :assets do
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'johnson'
gem 'sass-rails', "  ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end

Therubyracer 作为预编译器,Johnson 作为运行时。

在 Dreamhost 托管的2 Rails 3.1应用程序中,这对我来说很有用。

libv8是一个操作系统库; 您需要安装正确的 Linux 系统库

sudo apt-get install libv8-dev

另外,你也可以安装 node.js,它可以作为 Debian/Ubuntu 软件包用于不同的发行版,例如 http://ppa.launchpad.net/chris-lea/node.js/ubuntu

您可以在 Heroku 上部署,而不必管理 gems 的操作系统或组件,这样可以省去很多麻烦。

如果你使用 Ubuntu,安装 nodejs

sudo apt-get install nodejs

我建议安装 Nodejs,它对我很有效。

打开你的终端,输入:

Sudo apt-get install node.js

输入您的密码... 并按“ Y”每当它要求确认。我希望这有所帮助! ! !

我在 Dreamhost 共享服务器上。

我在没有使用 root/sudo 的情况下安装了 nodejs:

#download node js (check last version from web)
$ wget http://nodejs.org/dist/v0.8.16/node-v0.8.16-linux-x86.tar.gz
#untar
$ tar xzf node-v0.8.16-linux-x86.tar.gz

最后,将其路径添加到 loy.rb,并添加以下代码行(在本例中添加了一些其他路径) :

default_environment["PATH"] = ":/home/myUser/soft/node-v0.8.16-linux-x86/bin:/home/myUser/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:$PATH"

你完蛋了

我刚刚在我的 Win7开发机器上遇到了同样的问题。这看起来像是安装 https://github.com/hiranpeiris/therubyracer_for_windows并将 gem 'therubyracer'添加到 Gemfile中来解决问题。

Before:

$ rails generate
c:/Ruby193/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 c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
(...)

这基本上意味着 Rails 需要 rubyracerlibv8

之后:

$ rails generate
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.


Called from: c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.


Usage: rails generate GENERATOR [args] [options]
(...)

在 Gemfile 添加以下 gem 并尝试使用 bundle 安装

Gem“ therubyracer”,“ ~ > 0.10.2”

你只需要得到 libv8,对于具有 Brew 的操作系统,只需要做:

brew install v8

This error is due to absence of Javascript runtime environment. Like Nodejs. Either you haven't selected it or it is not installed.

看看是否已经有 nodejs 在使用,

nvm list
nvm use <version> //to use it (i.e nvm use 14)

if it is not installed use,

sudo apt-get install nodejs