14

I am following the ruby on rails getting started guide on a new install of Ubuntu 12.10. I'm up to running rake db:create but I get the following error:

rake aborted! Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

I've searched around and the suggested solutions (see list below) are to install some either therubyracer or nodejs but they don't explain why.

Before I go installing stuff I want to know what the differences are between these JavaScript runtimes and why I would choose one over the other?

Update:

I just read https://github.com/sstephenson/execjs (I know I should have read this first, sorry) and it seems to me that execjs is not a JavaScript runtime and I already have it... so it's down to therubyracer and nodejs ... please excuse my ignorance, I've amended my question

In addition to Intrepidd's answer:

The ruby on rails getting started guide supports Intrepidd's answer. See section 4.1 "Starting up the Web Server" where it says:

Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it.

For the rails noobs out there (like me) the GemFile is in the root folder of your rails application. After uncommenting that line in my GemFile I had to run bundle install to install therubyracer gem.

Community
  • 1
  • 1
Dean
  • 4,554
  • 7
  • 34
  • 45

2 Answers2

12

You should prefer NodeJS over therubyracer because NodeJS is memory efficient, but it might not be as easy to install, although on Mac OS it's easy so it is on Ubuntu.

Kenny Meyer
  • 7,849
  • 6
  • 45
  • 66
rubyonrails3
  • 259
  • 2
  • 6
  • can you offer any instructions, or a link to an article on how to install it? – Dean May 28 '14 at 22:18
  • 2
    On Mac you can install with homebrew with a simple command. `brew install node` that's it then you can verify this by running command `node` in terminal to verify then you would not need 'gem "therubyracer"' line anymore and while deploying if you on ubtuntu you can install with `sudo apt-get install nodejs` I'm using node on heroku and rackspace. on heroku you would not need to install node cuz its pre-installed for rails. – rubyonrails3 May 30 '14 at 09:53
  • @Dean head do https://gorails.com/setup/ubuntu/14.10 for information about how to install nodejs – mswiszcz Jan 24 '15 at 14:59
4

On a *NIX system, you can just uncomment the gem "therubyracer" in the gemfile and you're good to go, this is the easiest.

Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • gem "therubyracer" isn't in the GemFile... I guess I should just add it? (sorry about my last comment, I misread your answer)... sigh, nevermind found it like this: #gem 'therubyracer', :platforms => :ruby – Dean Feb 12 '13 at 09:57
  • ok so that worked, cheers! So therubyracer is easier, can you give me any other reasons for why therubyracer is better for rails development than nodejs or is there no clear cut answer? Don't get me wrong, "easiest" is a very good reason. – Dean Feb 12 '13 at 10:07
  • I never uses node as a js runtime but I guess that this is just a performance and implementation issue. And I'm not sure but if you want to use node.js you have to install it manually besides installing the gem I think, not sure though. – Intrepidd Feb 12 '13 at 10:17
  • 4
    They say `therubyracer` and `therubyracer-heroku` are ***strongly discouraged as these gems use a very large amount of memory***, https://devcenter.heroku.com/articles/rails-asset-pipeline#therubyracer – Green Jul 18 '13 at 11:18
  • I'm down-voting your answer because Node.js is fairly trivial to install on most platforms and offers much better performance than therubyracer. The fact using therubyracer is marginally easier than installing Node.js is not a good reason to use it. – Mario Aug 25 '16 at 17:57
  • I found some benchmark here stating that therubyracer would be more efficient... but it doesn't seem up to date ? https://gist.github.com/yuku-t/4758afde9d4b5be2064c – Cyril Duchon-Doris Apr 10 '17 at 08:48
  • Combination of `therubyracer` and `libv8` in recent ruby and rails versions (eg. Ruby 3 + Rails 6) causes a lot of trouble and waste of time when you want to simply install the gems. So, it will definitely force you think of choosing a different approach, ie. NodeJs. – yaka Jun 03 '22 at 14:41