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.