1

I've VM with the following composer.json file in /vagrant:

{
    "require": {
        "drush/drush": "dev-master"
    }
}

then when I run composer update in that folder, it's downloading the requirements but to /vagrant/vendor, instead of expected local HOME directory as usual (~/.composer/vendor).

Is there any reason why and how to fix that?

I'm using:

Composer version 1.0-dev (15face5432d7b7334db6ac69fac0190971cafa6e) 2015-09-23 17:46:25

on Ubuntu 15.04.

2 Answers 2

2

That is how composer works. If you want something added to ~/.composer/vendor, then you should put it in ~/.composer/composer.json. By default, the vendor directory will be placed next to the composer.json file.

You have a couple of options here. The best is probably to just dispense with /vendor/composer.json, and just run composer global require "drush/drush": "dev-master" instead. That will add drush/drush to ~/.composer/composer.json, and install it. You will then have a symlink to the Drush directory in ~/.composer/vendor/bin, which is, I suspect, what you are aiming for.

0
0

As for workaround, to use JSON file which is not in ~/.composer/composer.json, vendor path can be specified in config/vendor-dir, for example:

{
    "config": {
        "vendor-dir": "~/.composer/vendor"
    },
    "require": {
        "drush/drush": "dev-master"
    }
}

which should install drush in ~/.composer/vendor/drush/drush/drush, then appropriate change to PATH variable needs to be done, e.g.

ex +'$s@$@\rexport PATH=\~/.composer/vendor/bin:$PATH@' -cwq ~/.bashrc

To make it global (by running as root), I guess /var/lib/vendor can be used for vendor-dir, and either append the proper path to PATH variable in one of the global files such as /etc/bash.bashrc or /etc/profile, alternatively specify bin-dir in JSON file, for example:

{
    "config": {
        "vendor-dir": "/var/lib/vendor",
        "bin-dir": "/usr/local/bin"
    },
    "require": {
        "drush/drush": "dev-master"
    }
}

which will install drush globally with a minimal headache as /usr/local/bin should be already in the PATH.


Or if you don't want to hardcode the path in JSON file (so it can be shared between different services), there is even much simpler way as suggested by jonhattan, for example:

  • VM way (as root):

    COMPOSER_HOME=/var/lib/composer COMPOSER_BIN_DIR=/usr/local/bin COMPOSER_VENDOR_DIR=/var/lib/composer/vendor composer -nqq install --no-interaction --optimize-autoloader
    
  • Travis CI way:

    COMPOSER_BIN_DIR=~/bin composer -nqq install --no-interaction --optimize-autoloader --prefer-source
    

Instead of install, you can also use update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.