19

Here is the error I get:

sergio@sergio-VirtualBox:~/blog$ rake db:create
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

(See full trace by running task with --trace)

sergio@sergio-VirtualBox:~/blog$ 

So after some searching it seems I need to install a Javascript runtime for Ruby.

Is there a difference between the many different options? It seems Node.js is the easiest to install, will this come back to bite me or is this choice OK?

This answer, seems to be what I'm looking for but I don't know how to make use of it. Where do I find this "gemfile" and is it a per rails project file or a global ruby file? I'm very confused and can't seem to get my bearings and multiple answers contradict each other and don't solve the issue.

Add this to your Gemfile

gem 'therubyracer', require: "v8"

and run

bundle install

6 Answers 6

54

Ruby itself doesn't require a JS runtime, but a default new Rails application does.

There's a file called Gemfile in your main application directory (i.e. per Rails project) which is a list of gems required for your project that you can install using bundle install.

Adding the line gem 'therubyracer' and then bundle install will install the ruby racer JS runtime, which I've found to be the simplest if you're on a 64bit OS.

You can find more information about your Gemfile at the Bundler site.

1
6

Have you installed Node.js on your computer yet? It needs to be installed on your computer as well.

here is the link to download, http://nodejs.org/#download

1
  • 3
    Are you sure about that? Why would rake need Node.js?
    – Brady Holt
    Jul 26, 2012 at 21:48
1

There are several fairly similar options such rubytheracer, node and execjs.

rubytheracer has fallen out of favor due to its code size. Vendors such as Heroku (for rails) actively discourage it.

I currently recommend node.js

More info at Rails - Could not find a JavaScript runtime?

1
  • Fallen out of favor due to its code size? In the Rails crowd?! Surely you jest, sir. Oct 27, 2014 at 19:04
0

insert gem 'therubyracer' in Gemfile in a new line 1. run

gem install therubyracer -v '0.11.4'

  1. run

bundle install

This will work

0

I had the same error, but then I reinstalled Ruby193 with all the checkboxes (Tc/Tk, associate rb, and add to PATH).

And then deleted the GEMFile.lock

Edited the Gemfile whereever I saw gem therubyracer, I changed it to: gem therubyracer, :platform => :ruby

  • Then bundle install

  • Then rake db:drop

  • Then rake db:create

  • Then rake db:migrate

and so on

-1

Just gem install "therubyracer" and it just works.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.