Rails - Could not find a JavaScript runtime?

JavascriptRuby on-RailsRuby on-Rails-3node.jsRuby on-Rails-3.1

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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+

Solution 3 - Javascript

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.

Solution 4 - Javascript

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.

Solution 5 - Javascript

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.

Solution 6 - Javascript

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.

Solution 7 - Javascript

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

Solution 8 - Javascript

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.

Solution 9 - Javascript

On CentOS 6.5, the following worked for me:

sudo yum install -y nodejs

Solution 10 - Javascript

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.

Solution 11 - Javascript

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.

Solution 12 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael DurrantView Question on Stackoverflow
Solution 1 - JavascripttheTuxRacerView Answer on Stackoverflow
Solution 2 - JavascriptGazlerView Answer on Stackoverflow
Solution 3 - JavascriptRamiz RajaView Answer on Stackoverflow
Solution 4 - JavascriptflyingsnowView Answer on Stackoverflow
Solution 5 - JavascriptYangView Answer on Stackoverflow
Solution 6 - JavascriptEdub KendoView Answer on Stackoverflow
Solution 7 - JavascriptSnirDView Answer on Stackoverflow
Solution 8 - Javascriptuser3576216View Answer on Stackoverflow
Solution 9 - JavascriptBob StineView Answer on Stackoverflow
Solution 10 - JavascriptgnerkusView Answer on Stackoverflow
Solution 11 - JavascriptPatrickView Answer on Stackoverflow
Solution 12 - JavascriptdeheldenView Answer on Stackoverflow