7

I have node.js installed by compiling and installing it from the root user. I think this maybe where the hangup is. From the user running the rails app I checked for node.js.

$ which node
/usr/local/bin/node

When I launched my rails app (Rails 3.2.9) I get the universally unhelpful "We're sorry, but something went wrong." Checking the the production error log I saw that the Javascript runtime was not found. That's confusing as it is obviously installed. So I went about forcing the Node javascript runtime. I edited config/boot.rb to include:

ENV['EXECJS_RUNTIME'] = 'Node'

I checked my app again, while watching the production log. This time I got the error

ActionView::Template::Error (Node.js (V8) runtime is not available on this system

Still confused. I went to the execjs gem and changed the runtime command to the exact installed path.

Node = ExternalRuntime.new(
  :name        => "Node.js (V8)",
  :command     => "/usr/local/bin/node",
  :runner_path => ExecJS.root + "/support/node_runner.js",
  :encoding    => 'UTF-8'
)

I still get the same error. Node is installed and accessible by the user but the gem/rails can't seem to use it. The server is run CentOS 6.3. The specific javascript file causing the error to be thrown is jquery.nivo.slider.pack.js. Which I didn't edit after downloading it from nivo.

1
  • 1
    Your solution worked for me. I have a fedora box and serve an app using phusion passenger. I had to restart the app though, after I changed the runtime command, as you indicated above for this to work. Commented Apr 18, 2013 at 11:41

3 Answers 3

6

So, I have Ruby 2.0.0 installed and Rails 4.0.2 on CentOS 5.10 using Apache2 with Passenger. My first step I tried was opening the rails console and typing in the following command:

ExecJS.runtime

It returned the following value:

#<ExecJS::ExternalRuntime:0x99ab380 @name="Node.js (V8)", @command=["nodejs", "node"],@runner_path="/home/foo/vendor/bundle/ruby/2.0.0/gems/execjs-2.1.0 /lib/execjs/support/node_runner.js", @encoding="UTF-8", @deprecated=false, @binary="node">

Which meant that node was indeed installed and detected, but for some reason it was not working.

So, I tried the example on the website:

ExecJS.eval("'red yellow blue'.split(' ')")

and I got the correct response. So, now I am wondering why Passenger isn't picking it up.

Then, I noticed that passenger shows the path variable and it looks like:

/home/foo/vendor/bundle/ruby/2.0.0/bin:/usr/local/rvm/gems/ruby-2.0.0-p481/bin:/usr/local/rvm/gems/ruby-2.0.0-p481@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p481/bin:/usr/kerberos/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/rvm/bin:/home/foo/bin

But, it seems to be missing the usr/local/bin. I'm no expert on Linux, so for me the easiest way to fix this is with a symbolic link. So, I execute ln -s /usr/local/bin/node /usr/bin/node. You may want to note that I found the path to my nodejs using the command find / -name node.

I then refreshed my web application and wouldn't you know it worked. So, if it worked for me I am hoping that it can help someone else out.

UPDATE (Probably Better Way): This is probably a better way to do it. We can compile it from source like so:

mkdir ~/install
cd ~/install
wget https://nodejs.org/dist/v7.2.1/node-v7.2.1.tar.gz
tar xvf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure --prefix=/usr/
make && make install

This way Node.js will be installed in the path where Passenger expects it to be.

Sign up to request clarification or add additional context in comments.

3 Comments

Well, I searched for hours until I found this. My nodejs was fully installed, and your solution solved my problem. Although using a symlink doesn't look like the best solution.... Anyway, thanks!!
Where did you see that Passenger is looking for node in different path?
@simo this was almost 5 years ago so I don't remember but I think it was in the console after running the commands as listed above.
1

I have had similar issue installing nodejs with source on my centos 6.3 system. It was successfully installed but I keep failing in compiling my ror app assets until I explicitly set the PATH to where it was installed (nodejs)

[root]# make install
...
installing /usr/local/lib/node_modules/npm/html/doc/folders.html
symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /usr/local/bin/npm
updating shebang of /usr/local/bin/npm to /usr/local/bin/node

[root]# export PATH=/usr/local/bin:$PATH

Now it works. Hope that helps!

Comments

0

I don't know if this will help but check your $PATH that node is in there. Also, you should be using rvm if you want to use node. Check that your node install is done correctly.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.