Node.js not found by Rails / execjs

后端 未结 3 648
谎友^
谎友^ 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: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:

    #

    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.

提交回复
热议问题