title: How do I get a Ruby CGI program that requires a gem to run properly?
body: <p>I have configured my Apache installation to run Ruby CGI scripts. I am now trying to run a simple Ruby CGI script that requires a gem.</p>
  
  <p>When I run this script from the command line, it outputs correctly. But when I call it as an Apache CGI script, it generates an Apache <strong>Internal Server Error</strong>. The script looks like this:</p>
  
  <pre><code>#!/Ruby/bin/ruby
  
  require 'RedCloth'  # &lt;-- This is the gem
  
  puts "Content-type: text/html"
  puts 
  puts
  puts "&lt;html&gt;"
  puts "&lt;head&gt;"
  puts "&lt;/head&gt;"
  puts "&lt;body&gt;"
  puts "I want to call a gem."
  puts "&lt;/body&gt;"
  puts "&lt;/html&gt;"
  </code></pre>
  
  <p>The Apache error log shows these lines:</p>
  
  <pre><code>C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:56:in `join': can't convert nil into String (TypeError)
  [error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:56:in `&lt;class:ConfigFile&gt;'
  [error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems/config_file.rb:28:in `&lt;top (required)&gt;'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
  [error] [client 127.0.0.1] \tfrom C:/Ruby/lib/ruby/1.9.1/rubygems.rb:1110:in `&lt;top (required)&gt;'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
  [error] [client 127.0.0.1] \tfrom &lt;internal:gem_prelude&gt;:167:in `load_full_rubygems_library'
  [error] [client 127.0.0.1] \tfrom &lt;internal:gem_prelude&gt;:217:in `try_activate'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:32:in `rescue in require'
  [error] [client 127.0.0.1] \tfrom &lt;internal:lib/rubygems/custom_require&gt;:29:in `require'
  [error] [client 127.0.0.1] \tfrom C:/Apache/Apache2.2/cgi-bin/cgitest.rb:3:in `&lt;main&gt;'
  </code></pre>
  
  <p></p>
  
  <p>When I don't include the <code>require 'RedCloth'</code> line, Apache executes my cgi script just fine. </p>
  
  <p>Is there someting obvious that I'm missing here? Can you, in fact, even execute a Ruby CGI script that requires a gem? Any insights would be greatly appreciated.</p>
  
  <p>Thanks,
  Maurice</p>