4

I have created a new Rails application. When I try to start the server I get the following error:

[bathakarai@Project1-CO samp]$ rails server
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/script_rails_loader.rb:11: warning: Insecure world writable dir /usr in PATH, mode 040777
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /usr in PATH, mode 040777
/home/bathakarai/.rvm/gems/ruby-2.0.0-p0/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/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
    from /home/bathakarai/gold/Ruby/Practice/Rails/samp/config/application.rb:7:in `<top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /home/bathakarai/.rvm/gems/ruby-2.0.0-p0/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>'

How can I fix this error?

toro2k
  • 19,020
  • 7
  • 64
  • 71
Bathakarai
  • 1,517
  • 6
  • 23
  • 39

3 Answers3

9

If you've just generated a new application, this can come up when the gem therubyracer is commented. It is needed to compile your assets. You can uncomment that or install something like nodejs so you won't need to use the gem in all of your projects.

brew install nodejs
# or
sudo apt-get install nodejs
jvnill
  • 29,479
  • 4
  • 83
  • 86
3

Try

sudo gem install therubyracer

or

gem install therubyracer

Hope this helps

muttonlamb
  • 6,341
  • 3
  • 26
  • 35
  • 1
    After install therubyracer gem, run bundle or bundle install command. Once successful installation add "gem 'therubyracer'" line in Gemfile which is located inside the project – Bathakarai Mar 20 '13 at 04:54
  • OK but what if I don't use coffee-script and don't want execjs? Sprockets depends on execjs, but does rails 4 need sprockets? Can I just pull the plug on execjs? – Ziggy Aug 08 '13 at 17:29
  • Great solution @Bathakarai! [Here](https://gist.github.com/lucio-martinez/23110e3618c1bac7f641) is a snippet to quickly solve it :-) – Lucio Sep 28 '14 at 04:17
1

The most popular JavaScript runtime is therubyracer which is a gem. As @muttonlamb said, install it running:

gem install therubyracer

Then, as Bathakarai mentioned, add the next line into your Gemfile at the bottom of the file:

gem 'therubyracer'

Now run rails server again and everything should be working.

To simplify the process you can run a script to generate the app and add the JS runtime automatically.

Community
  • 1
  • 1
Lucio
  • 4,753
  • 3
  • 48
  • 77