ExecJS and could not find a JavaScript runtime

263,847

Solution 1

Ubuntu Users

I'm on Ubuntu 11.04 and had similar issues. Installing Node.js fixed it.

As of Ubuntu 13.04 x64 you only need to run:

sudo apt-get install nodejs

This will solve the problem.


CentOS/RedHat Users

sudo yum install nodejs

Solution 2

Just add ExecJS and the Ruby Racer in your gem file and run bundle install after.

gem 'execjs'

gem 'therubyracer'

Everything should be fine after.

Solution 3

In your Gem file, write

gem 'execjs'
gem 'therubyracer'

and then run

bundle install

Everything works fine for me :)

Solution 4

I had a similar problem: my Rails 3.1 app worked fine on Windows but got the same error as the OP when running on Linux. The fix that worked for me on both platforms was to add the following to my Gemfile:

gem 'therubyracer', :platforms => :ruby

The trick is knowing that :platforms => :ruby actually means only use this gem with "C Ruby (MRI) or Rubinius, but NOT Windows."

Other possible values for :platforms are described in the bundler man page.

FYI: Windows has a builtin JavaScript engine which execjs can locate. On Linux there is not a builtin although there are several available that one can install. therubyracer is one of them. Others are listed in the execjs README.md.

Solution 5

Adding the following gem to my Gemfile solved the issue:

gem 'therubyracer'

Then bundle your new dependencies:

$ bundle install
Share:
263,847
srboisvert
Author by

srboisvert

Enough about me.

Updated on July 08, 2022

