Node.js not found by Rails / execjs

后端 未结 3 639
谎友^
谎友^ 2020-12-06 12:38

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

相关标签:
3条回答
  • 2020-12-06 13:26

    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.

    0 讨论(0)
  • 2020-12-06 13:33

    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.

    0 讨论(0)
  • 2020-12-06 13:36

    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!

    0 讨论(0)
提交回复
热议问题