ExecJS and could not find a JavaScript runtime
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
Comments
-
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 about 13 yearstried it. no luck. I wonder if it is a rvm conflict or something. Everything other people have suggested hasn't worked for me.
-
eldewall about 13 yearsOkey, 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 about 13 yearsYou can try changing the Gemfile so it uses rails3.1.0rc2 instead of 3.1.0.rc1 and run bundle install
-
srboisvert about 13 yearsactually, i just reinstalled nodejs and it worked. Not sure what I did before but yay!
-
wonderfulthunk about 13 yearsThis 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 almost 13 yearsWas deploying on Heroku and received that error. Once I added the new gem and deployed, I was golden.
-
Mert Fırat almost 13 yearsgem 'execjs' gem 'therubyracer' it's a better solution than this one.
-
RushHour almost 13 yearsFor Rails 3.1 RC 6, you just need to specify
gem 'therubyracer'
-
Richard Fawcett almost 13 yearsIs there anyway to have these gems included in the default Gemfile when a new application is created?
-
mydoghasworms over 12 yearsWorks on Ubuntu 11.04, 11.10. Thanks. Easy solution, but like other comments say: Why this? Must we always do this now?
-
jdkealy over 12 yearsthis 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 over 12 yearsAs 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 over 12 yearsalso add gem 'execjs' in Gemfile
-
JDutil over 12 yearsexecjs is already included by rails now. It was only also required during the release candidates.
-
jasoares over 12 yearsI'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 over 12 yearsHeroku 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 over 12 yearsHeroku 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 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 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 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 addtherubyracer
every time on your own. -
miguelSantirso over 12 yearsYou don't need to add 'execjs'
-
manish nautiyal over 12 yearsYes u r right in rails 3.2.1 you have to use only gem'therubyracer'
-
Yashima over 12 yearsThanks, this one fixed it for me on Ubuntu Oneiric using rvm installation of ruby 1.9.3 and Rails 3.2.1
-
Frantz Romain about 12 yearsBest Answer. Worked for rails version 3.2.3
-
Benoit about 12 yearsI prefer the Gemfile solution as it allows the project to build without dependancies on system-wide libraries
-
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 about 12 yearsI 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 almost 12 yearsThis 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 over 11 years@MarkBerry thanks! I removed therubyracer and installed nodejs and it also sped up my dev env. Sweet.
-
ncherro over 11 yearsI ran into the error on a CentOS server with node.js installed. This got me past it. Thanks!
-
Sturm over 11 yearsIt 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 over 11 yearsThis seems to be causing problems with heroku deployment.
-
Ravindra almost 11 yearsThanks @manish nautiyal and @ Peter Mortensen. it works for me
-
Travis Pessetto over 10 yearsI 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 over 10 yearshow do you add nodejs to the gemfile? I didn't find a nodejs gem.
-
duma over 9 yearsDoing
sudo apt-get install nodejs
worked for me on 14.04, but I suspect it's because it also installed libv8. I feel like installingtherubyracer
should fail if you don't have libv8 installed, but it doesn't -- it acts like it succeeds. -
damuz91 about 8 yearsThanks, this should be in a higher level
-
jjk over 6 yearsthis was essential to getting a capistrano deployment to work on AWS standard linux distro.
-
Rafael Gomes Francisco over 5 yearsworks like charm! A advice: I needed make symlink for
nodejs
also -
Luke Abel over 3 yearsNew man page for
bundler
gemfile: bundler.io/v2.2/man/gemfile.5.html#PLATFORMS -
Matt West about 3 yearsBOOM. 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 over 2 yearsIt does not work with Rails 6 and Ubuntu 18.04, does anyone show me how to fix it?