I'm getting this error:
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs,
I have already spent more hours searching google then I am willing to admit. I believe this is an execJs bug.
From all the posts, this is a very common issue with rails 3.1. A js runtime is now needed by what are now standard gems like coffee-script and sass.
Most of these cases were resolved by adding the gems 'execjs' and 'therubyracer' to the app Gemfile, and then running 'bundle update' and/or 'bundle install'. But not for me.
I guess I got lucky. I am running rails 3.1.3/ruby 1.9 on an old version of Redhat Linux 4 (2.6.9-101.ELsmp) and gcc is 3.4.6.
Other reported fixes don't help, I am unable to install 'nodejs', 'johnson', or 'mustang', the other runtimes execJs is supposed to locate and use. They won't make/install on my system.
I need to fix the problem causing execJs to fail to locate 'therubyracer'. Here is the Gemfile (and bundle install says Ok):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'sho-mongrel'
gem 'execjs'
gem 'therubyracer'
#gem "therubyracer", :require => 'v8'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
And here is a trace:
~/rails/316-private-pub/chatter-after>rake db:create --trace
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
/home/vitalarthur/rails/316-private-pub/chatter-after/config/application.rb:7:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/vitalarthur/rails/316-private-pub/chatter-after/Rakefile:5:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'
There is nothing interesting in the development log.
Here is the execjs dir:
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs>ls
disabled_runtime.rb module.rb ruby_rhino_runtime.rb version.rb
external_runtime.rb mustang_runtime.rb runtimes.rb
johnson_runtime.rb ruby_racer_runtime.rb
I have also tried execjs-1.2.13. Same problem.
If I comment execjs.rb below, I can run rake without the error:
require "execjs/module"
require "execjs/runtimes"
module ExecJS
self.runtime #||= Runtimes.autodetect
end
But then I don't get a runtime.
I can see where the error text comes from in runtimes.rb:
def self.autodetect
from_environment || best_available ||
raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
"See https://github.com/sstephenson/execjs for a list of available runtimes.")
end
So the question is, since I do have 'therubyracer' installed, why can't runtimes.rb find it? Is execJs broken?
Here it 'therubyracer':
/usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9
How can I fix this?
Ubuntu Users:
I had the same problem and I fixed it by installing nodejson my system independent of the gem.
on ubuntu its: sudo apt-get install nodejs
I'm using 64bit ubuntu 11.10
update:
From #Galina 's answer below I'm guessing that the latest version of nodejs is required,
so #steve98177 your best option on a redhat(or CentOS) box is to install from source code as #Galina did, but as you can't "make/install" on this box ?, I suggest you try to install a fedora rpm(long shot) https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
or find another RH/CentOs box(that you can 'make' on) and create your own rpm and install on original RH box(if old glibc on RH plays nice).
The real issue here(IMHO) is installing Gems that have dependencies on installed packages outside of the ruby environment, is there a way of knowing before installing ? an RFI for Gems or bundler ?
CentOS/RedHat Users:
sudo yum install nodejs
In your gemfile add:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
For more details:
ExecJS and could not find a JavaScript runtime
This is the link I needed to fix the problem (install nodejs): https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
When you create an empty project, this line is commented in Gemfile. Just uncomment it and bundle!
gem 'therubyracer', :platforms => :ruby
If you were on ubuntu
$ sudo apt-get install nodejs
Try to don't use another systems like Windows to development. Think that almost all servers in the world are Linux servers, so when you try to deploy that application it will be easier if you have developed that on a Linux or Unix environment too.
I had similar issues on ubuntu 12.04. Installing Node.js fixed it.
I am using Ubuntu 11.10- 32 bit with ruby 1.9.3p194, rails 3.2.3, gem 1.8.24. Was receiving the same Javascript error while running "script/rails console".
However doing a "sudo apt-get install nodejs" solved my issue.
Fedora users WILL NOT be able to do a simple "yum install nodejs" due to serious naming and file placement conflicts that prevent this package from even being available through the Fedora repositories.
There is apparently at least one alternate repository available with an alternate build that may work, but that's two too many "alternates" for me to be willing to use it-- I'm looking for another alternative.
Try installing NodeJS and try again.
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
NodeJS should be able to solve this issue.
You could also factor the version
I had the same problem on a staging server. I had no issues running rake tasks on my local development machine, but deploying to the staging server failed with the "Could not find a JavaScript runtime" error message while trying to run the assets:precompile rake task.
Of course, therubyracer and execjs were in my Gemfile, and I was using the latest versions. My Gemfile.lock files matched, and I further verified versions by running bundle show.
After searching around on Google, I ended up deleting all of my gems and reinstalling them which fixed the problem. I still don't know what the root cause was, but maybe this will help you.
Here's what my environment looks like, BTW:
Ubuntu 10.04.3 LTS
rbenv
Ruby 1.9.2-p290
bundler-1.0.21
execjs-1.3.0
therubyracer-0.9.9
I had the same problem. Adding the gems 'execjs' and 'therubyracer' not work for me.
apt-get install nodejs - also dosn't works. I'm using 64bit ubuntu 10.04.
But it helped me the following:
1. I created empty folder (for example "java").
2. From the terminal in folder that I created I do:
$ git clone git://github.com/ry/node.git
$ cd node
$ ./configure
$ make
$ sudo make install
After that I run "bundle install" as usual (from folder with ruby&rails project).
And the problem was resolved. Ruby did not have to reinstall.
I had this occur to me on my Windows machine, turns out the problem was quite different. I had accidentally removed some paths from my %PATH% variable. Simply restarting the command prompt solved it. It seems as though there was a JS runtime in one of those missing paths.
I have pulled my hair out with this error a few time. I have managed to make it sometime disappear by restarting Apache/Nginx.
So I fixed it the same way as above, by adding the following to the GEM file:
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
and then I DELETED my gemfile.lock file and then reran "bundle install". I found only then did "bundle install" actually install the correct libraries etc.
On Ubuntu, I had to sudo apt-get update and then the nodejs install worked.
when i generate rails g controller i got the same error. After that when do the following changes on Gemfile(in rails 4) everything went smooth.The changes i made was
gem 'execjs'
gem 'therubyracer', "0.11.4"
After that i can able to run the server and able to do all basic operations on the application.
For mac, install node with
brew install node
add in your gemfile which is in the folder you have created:
gem 'execjs'
gem 'therubyracer'
In my case running the bundle command did the trick. I trust they find each other then.
I had this problem when using RubyMine (6.3.3). One day I tried to run my code, but it didn't work and complained about no JavaScript runtime found. I was able to run rails s though. The fix for me was creating a new Run configuration. Seems really bizarre that the Run configuration would become corrupt.
I was getting the same old error when trying to run a rails app via a Dockerfile.
As suggested by user #PaulWilliams, I used apt to grab the missing package by adding these lines:
RUN apt-get update
RUN apt-get install nodejs -y
Notes
I didn't need to change/edit Gemfile or Gemfile.lock at all.
This solution didn't work for me when the lines were added early in the build process. It only worked when the lines were placed immediately before the line in the Dockerfile that was erroring.
If you happen to get the error on fly.io, here's some more information/documentation on the fix.
Lastly, I didn't have (nor need 'therubyracer') in my rails app, but was still getting the first part of the error message execJs: 'Could not find a JavaScript runtime'
Hope it helps someone.
When trying to launch the rails console after updating my ruby setup using 'sudo gem update --system', I then try execute the rails console by issuing rails c
I get this error:
Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find json (~> 1.4) amongst [Ascii85-1.0.1, abstract-1.0.0, actionmailer-3.1.1, actionmailer-3.1.0, actionmailer-3.0.9, actionmailer-3.0.5, actionmailer-3.0.3, actionpack-3.1.1, actionpack-3.1.0, actionpack-3.0.9, actionpack-3.0.5, actionpack-3.0.3, activemodel-3.1.1, activemodel-3.1.0, activemodel-3.0.10, activemodel-3.0.9, activemodel-3.0.5, activemodel-3.0.3, activerecord-3.1.1, activerecord-3.1.0, activerecord-3.0.9, activerecord-3.0.5, activerecord-3.0.3, activeresource-3.1.1, activeresource-3.1.0, activeresource-3.0.9, activeresource-3.0.5, activeresource-3.0.3, activesupport-3.1.1, activesupport-3.1.0, activesupport-3.0.10, activesupport-3.0.9, activesupport-3.0.5, activesupport-3.0.3, addressable-2.2.6, ansi-1.3.0, arel-2.2.1, arel-2.0.10, arel-2.0.9, arel-2.0.7, bcrypt-ruby-3.0.1, bcrypt-ruby-3.0.0, bcrypt-ruby-2.1.4, builder-3.0.0, builder-2.1.2, bundler-1.0.21, bundler-1.0.18, bundler-1.0.11, choices-0.2.4, cocaine-0.2.0, coffee-rails-3.1.1, coffee-rails-3.1.0, coffee-script-2.2.0, coffee-script-source-1.1.2, devise-1.4.8, devise-1.4.2, erubis-2.7.0, erubis-2.6.6, execjs-1.2.9, execjs-1.2.6, execjs-1.2.4, faraday-0.7.4, faraday-0.6.1, faraday_middleware-0.7.0, faraday_middleware-0.6.3, fastercsv-1.5.4, formtastic-2.0.2, formtastic-1.2.4, geocoder-1.0.4, geocoder-1.0.2, has_scope-0.5.1, hashie-1.1.0, hashie-1.0.0, heroku-2.7.0, hike-1.2.1, i18n-0.6.0, i18n-0.5.0, inherited_resources-1.3.0, inherited_resources-1.2.2, jquery-rails-1.0.16, jquery-rails-1.0.14, kaminari-0.12.4, launchy-2.0.5, libv8-3.3.10.2-x86_64-darwin-10, mail-2.3.0, mail-2.2.19, mail-2.2.15, mail-2.2.14, mechanize-2.0.1, mechanize-1.0.0, meta_search-1.1.1, meta_search-1.0.6, mime-types-1.16, multi_json-1.0.3, multi_xml-0.4.1, multi_xml-0.4.0, multi_xml-0.3.0, multi_xml-0.2.2, multipart-post-1.1.3, multipart-post-1.1.2, mysql-2.8.1, mysql2-0.3.7, mysql2-0.2.7, mysql2-0.2.6, net-http-digest_auth-1.1.1, net-http-persistent-2.1, net-http-persistent-2.0, net-http-persistent-1.9, nokogiri-1.5.0, nokogiri-1.4.4, orm_adapter-0.0.5, pdf-reader-0.10.0, pg-0.11.0, polyamorous-0.5.0, polyglot-0.3.2, polyglot-0.3.1, prawn-0.12.0, rack-1.3.4, rack-1.3.3, rack-1.3.2, rack-1.2.3, rack-1.2.2, rack-1.2.1, rack-cache-1.1, rack-cache-1.0.3, rack-mount-0.8.3, rack-mount-0.6.14, rack-mount-0.6.13, rack-ssl-1.3.2, rack-test-0.6.1, rack-test-0.5.7, rails-3.1.1, rails-3.1.0, rails-3.0.9, rails-3.0.5, rails-3.0.3, railties-3.1.1, railties-3.1.0, railties-3.0.9, railties-3.0.5, railties-3.0.3, rake-0.9.2, rake-0.8.7, rake-0.8.7, rash-0.3.1, rash-0.3.0, rdoc-3.10, rdoc-3.9.4, rdoc-3.9.2, responders-0.6.4, rest-client-1.6.7, rubygems-update-1.8.11, rubygems-update-1.8.10, rubygems-update-1.7.2, rubygems-update-1.7.1, rubygems-update-1.6.2, rubyzip-0.9.4, sass-3.1.10, sass-3.1.7, sass-rails-3.1.4, sass-rails-3.1.2, sass-rails-3.1.0, simple_oauth-0.1.5, sprockets-2.0.2, sprockets-2.0.0, sqlite3-1.3.4, term-ansicolor-1.0.6, therubyracer-0.9.4, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, treetop-1.4.9, ttfunk-1.0.3, ttfunk-1.0.2, turn-0.8.2, twitter-1.7.1, twitter-1.4.1, tzinfo-0.3.30, tzinfo-0.3.29, tzinfo-0.3.26, tzinfo-0.3.24, uglifier-1.0.3, warden-1.0.6, warden-1.0.5, webrobots-0.0.12, webrobots-0.0.11] (Gem::LoadError)
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1932:in `block in traverse'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1931:in `each'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1931:in `traverse'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:465:in `block in find_in_unresolved_tree'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:463:in `reverse_each'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:463:in `find_in_unresolved_tree'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:47:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.1/lib/rails/script_rails_loader.rb:1:in `<top (required)>'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.1/lib/rails/cli.rb:2:in `<top (required)>'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/gems/rails-3.1.1/bin/rails:7:in `<top (required)>'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/bin/rails:19:in `load'
from /Users/myusername/.rvm/gems/ruby-1.9.2-p136/bin/rails:19:in `<main>'
Any ideas?
what do you get when you try to list your gems.. is json >= 1.4 there?
e.g.:
> gem list json
*** LOCAL GEMS ***
json (1.6.1, 1.5.4, 1.5.3, 1.5.1, 1.4.2)
json_pure (1.6.1, 1.5.4, 1.5.3)
if you use RVM gemsets, you may want to list them also, to check if your default gemset has changed:
rvm gemset list
EDIT: Mystery Solved! :-)
you accidentially installed your gems with sudo -- but you have RVM installed for your user account!
When you have RVM installed for an individual user, it's generally not a good idea to do sudo gem install ... , but you should install the gems just for the local user and let RVM manage them for whatever Ruby version you are using.
If you still install with sudo, RVM will not find the gems, because they are stored in a different location, outside of RVM, and not searched by RVM...! Looks like that's the case you experienced.
Check this RailsCast: http://railscasts.com/episodes/200-rails-3-beta-and-rvm
if you're using Rails:
- edit your Gemfile and add the json dependency , then run bundle install
if you're just using Ruby by itself, or an old version or Ruby:
- run gem install json in the shell
With newer Ruby versions you should not manually install the gems
Add gem "json", "~> 1.4" in your Gemfile and run bundle install
Also
You only use the sudo command during the install process. In Multi-User configurations, any operations which require sudo access must use the rvmsudo command which preserves the RVM environment and passes this on to sudo. There are very few cases where rvmsudo is required once the core install is completed, except for when updating RVM itself. There is never a reason to use sudo post-install. Once users added to the 'rvm' group have logged out, then back in to gain rvm group membership, rvmsudo should only be needed for updating RVM itself with
rvmsudo rvm get head
Please read the https://rvm.beginrescueend.com/support/troubleshooting/ page The installer page also details this for new installations. You will need to remove your existing installation and redo it in order to properly reconfigure the permissions. In the future, never user sudo when working on your RVM installation, except when installing. Any other commands will not require sudo use except for
rvmsudo rvm get head
to update your installation. If the users are properly placed in the rvm group as detailed on the site, you will have no need to use sudo at all, and rvmsudo only for updating.
Also, RVM does not manage the system installed ruby at all! We do provide the use of
rvm use system
in order to give a natural way to switch between RVM controlled rubies, and the system. Your package manager, or lack thereof for OS X, is responsible for managing your system installed ruby and is outside the control of RVM 100%.