Ruby Rails - Could not find a JavaScript runtime

2012 April 21 at 13:22 » Tagged as :virtualization, javascript, ruby, swap,

I recently had a series of posts on learing Ruby in less than 48 hours. I managed to do so in spite of running into considerable issues with installation of Ruby or various Gems. But those issues are nothing in comparison to the stumbling blocks and pitfalls the RoR trail.  In the end what worked was to find a suitable Amazon EC2 instance with all the pre requisites installed. No wonder my first attempt from 2006, left a rather bad taste in the mouth.  Anyway, here is one of the issues that I ran into, related to a javascript runtime. Why on earth server side javascript even needs to come into the picture is a huge mystery to me.

/usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See for a list of available runtimes. (ExecJS::RuntimeUnavailable)

 I read in stackoverflow that gem install therubyracer will do the trick but I had to install g++ before it installed but that didn't make the error go away. So what next? Find a better AMI and launch another EC2 instance. After another round of installations and updates (this time I meticulously followed the instructions in the ruby on rails tutorial book I arrived back on square one, that is the same error popped up again.   Then I read several posts that suggested that the following two lines should be added to the Gemfile and then `bundle update` or `bundle install` should be run.

gem 'exec.js' gem 'therubyracer.js'

All that happens is you get a different error

Could not find gem 'therubyracer.js (>= 0) ruby' in the gems available on this machine.

  Further digging revealed that this can be fixed by installing node.js unfortunately there doesn't solve it either. Then I gave up on my current AMI and thought to start all over and to follow the instructions given here and here.  

/usr/local/rvm/rubies/ruby.9.3-p125/lib/ruby.9.1/yaml.rb:56:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. Latest version currently installed. Aborting.

  But the persistent errors just wouldn't go away, then my luck changed and I found an AMI that has all this installed. Unfortunatley I forgot to make  a note of the machine ID but I created a new AMI from it for my own use so I am safe!