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.
This question is related to
javascript
ruby-on-rails
ruby-on-rails-3
node.js
ruby-on-rails-3.1
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.
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.
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.
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.
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.
On CentOS 6.5, the following worked for me:
sudo yum install -y nodejs
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:
usr/share/applications
vim RubyMine
/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
As a benefit all your environment variables are now available for RubyMine. So you feel no pain with additing them.
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.
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+
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
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.
Source: Stackoverflow.com