Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:create - Could not find a JavaScript runtime

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

like image 464
Only Bolivian Here Avatar asked Jan 29 '12 22:01

Only Bolivian Here


2 Answers

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.

like image 156
djlumley Avatar answered Sep 28 '22 02:09

djlumley


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

like image 37
Ben Zhang Avatar answered Sep 28 '22 00:09

Ben Zhang