Rails:找不到JavaScript运行时.看见https://github.com/sstephenson/exec

Rails: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

本文关键字:github com exec sstephenson 看见 找不到 JavaScript 运行时 Rails https      更新时间:2023-09-26

自从Dreamhost几周前升级了他们的服务器后,我的网站就坏了。我一直在努力修复我的头发,并取得了一些进展,但我被困在了希望是最后一个问题上。

我在Ruby 1.8.7上使用Rails 3.1.1,并收到来自PhusionPassenger的"Ruby(Rack(应用程序无法启动错误"。它声明"找不到JavaScript运行时"。看见https://github.com/sstephenson/execjs以获取可用运行时的列表。(ExecJS::RuntimeUnavailable('。在Dreamhost的wiki上搜索这个建议,可以找到一个安装"therubyracer"gem的解决方案。

所以我用建议的宝石更新了我的宝石文件,比如:

宝石"therubyracer",'~>0.9.9'

编辑:我也试着用添加到文件中

gem"therubyracer",:平台=>:ruby

但这并没有什么不同。

然后捆绑安装在我的Macbook上(运行OS X 10.5.8(,没有任何问题。然而,当我在Dreamhost上运行"cap-deploy"时,这会失败;当它试图安装ubyracer所依赖的libv8时,我看到了一个错误。

有人知道如何正确安装或其他有效的解决方案吗?

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

来自终端的完整错误反馈:

  • 执行"cd/home/futureprof/abunchofletters.co.uk/releases/20111118003703&捆绑安装--gemfile/home/futureproof/abunchoflets.co.uk/releases/20111118003703/Gemfile--path/home/futureprof/.gems/bundle--部署--安静--无开发测试"服务器:["abuncholets.co.uk"][abunchoflets.co.uk]执行命令**[out::abuncholets.co.uk]不幸的是,发生了致命错误。请将此错误报告给Bundler问题跟踪器,网址为https://github.com/carlhuda/bundler/issues这样我们就可以修复它。谢谢!**[输出::abunchofletters.co.uk]/usr/lib/ruby/1.8/rubygems/installer.rb:483:in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] /usr/bin/ruby1.8 extconf.rb ** [out :: abunchofletters.co.uk] *** extconf.rb failed *** ** [out :: abunchofletters.co.uk] Could not create Makefile due to some reason, probably lack of ** [out :: abunchofletters.co.uk] necessary libraries and/or headers. Check the mkmf.log file for more ** [out :: abunchofletters.co.uk] details. You may need configuration options. ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] Provided configuration options: ** [out :: abunchofletters.co.uk] --with-opt-dir ** [out :: abunchofletters.co.uk] --without-opt-dir ** [out :: 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] --without-opt-lib=${opt-dir}/lib ** [out :: abunchofletters.co.uk] --with-make-prog ** [out :: abunchofletters.co.uk] --without-make-prog ** [out :: abunchofletters.co.uk] --srcdir=. ** [out :: abunchofletters.co.uk] --curdir ** [out :: abunchofletters.co.uk] --ruby=/usr/bin/ruby1.8 ** [out :: abunchofletters.co.uk] extconf.rb:13: uninitialized constant Gem (NameError) ** [out :: abunchofletters.co.uk] Checking for Python... ** [out :: abunchofletters.co.uk] ** [out :: abunchofletters.co.uk] Gem files will remain installed in /home/futureproof/.gems/bundle/ruby/1.8/gems/libv8-3.3.10.4 for inspection. ** [out :: abunchofletters.co.uk] Results logged to /home/futureproof/.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:在build_extensions' ** [out :: abunchofletters.co.uk] from /usr/lib/ruby/1.8/rubygems/installer.rb:198:in中安装'**[out::abunchofletters.co.uk]/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/source.rb:90:ininstall' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/rubygems_integration.rb:78:in preserve_paths'**[out::abuncholets.co.uk]来自/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/source.rb:89:ininstall' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:73:in install_gem_from_spec'**[out::abuncholets.co.uk]来自/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/rubygems_integration.rb:93:inwith_build_args' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:72:in install_gem_from_spec'**[out::abuncholets.co.uk]来自/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:56:inrun' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:55:in 从运行'**[out::abunchofletters.co.uk]/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/installer.rb:12:ininstall' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/cli.rb:219:in 从安装'**[out::abuncholets.co.uk]/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/vender/thor/task.rb:22:insend' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor/task.rb:22:in 从运行'**[out::abuncholets.co.uk]/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/vender/thor/invocation.rb:118:ininvoke_task' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/lib/bundler/vendor/thor.rb:263:in 从/home/futureprof/.gems/gems/bundler-1.1.rc/lib/bundler/vender/thor/base.rb:386:instart' ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/gems/bundler-1.1.rc/bin/bundle:13 ** [out :: abunchofletters.co.uk] from /home/futureproof/.gems/bin/bundle:19:in 从加载'**[out::abuncholets.co.uk]/home/futureprof/.gems/bin/bundle:19命令在13170ms内完成***[deploy:update_code]回滚*执行"rm-rf/home/futureproof/abunchofletters.co.uk/releases/20111118003703;true"服务器:["abuncholets.co.uk"][abunchoflets.co.uk]执行命令在563ms内完成的命令失败:"sh-c'cd/homefutureproof/abunchofletters.co.uk/releases/20111118003703&捆绑安装--gemfile/home/futureproof/abunchoflets.co.uk/releases/20111118003703/Gemfile--path/home/futureproof/.gems/bundle--部署--安静--不进行开发测试">

如果你在Ubuntu上,请安装nodejs

sudo apt-get install nodejs

libv8是一个操作系统库;您需要安装正确的Linux系统库。如果你运行的是Ubuntu,那就是

sudo apt-get install libv8-dev

或者,您可以安装node.js,它可以作为Debian/Uubuntu包用于各种发行版,例如。http://ppa.launchpad.net/chris-lea/node.js/ubuntu

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

我在Dreamhost上使用这些宝石,并将Rails 3.1用于资产管道

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个Rails3.1应用程序。

您只需要获得libv8,对于带有Brew的操作系统,只需执行:

brew install v8

我在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

Finnaly将其路径添加到deploy.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"

你已经完成了

我刚刚看到了一个关于这方面的演示。

到目前为止,我一直在用卢布赛。显然不是很好。它是巨大的。

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

推荐的另外两个是execjs和node.js(目前非常热门(。

确保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。

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

只需转到您的终端并键入:

sudo apt-get-install-node.js

输入您的密码。。。每当它要求确认时,请按"Y"。我希望这能有所帮助!!!

我刚刚在Win7开发机器上遇到了同样的问题。看起来像是在安装https://github.com/hiranpeiris/therubyracer_for_windows并且将CCD_ 17添加到CCD_。

之前:

$ 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,并尝试使用捆绑包安装

gem"therubyracer","~>0.10.2">

此错误是由于缺少Javascript运行时环境造成的。像Nodejs。您可能没有选择它,或者它没有安装。

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

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

如果没有安装使用

sudo apt-get install nodejs