Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails server does not start -> Could not find a JavaScript runtime [duplicate]

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
like image 442
jerseybyte Avatar asked May 30 '13 21:05

jerseybyte


2 Answers

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.

like image 108
Art Avatar answered Sep 27 '22 22:09

Art


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
like image 25
salcoin Avatar answered Sep 27 '22 22:09

salcoin