title: How to configure a composer package to be globally installed?
body: <p>I'm trying to make a little CLI tool and package it up with composer.</p>
  <p>Below is an extremely simplified version of the program, but it's enough to demonstrate the problem I'm encountering.</p>
  <p>The project has one dependency, and one &quot;binary&quot; file</p>
  <p><strong>composer.json</strong></p>
  <pre class="lang-js prettyprint-override"><code>{
    &quot;name&quot;: &quot;alice/yamldump&quot;,
    &quot;version&quot;: &quot;0.2.0&quot;,
    &quot;bin&quot;: [
      &quot;bin/yamldump&quot;
    ],
    &quot;require&quot;: {
      &quot;symfony/yaml&quot;: &quot;2.5.3&quot;
    }
  }
  </code></pre>
  <p><strong>bin/yamldump</strong></p>
  <pre><code>#!/usr/bin/env php
  &lt;?php
  
  // use Yaml namespace
  use Symfony\Component\Yaml as Yaml;
  
  // autoload
  require_once &quot;vendor/autoload.php&quot;;
  
  // read yaml
  $yaml = file_get_contents(sprintf(&quot;%s/%s&quot;, getcwd(), $argv[1]));
  
  // create parser
  $parser = new Yaml\Parser();
  
  // parse the yaml
  var_dump($parser-&gt;parse($yaml));
  </code></pre>
  <hr />
  <p>So when I install it globally, I get this</p>
  <pre><code>$ composer global require alice/yamldump=dev-master
  </code></pre>
  <p>Files are installed to</p>
  <ul>
  <li><code>~/.composer/vendor/bin/yamldump -&gt; ../alice/yamldump/bin/yamldump</code></li>
  <li><code>~/.composer/vendor/alice/yamldump/</code></li>
  <li><code>~/.composer/vendor/symfony/yaml/</code></li>
  </ul>
  <p>This is a problem, because I did not intend to globally install <code>symfony/yaml</code> <strong>and</strong> my package's <code>vendor/autoload.php</code> can no longer find the Yaml package in the proper location.</p>
  <p>I don't <em>mind</em> that <code>symfony/yaml</code> was installed globally, but it would make sense to me that <code>composer global require</code> would install the package like this:</p>
  <ul>
  <li><code>~/.composer/vendor/bin/yamldump -&gt; ../alice/yamldump/bin/yamldump</code></li>
  <li><code>~/.composer/vendor/alice/yamldump/</code></li>
  <li><code>~/.composer/vendor/alice/yamldump/vendor/symfony/yaml/</code></li>
  </ul>
  <p>After all, what if I have <code>Package A</code> that depends on <code>symfony/yaml=2.5.3</code> and <code>Package B</code> that requires <code>symfony/yaml=2.6.x</code>?</p>
  <p>If the <code>composer global require</code> installs dependencies to <code>~/.composer/vendor/*</code>, each globally required package can't maintain it's own version requirement of its dependency...</p>
  <p>I know this is sort of a convoluted problem, but I really don't know how to begin fixing it.</p>
  <hr />
  <p><strong>The goal</strong></p>
  <p>A user should be able to</p>
  <pre><code>$ composer global require alice/yamldump=dev-master
  $ yamldump sample.yml
  </code></pre>
  <p><strong>The error</strong></p>
  <pre class="lang-none prettyprint-override"><code>$ yamldump sample.yml
  Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
  
  Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:') in /Users/alice/.composer/vendor/alice/yamldump/bin/yamldump on line 8
  </code></pre>
  <p><strong>The question</strong></p>
  <p>Here it is in black &amp; white:</p>
  <p><strong>How am I intended to write the <code>require &quot;vendor/autoload.php&quot;</code> line and have it work for both locally installed packages and globally installed packages?</strong></p>