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

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

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.

How to fix cannot load such file -- Nokogiri (LoadError) in c9.io?

I'm using Cloud9 IO for Ruby.
I ran bundle install.
Even installed the gems.
But I'm still getting this error.
scarletmclearn:~/workspace/nokogiri_tutorial (master) $ ruby
web_scraper.rb
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
require': cannot load such file -- Nokogiri (LoadError)
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
require'
from web_scraper.rb:1:in `'
Do check out my Repository : https://github.com/ScarletMcLearn/ruby_ws_1/tree/master/workspace
a beginner here, so simple instructions on which file or what to change will help.
Thanks for the read!
from your command prompt install nokogiri by running
gem install nokogiri

FCGI Ruby Gem not found when using apache

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.

ruby test-unit test runner isnt running

I am attempting to make a custom test runner using test/unit in ruby
and have followed a tutorial outlined here
http://endofline.wordpress.com/2008/02/11/a-custom-testrunner-to-scratch-an-itch/
however when i try to run on it using the
ruby -rfast_fail_runner example_test.rb --runner fastfail
however i get the error
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- fast_fail_runner (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
You have a file in the current directory named fast_fail_runner.rb, right? Ruby is not finding it. You are following a very old tutorial and I suspect that old versions of Ruby had the current directory (.) on the load path or something like that.
Try replacing -rfast_fail_runner with -r./fast_fail_runner.

I cant load Ruby Gems

i am getting this error whenever i try to load a ruby gem
/home/hilarl/.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 -- twit
ter (LoadError)
from /home/hilarl/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from sample.rb:2:in `<main>'
can you please help?
You missed to use a ruby, in normal console first run:
rvm use 1.9.3
If it's in a script then instead use following path to ruby:
$rvm_path/wrappers/ruby-1.9.3-p194/ruby
You should get also the minimal basics of using RVM:
screencast: http://screencasts.org/episodes/how-to-use-rvm
cheatsheet: http://cheat.errtheblog.com/s/rvm/
rvm site: https://rvm.io/

Resources