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

社会主义新天地 提交于 2019-12-02 14:27:12

libv8 is an OS library; you'll need to install the correct Linux system library. If you're running Ubuntu, it's

sudo apt-get install libv8-dev

Alternatively, you can install node.js which is available as a Debian/Ubuntu package for various distros, e.g. http://ppa.launchpad.net/chris-lea/node.js/ubuntu

You may save yourself a lot of trouble by deploying on Heroku instead where you don't have to manage the OS or components for gems.

If you're on Ubuntu, install nodejs

sudo apt-get install nodejs

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 as precompiler, and johnson as runtime.

This work for me in 2 Rails 3.1 apps hosted by Dreamhost.

I'm in dreamhost shared server.

I installed nodejs without using root/sudo. On the server:

#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 add its path to the deploy.rb, adding the following line (some more paths are added in this case):

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"

You are done

I just a saw a presentation on this.

I've used rubytheracer up till now. Apparently it ain't so great. And it's huge.

But you can use any javascript runtime.

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

Make sure to gem install the selected gem and then bundle install or bundle update for your app.

One other note is that you should switch to 1.9.2 also.
Install RVM (bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)) and you can have both 1.8.7 and 1.9.2 side-by-side.

I've just hit the very same problem on my Win7 dev machine. It looks like installing https://github.com/hiranpeiris/therubyracer_for_windows and adding gem 'therubyracer' to the Gemfile sorts things out.

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>'
(...)

This basically means that Rails needs rubyracer and libv8.

After:

$ 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]
(...)

I would suggest installing Nodejs. It worked for me.

Just go to your terminal and type in :

sudo apt-get install node.js

Enter your password...And press 'Y' whenever it asks for a confirmation. I hope this helps !!!

Add following gem in Gemfile and try with the bundle install

gem "therubyracer", "~> 0.10.2"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!