FCGI Ruby Gem not found when using apache - ruby

I am using Apache with FastCGI to run a ruby application. I have installed the apache fcgi module and also the Ruby fcgi gem.
When I run the fcgi script 'search.fcgi' like so
ruby search.fcgi
It runs successfully. However when starting Apache I get the following error in my log file when it tries to run the same script:
/usr/local/rvm/rubies/ruby-2.1.8/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- fcgi (LoadError)
from /usr/local/rvm/rubies/ruby-2.1.8/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/user/fcgi/search.fcgi:13:in `<main>'
Line 13 in search.fcgi is simply
require 'fcgi'
It appears as though when running through Apache it is unable to detect the installed gem. I have loaded irb and and run require 'fcgi' which returns true.
Am I missing something here? Some path or config item I need to set?

My problem was caused by the fact that Ruby was installed using RVM. There was some issue with the script from apache accessing some parts of the RVM instillation. The solution was to remove the RVM ruby install and reinstall ruby from source.

Related

Ruby - Can't require gem properly

I'm trying to require the gem 'cerebrum'. I tried requiring it using the irb, and that worked, and also running the program in JRuby worked too. However, Ruby throws a LoadError.
C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- cerebrum (LoadError)
from C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
What am I doing wrong? Has anyone had that issue too?
You get the load error when gem is not installed. First check if this gem is installed in this ruby version using gem list cerebrum. It may be installed in your jruby that's why it didn't throw error.

cannot load such file -- rubygems.rb (LoadError)

I'm new to ruby. I removed ruby 1.9 with sudo apt-get purge ruby and then
I installed ruby 2.3.0 using ruby-install. But I got the following error
<internal:gem_prelude>:4:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:4:in `<internal:gem_prelude>
when running rspec my_script.rb.
Still can't fix this after googling! Anyone can help me out?
It seems that the rspec binary was only installed for your previous ruby version. Therefore it is found, but not guaranteed to work.
I'd recommend to use something like rvm (https://rvm.io/) or rbenv (https://github.com/rbenv/rbenv). Both of them can easily handle different ruby versions while maintaining dependencies (e.g. different load paths, different gem versions, etc.). I'd even use rvm if there is only one single ruby version installed on a system.

LoadError when executing ruby code in /etc/rc.d/rc.local

I use CentOS 6.6. I want to execute a Ruby code on startup, so I added the following command to execute the code to /etc/rc.d/rc.local.
ruby /ruby/send_mail.rb
In send_mail.rb, there is require 'mail', but error occurred like the following.
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mail (LoadError)
from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /ruby/send_mail:23:in `<main>'
(I got this error by using ruby /ruby/send_mail.rb &> error_output)
I did gem install mail. And "send_mail.rb" works properly when I run this manually. Would you tell me what I should do?
Try running ruby using the RVM wrappers, as described here:
/usr/local/rvm/wrappers/ruby-2.2.2/ruby /ruby/send_mail.rb

WEBrick CGI handler pointing to wrong gem location

I am trying to execute my CGI program from WEBrick CGIhandler and kept failing with 'loaderror' of gem libraries. Is someone seen following behavior before? How could I get my CGI scripts to search valid gem location?
[Situaltion]
When I ran CGI scripts that requires 'mysql2' library via Webrick server, I got a following error:
ERROR CGIHandler: /home/charles/code/svr/lib/cgitest.rb:
/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mysql2/version (LoadError)
Comment this particular 'require' out from cgitest.rb makes this script work so looks just failed to load this library. Added "puts Gem.path" to the script indicates CGIHandler is looking to following directories to find gem;
["/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1", "/.gem/ruby/1.9.1"]
while actual GEM:HOME and GEM:PATH are following;
["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-p194#global"]
I think I am missing something very simple but could not figure them out. Really appreciate if someone lead me to the right direction. Any input would be highly welcome.
[Environment]
Using RVM to install Ruby 1.9.3 to Ubuntu Server 12.4 with bunch of gems including "mysql2" library. And the script can load 'mysql2' when I run from local.
$which ruby
/home/charles/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
$irb
1.9.3-p194 :001 > Gem.path
=> ["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-
p194#global"]
1.9.3-p194 :002 > require 'mysql2'
=> true
You need to use wrapper instead of bin/ruby:
/home/charles/.rvm/wrappers/ruby-1.9.3-p194/ruby
This will ensure you load proper environment when starting ruby.

OSX Ruby Gems Add to ruby path?

I am just starting to learn ruby. It seems that the default gems install path is not part of Ruby. Is this normal behavior? How can I set the default ruby path? Example:
[11:53:33]wuntee:/Library/Ruby/Gems/1.8/gems/packetfu-1.0.0/examples$ sudo ruby arphood.rb
Fetching the oui.txt from IEEE, it'll be a second. Avoid this with arphood.rb <filename>.
arphood.rb:30:in `require': no such file to load -- packetfu (LoadError)
from arphood.rb:30:in `arp_everyone'
from arphood.rb:51
As you can see packetfu is installed in /Library/Ruby/Gems/1.8/gems/, but ruby cant find it...
that's because you're not in the directory where packetfu.rb file lies and there's no require 'rubygems' to add the gems paths in your script

Resources