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.

1

13 Answers 13

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
6
  • 14
    for me too. sudo apt-get install nodejs. Dec 9, 2011 at 3:34
  • 1
    I now recommend this as the route to take. See above. Dec 29, 2011 at 2:13
  • 1
    removed note in the answer about installing node through the Ubuntu software center as it wasn't in there (Ubuntu 12.04) Nov 25, 2012 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 9, 2013 at 20:59
  • @gwho There is an answer below by Yang. Take a look at that. Jul 15, 2014 at 9:57
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+

8
  • 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, 2011 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! Aug 17, 2011 at 12:35
  • 1
    btw The standard rails app that gets created does use uglifier which also requires this I believe. Aug 17, 2011 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, 2011 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, 2012 at 1:20
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.

1
  • 1
    This worked for me (Linux Mint 16), I think that in the latest version of rails either misses off some of the dependencies. Jan 31, 2014 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.

2
  • doenst work for me the add-apt-repository ppa:chris-lea/node.js
    – jpganz18
    May 2, 2013 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: blog.anantshri.info/howto-add-ppa-in-debian
    – Robin
    Sep 25, 2013 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.

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.

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

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
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.

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.

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.