title: Running a ruby script globally
body: <p>I'm writing a command line application in ruby and want to run it globally in my shell, without having to preface my call with <code>./</code> or with <code>ruby &lt;filepath&gt;</code> - just as I would run <code>git</code>, <code>brew</code> or <code>rails</code>.</p>
  
  <p>The structure of my simple application is as follows: I've got a directory in <code>/Developer</code> folder called <code>rubyPlug</code>. Inside <em>rubyPlug</em> is <em>plug</em> and <em>Formulae.rb</em>. </p>
  
  <p>I'm writing a command line application in ruby and want to run it globally in my shell, without having to preface my call with <code>./</code> or with <code>ruby &lt;filepath&gt;</code> - just as I would run <code>git</code>, <code>brew</code> or <code>rails</code>.</p>
  
  <p>The structure of my simple application is as follows: I've got a directory in <code>/Developer</code> called <code>rubyPlug</code>. Inside <code>rubyPlug</code> is <code>plug</code> and <code>Formulae.rb</code>. <code>Formulae.rb</code> is where all the application specific code is stored. <code>Plug</code> stores some boilerplate startup code: </p>
  
  <pre><code>!/usr/bin/env ruby 
  require  "/Users/theideasmith/Developer/rubyPlug/Formulae.rb"
   begin
     x = Application.new ARGV
   rescue Errno::ENOENT =&gt; err
     abort "plug: #{err.message}"
   end```
  </code></pre>
  
  <p><strong>I want to run my app by typing <code>plug &lt;args&gt;</code>. If I'm storing <code>plug</code> globally, how would I structure my <code>require()</code> call?</strong> </p>
  
  <p>I've included <code>#!/usr/bin/env ruby</code> in <code>plug</code>, ran <code>chmod +x plug</code>, and tried <code>sudo cp plug /usr/bin/plug.</code> My script ran, but failed at the <code>require "/Users/.../Formulae.rb"</code> call. How do I avoid this - do I have to store the parent directory as some sort of package in <code>/usr/bin</code>? I've included <code>#!/usr/bin/env ruby</code> in <code>plug</code>, ran <code>chmod +x plug</code>, and tried <code>sudo cp plug /usr/local/bin/plug</code>. I was then able to type <code>plug &lt;args&gt;</code>, but I then got an error message related to my <code>require</code> call not working. </p>
  
  <p>Any suggestions? </p>