266

I created a new Rails project using rails 3.1.0.rc4 on my local machine but when I try to start the server I get: Could not find a JavaScript runtime. See here for a list of available runtimes. (ExecJS::RuntimeUnavailable)

Note: This is not about Heroku.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • 1
    possible duplicate of [ExecJS and could not find a JavaScript runtime](http://stackoverflow.com/questions/6282307/execjs-and-could-not-find-a-javascript-runtime) – Lucio Sep 17 '14 at 21:03

13 Answers13

503

Installing a javascript runtime library such as nodejs solves this

To install nodejs on ubuntu, you can type the following command in the terminal:

sudo apt-get install nodejs

To install nodejs on systems using yum, type the following in the terminal:

yum -y install nodejs
Community
  • 1
  • 1
theTuxRacer
  • 13,709
  • 7
  • 42
  • 59
  • 14
    for me too. `sudo apt-get install nodejs`. – Hertzel Guinness Dec 09 '11 at 03:34
  • 1
    I now recommend this as the route to take. See above. – Michael Durrant Dec 29 '11 at 02:13
  • 1
    removed note in the answer about installing node through the Ubuntu software center as it wasn't in there (Ubuntu 12.04) – Michael Durrant Nov 25 '12 at 14:08
  • 2
    Ubuntu 64 is giving a huge trouble to get therubyracer installed, not even the last version, 0.11.1, solved that. This answer helped me on that. – Eduardo Jan 09 '13 at 20:59
  • @gwho There is an answer below by Yang. Take a look at that. – theTuxRacer Jul 15 '14 at 09:57
  • Worked for me too. While generating controller (Rails project) I was getting below mentioned error:- There was an error while trying to load the gem 'coffee-rails'. (Bundler::GemRequireError) Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. Following above set resolved the issue – Apurva Mayank Aug 03 '17 at 05:37
47

Note from Michael 12/28/2011 - I have changed my accept from this (rubytheracer) to above (nodejs) as therubyracer has code size issues. Heroku now strongly discourage it. It will 'work' but may have size/performance issues.

If you add a runtime, such as therubyracer to your Gemfile and run bundle then try and start the server it should work.

gem 'therubyracer'

A javascript runtime is required for compiling coffeescript and also for uglifier.

Update, 12/12/2011: Some folks found issues with rubytheracer (I think it was mostly code size). They found execjs (or nodejs) worked just as well (if not better) and were much smaller.

n.b. Coffeescript became a standard for 3.1+

Hosam Aly
  • 41,555
  • 36
  • 141
  • 182
Gazler
  • 83,029
  • 18
  • 279
  • 245
  • 3
    It is also used for compressing JavaScript with UglifyJS. Note that the recommended way of doing these tasks is to do them in development with `rake assets:precompile` and then add assets to your repository; Rails 3.1 won't actually require a JavaScript runtime in production at the time of release. – Catherine Aug 17 '11 at 11:48
  • 1
    I've marked this as the answer. It was a bit hairy as this didn't fix it right away and I was also trying new apps with 3.0.9 and 3.0.4 but got (different) errors with them. Finally I did a new app again - and also got rails rc5 with it and added the rubytheracer and did a bunlde update and finally I can get the server up and running. Thanks Gazier! – Michael Durrant Aug 17 '11 at 12:35
  • 1
    btw The standard rails app that gets created does use uglifier which also requires this I believe. – Michael Durrant Aug 17 '11 at 12:39
  • 1
    I think a good practice could be put it in the gemfile under the development group , something like `group :development do gem 'therubyracer' end` – eveevans Oct 31 '11 at 22:11
  • @eveevans the runtime cannot be found error. The asset is compiled in the production environment so therubyracer has to be under the production env block. – lulalala Jul 11 '12 at 01:20
  • No, the assets must be compiled in development environment, obviously you can compile it in production, but that's a bad practice. – eveevans Jul 12 '12 at 23:07
  • if you open your gemfile this gem is already inside but commented out. Removing the # and running bundle install should do it – Geo Nov 17 '12 at 22:33
  • In my case, I was running into this issue because using `therubyracer` with Sidekiq is not [recommended](https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#not-thread-safe-gems). – Rodrigo Dias Dec 19 '17 at 12:55
31

Add following gems in your gem file

gem 'therubyracer'
gem 'execjs'

and run

bundle install

OR

Install Node.js to fix it permanently for all projects.

Ramiz Raja
  • 5,942
  • 3
  • 27
  • 39
  • 1
    This worked for me (Linux Mint 16), I think that in the latest version of rails either misses off some of the dependencies. – geminiCoder Jan 31 '14 at 10:52
16

sudo apt-get install nodejs does not work for me. In order to get it to work, I have to do the following:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Hope this will help someone having the same problem as me.

Justin Force
  • 6,203
  • 5
  • 29
  • 39
flyingsnow
  • 161
  • 1
  • 2
  • doenst work for me the add-apt-repository ppa:chris-lea/node.js – jpganz18 May 02 '13 at 22:38
  • @jpganz18 try this first: `sudo apt-get install software-properties-common` If this does not solve the problem, you could install it manually: http://blog.anantshri.info/howto-add-ppa-in-debian/ – Robin Sep 25 '13 at 11:38
7

On the windows platform, I met that problem too The solution for me is just add

C:\Windows\System32

to the PATH

and restart the computer.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Yang
  • 825
  • 1
  • 10
  • 13
4

I had this issue on a Windows machine and installing node.js was the solution that finally worked for me. This came after trying multiple other routes including trying to get 'therubyracer' working. Though the github for node.js suggests that installation on windows is still unstable, the website at http://nodejs.org/ had a Windows installer which worked perfectly.

Edub Kendo
  • 473
  • 2
  • 11
1

if you already install nodejs from source for example, and execjs isn't recognizing it you might want to try this tip: https://coderwall.com/p/hyjdlw

SnirD
  • 708
  • 11
  • 22
1

If all fails you can try

# aptitude install nodejs

as root. You can test your install with the following command:

# node -v

If you want to install NPM, please refer following link. Hope it helps.

0

On CentOS 6.5, the following worked for me:

sudo yum install -y nodejs
zishe
  • 10,665
  • 12
  • 64
  • 103
Bob Stine
  • 905
  • 10
  • 13
0

Install a Javascript runtime

The error is caused by the absence of a Javascript runtime on your local machine. To resolve this, you'll need to install NodeJS.

You can install NodeJS through the Node Version Manager or nvm:

First, install nvm:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

Install Node through nvm:

nvm install 5.9.1

This will install version 5.9.1 of Node.

gnerkus
  • 11,357
  • 6
  • 47
  • 71
0

I ran into this issue using Phusion Passenger (running as an nginx module) on a Redhat server. We already had a Javascript runtime installed. Other Rails apps in the same parent directory worked fine.

It turned out that we had a permissions issue. Run "ls -l" and see if the folder has the same owner and group as other working apps on the system. I had to run chown and chgrp on the folder (with the recursive switch) to fix it.

Patrick
  • 1,227
  • 14
  • 17
0

I hope you have pre-installed nodejs || nmv.

My solution does not require gem setup or installing 'node with sudo apt" when you already have nvm.

All you need is to edit DesctopEntry of RubyMine. for that we will have those small steps:

  1. Go to usr/share/applications
  2. Open in any editor (i use vim ) Rubymine DesktopEntry vim RubyMine
  3. Edit line 6 (starts with Exec). You shoud add to beginning /bin/bash -i -c. So your line should look like this Exec=/bin/bash -i -c "/home/USERNAME/rubymine/RubyMine-2019.1.2/bin/rubymine.sh" %f
  4. Done! You are glorious!

As a benefit all your environment variables are now available for RubyMine. So you feel no pain with additing them.

dehelden
  • 39
  • 6
0

On MacOS try running:

brew install node

brew link node

To force the link and overwrite all conflicting files:

brew link --overwrite node

node -v
kimbo
  • 2,513
  • 1
  • 15
  • 24
B. Lakshmi
  • 159
  • 8