Comments

  • srboisvert
    srboisvert almost 2 years

    I'm trying to use the Mongoid / Devise Rails 3.1 template (Mongoid and Devise), and I keep getting an error stating ExecJS cannot find a JavaScript runtime. Fair enough when I didn't have any installed, but I've tried installing Node.js, Mustang and the Ruby Racer, but nothing is working.

    I could not find a JavaScript runtime. See sstephenson/ExecJS (GitHub) for a list of available runtimes (ExecJS::RuntimeUnavailable).

    What do I need to do to get this working?

  • srboisvert
    srboisvert about 13 years
    tried it. no luck. I wonder if it is a rvm conflict or something. Everything other people have suggested hasn't worked for me.
  • eldewall
    eldewall about 13 years
    Okey, i got the error when i tried generating a model in rails 3.1.0rc2. Does generating models work for you? (this was before installing nodejs that fixed it)
  • eldewall
    eldewall about 13 years
    You can try changing the Gemfile so it uses rails3.1.0rc2 instead of 3.1.0.rc1 and run bundle install
  • srboisvert
    srboisvert about 13 years
    actually, i just reinstalled nodejs and it worked. Not sure what I did before but yay!
  • wonderfulthunk
    wonderfulthunk about 13 years
    This worked for me, rails 3.1rc4 and Ubuntu 11.04 (my first try with rails 3.1). I was trying to generate a scaffold when I got the error. Still pretty lame that rails 3.1 is "broken" out of the box.
  • François Beausoleil
    François Beausoleil almost 13 years
    Was deploying on Heroku and received that error. Once I added the new gem and deployed, I was golden.
  • Mert Fırat
    Mert Fırat almost 13 years
    gem 'execjs' gem 'therubyracer' it's a better solution than this one.
  • RushHour
    RushHour almost 13 years
    For Rails 3.1 RC 6, you just need to specify gem 'therubyracer'
  • Richard Fawcett
    Richard Fawcett almost 13 years
    Is there anyway to have these gems included in the default Gemfile when a new application is created?
  • mydoghasworms
    mydoghasworms over 12 years
    Works on Ubuntu 11.04, 11.10. Thanks. Easy solution, but like other comments say: Why this? Must we always do this now?
  • jdkealy
    jdkealy over 12 years
    this is a better solution than installing node.js. If you're deploying to a remote server or sharing the app with other developers, having everyone install node.js is a lot more pain than just running bundle install, which they would be doing anyway.
  • vincent jacquel
    vincent jacquel over 12 years
    As stated above, since the official release of rails 3.1, just adding the rubyracer gem is enough. Although we would have liked to add nothing in the final release ! Thanks to foo for the precision.
  • Bijendra
    Bijendra over 12 years
    also add gem 'execjs' in Gemfile
  • JDutil
    JDutil over 12 years
    execjs is already included by rails now. It was only also required during the release candidates.
  • jasoares
    jasoares over 12 years
    I'm on Ubuntu 11.10 running Ruby 1.9.2 on Rails 3.1.3 freshly installed through RVM. I need both the package nodejs and the gem execjs to resolve the isse on my machine. I did not need the therubyracer gem, but the execjs per se did not solve the problem, so I guess for me it was a mix from the above and below solutions. Hope this can help others...
  • Mark Berry
    Mark Berry over 12 years
    Heroku is now strongly discouraging therubyracer due to memory use. I installed nodejs on my dev machine (github.com/joyent/node/wiki/…) and took therubyracer out of my gemfile. See also stackoverflow.com/questions/7092107/….
  • Mark Berry
    Mark Berry over 12 years
    Heroku is now strongly discouraging therubyracer due to memory use. I installed nodejs on my dev machine per this answer and took therubyracer out of my gemfile. See also stackoverflow.com/questions/7092107/….
  • William Denniss
    William Denniss over 12 years
    @dwaynemac I disagree. I'd rather the runtime exist as an OS library (as with Mac and Windows by default), rather than adding yet another gem to the dependancy list.
  • Mert Fırat
    Mert Fırat over 12 years
    @WilliamDenniss but it is a dependency. having it as a gem ensures you'll have that installed in any server you deploy.
  • KL-7
    KL-7 over 12 years
    @dwaynemac, true, but a lot of existing projects (as well as a fresh project generated by rails) do not have this dependency in their Gemfile and it's pretty annoying to have to add therubyracer every time on your own.
  • miguelSantirso
    miguelSantirso over 12 years
    You don't need to add 'execjs'
  • manish nautiyal
    manish nautiyal over 12 years
    Yes u r right in rails 3.2.1 you have to use only gem'therubyracer'
  • Yashima
    Yashima over 12 years
    Thanks, this one fixed it for me on Ubuntu Oneiric using rvm installation of ruby 1.9.3 and Rails 3.2.1
  • Frantz Romain
    Frantz Romain about 12 years
    Best Answer. Worked for rails version 3.2.3
  • Benoit
    Benoit about 12 years
    I prefer the Gemfile solution as it allows the project to build without dependancies on system-wide libraries
  • iGEL
    iGEL about 12 years
    @dwaynemac: To run the rails test suite, you need to have it installed manually. Within your own application, both ways are valid options.
  • leetheguy
    leetheguy about 12 years
    I was having this problem with Sinatra. I tried installing nodejs and may have missed a step but I was still receiving the error. Installing the two gems worked quite well. If this is the case with your rails app I recommend putting therubyracer in your development group and putting your app on heroku's cedar stack.
  • Mike Blyth
    Mike Blyth almost 12 years
    This is great, and such a simple fix. The Heroku site says RubyRacer is no longer required (with Cedar stack) so I was puzzled over why suddenly my program wasn't running locally. This did the trick.
  • Seth Malaki
    Seth Malaki over 11 years
    @MarkBerry thanks! I removed therubyracer and installed nodejs and it also sped up my dev env. Sweet.
  • ncherro
    ncherro over 11 years
    I ran into the error on a CentOS server with node.js installed. This got me past it. Thanks!
  • Sturm
    Sturm over 11 years
    It seems that therubyracer and execjs are causing problems with heroku deployment, unless there's something else that was modified that I missed. This is the preferred solution.
  • Sturm
    Sturm over 11 years
    This seems to be causing problems with heroku deployment.
  • Ravindra
    Ravindra almost 11 years
    Thanks @manish nautiyal and @ Peter Mortensen. it works for me
  • Travis Pessetto
    Travis Pessetto over 10 years
    I hesitate to add therubyracer to my Gemfile as it causes issues with Windows. I know I may be crazy to develop on Windows, but I have to for work.
  • Papouche Guinslyzinho
    Papouche Guinslyzinho over 10 years
    how do you add nodejs to the gemfile? I didn't find a nodejs gem.
  • duma
    duma over 9 years
    Doing sudo apt-get install nodejs worked for me on 14.04, but I suspect it's because it also installed libv8. I feel like installing therubyracer should fail if you don't have libv8 installed, but it doesn't -- it acts like it succeeds.
  • damuz91
    damuz91 about 8 years
    Thanks, this should be in a higher level
  • jjk
    jjk over 6 years
    this was essential to getting a capistrano deployment to work on AWS standard linux distro.
  • Rafael Gomes Francisco
    Rafael Gomes Francisco over 5 years
    works like charm! A advice: I needed make symlink for nodejs also
  • Luke Abel
    Luke Abel over 3 years
    New man page for bundler gemfile: bundler.io/v2.2/man/gemfile.5.html#PLATFORMS
  • Matt West
    Matt West about 3 years
    BOOM. Still a great answer in 2021. Kudos. In my case, I had to simlink for NVM, but the process was the same.
  • Huy Vu The
    Huy Vu The over 2 years
    It does not work with Rails 6 and Ubuntu 18.04, does anyone show me how to fix it?