15

I created a new rails app in folder 'issues' and when I wanted to 'ruby s' I got an error. Any help will be much appreciated

[thiago@netbox issues]$ rails s
/home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /home/thiago/Documents/wdi/rails_practice/issues/config/application.rb:7:in `<top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I added 'therubyracer' gem into my Gemfile and then '$ bundle install' Works!

Gemfile
source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'sqlite3'

group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'therubyracer' # added
1
  • 2
    Can you post the contents of your Gemfile? May 30, 2013 at 21:24

6 Answers 6

19

I had the same error both for Windows and Ubuntu when I started working on Rails in January. The error is pretty straightforward. You need a JavaScript runtime environment for the server to start.

There are a number of solutions to this. The one I use on Ubuntu is to install NodeJS.

On Ubuntu you'd run something like the following to install NodeJS:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs

Those are the commands I use to do it as it will install the latest stable version of NodeJS, but you can just run sudo apt-get -y install nodejs and be fine.

On Windows, the answer I used, and there may be others, was to edit your Gemfile to install therubyracer. I work on Rails 4.0 RC1 apps right now and they all have gem 'therubyracer', platform: :ruby already in the Gemfile just commented out.

You can just go add gem 'therubyracer' in your Gemfile if you're running on Windows and that will get you running I'd bet. Then run bundle install.

0
8

A JavaScript runtime cannot be find. I would suppose that you don't have one in your Gemfile. Try editing your Gemfile and add

gem 'therubyracer'

And then run

$ bundle install
1

You need to install a javascript Interpreter:

Add this to your Gemfile:

gem "libv8", ">= 3.11.8"
gem "therubyracer", ">= 0.11.0", :group => :assets, :platform => :ruby, :require => "v8"

Also you can check other options like Node.js for production, but for development it will be enough.

0

You should open /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/runtimes.rb and go to line 51. See what resource autodetect is looking for. This seems to be missing.

You probably have a dependency that didn't load. Best strategy is to create a fresh ruby gem environment with rbenv or rvm, then bundle again. Should fix it.

0
  • Possible Problem: My Rails-server did not start on Windows 7, because ExecJS was unable to detect a Javascript Runtime, even though, I had NodeJS installed.
  • Reason on my machine: The NodeJS-directory was part of the environment, but surrounded by quotations (eg. [...];"C:\Program Files\nodejs\";[...]). This lead to where and ExecJS being unable to understand the path-entry and, eventually, not finding the node.js executable.
  • Solution: see below...

To get my Rails-server to start on Windows (7 64bit), I

  • installed NodeJS to a directory that does NOT include spaces (eg. in C:\development\nodejs\) ... because where (Windows version of which) was not able to find executables in the PATH if the respective entry was surrounded by quotation marks

  • made sure that where node returned the node-executable (eg. C:\development\nodejs\node.exe) I just installed (if where can't find NodeJS, execJS will probably not find it either) if where node returns an error, check your PATH-variable, you may want to move the entry for NodeJS to the front and NOT use quotation marks

  • excluded therubyracer from the Gemfile by changing the respective line to gem 'therubyracer', :platforms => :ruby (as said before) this will lead to therubyracer being installed in Linux/production environment, but not on local Windows environment

  • deleted the Gemfile.lock and called bundle install in order to have a clean installation of the gemfiles

  • started Rails with rails server

0

It won't allow you to start the server inside any directory. Just go to the root directory and type

rails server   

or

rails s

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