11

I've been trying to use Rails and when I use rake, I get this error. Any suggestions on which run time should I use?

ngzhongqin@ngzhongqin-linux:~/RailsProjects/webuiltit$ rake db:create:all --trace
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.4/lib/execjs/runtimes.rb:45:in `autodetect'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.4/lib/execjs.rb:5:in `<module:ExecJS>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.4/lib/execjs.rb:4:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.1.0/lib/coffee-rails.rb:1:in `require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.1.0/lib/coffee-rails.rb:1:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `block in require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
/home/ngzhongqin/RailsProjects/webuiltit/config/application.rb:13:in `<top (required)>'
/home/ngzhongqin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/ngzhongqin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/ngzhongqin/RailsProjects/webuiltit/Rakefile:5:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/home/ngzhongqin/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
htanata
  • 36,666
  • 8
  • 50
  • 57
Ng Zhong Qin
  • 1,211
  • 2
  • 15
  • 28
  • Are you still doing 'rake db:create:all' ? have you tried 'rake db:create ' ? Also, do you get the same error trying to run the server (script/rails server for rails3, script/server for rails2)? – Michael Durrant Sep 12 '11 at 01:55

3 Answers3

31

Add this to your Gemfile

gem 'therubyracer', require: "v8"

and run

bundle install

NARKOZ
  • 27,203
  • 7
  • 68
  • 90
  • 2
    I do this after install the `therubyracer` gem, and, finally, it works. Thanks very much. – caarlos0 Jan 03 '12 at 23:32
  • 2
    I had to uncomment this line from my GemFile – Andrew Kozlik Apr 24 '12 at 18:11
  • It's worth noting, apparently installing `therubyracer` gem alone *does not do the trick*... One would think `execjs` would "automatically pick the best runtime available" ([as it claims to](https://github.com/sstephenson/execjs)), but for some reason *you must* add the relevant line to your `Gemfile`. (Perhaps this is a 'feature' of Bundler, whereby it's hiding gems not in `Gemfile`?) – Chris W. Feb 11 '15 at 01:06
12

I have installed the gem therubyracer, execjs, mustang but nothing worked.

On my linux (ubuntu) the command

sudo apt-get install nodejs

did the job finally for me.

May be this post could also be helpful: https://github.com/intridea/rails_wizard/issues/31

tivo
  • 337
  • 1
  • 6
  • Yes! This was the one. Ubuntu Rails321 ruby192 – Andreas Lyngstad Mar 05 '12 at 21:44
  • Note, to get `execjs` to "detect" the installed gem for `therubyracer`, you *must* add the following line to your `Gemfile`: `gem 'therubyracer', require: "v8"`. Apparently Bundler hides access to gems that are not specified there (in the `Gemfile`). Installing `nodejs` via `apt-get` will of course work as well (but that package isn't available on all Linux systems, like the current stable version of Debian). – Chris W. Feb 11 '15 at 01:08
0

You need to install runtime for these.. some of the good options are

therubyracer - Google V8 embedded within Ruby

therubyrhino - Mozilla Rhino embedded within JRuby

Johnson - Mozilla SpiderMonkey embedded within Ruby

Mustang - Mustang V8 embedded within Ruby

Node.js

Apple JavaScriptCore - Included with Mac OS X

Mozilla SpiderMonkey

Microsoft Windows Script Host (JScript)

you can find more details at https://github.com/sstephenson/execjs

arunagw
  • 1,193
  • 6
  • 8
  • 14
    -1, No command or direct solution provided whatsoever, just general info which is only confusing me as a rails beginner. – Tarrasch Jan 07 '12 at 12:16
  • @tarrasch why should the poster provide a command for you to blindly paste into your shell? The series of steps depends on the distribution installed and which package you want to install to meet the requirement. – Adam Hawes Jan 28 '12 at 02:19
  • @AdamHawes, I agree with you, but I think *this* answer not only have no "line to blindly paste", it just doesn't provide any explanation in text to compensate for that, it's just a listing of stuff I've never heard of before. – Tarrasch Jan 28 '12 at 14:14
  • @Tarrasch so Google for some of those things! Each of them solves the problem. The execjs page tells you what they're for already. All you need to do is install one, and that's different depending on what OS/distro you use! – Adam Hawes Feb 03 '12 at 04:38