Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is COMPOSER_HOME empty?

I have a question about the programming tool composer which is installed as an executable in /usr/local/bin/composer on 3 different machines that I use between work and home. According to:

composer help global
COMPOSER_HOME is c:\Users<user>\AppData\Roaming\Composer on Windows
and /home/<user>/.composer on unix systems.

Note: This path may vary depending on customizations to bin-dir in
composer.json or the environmental variable COMPOSER_BIN_DIR.

But both of these are empty:

echo $COMPOSER_HOME
echo $COMPOSER_BIN_DIR

When I run:

composer global require <package>

It installs to /home/<user>/.config/composer/vendor/bin only on my Ubuntu 16.04 desktop, but everywhere else it installs appropriately to /home/<user>/.composer/vendor/bin

Why is it installing to ~/.config instead of ~/.composer and not setting the COMPOSER_HOME variable?

I notice this because I source my common dotfiles which includes the global composer bin path. I know I can workaround this by manually setting COMPOSER_HOME in my bashrc, but I would rather understand why this is happening in the first place.

like image 834
Jeff Puckett Avatar asked Aug 01 '16 16:08

Jeff Puckett


1 Answers

The source code reveals some additional complexity to how Composer's home directory is computed.

If your system uses freedesktop.org standards, which it detects by looking for environment variables beginning with XDG_, then Composer uses $XDG_CONFIG_HOME/composer/, falling back to $HOME/.config/composer/ if that isn't set.

You might be interested to see that there is a special case: if $HOME/.composer/ exists and is a directory it will be used in favour of the freedesktop.org logic. Presumably this is for backwards compatibility. If you create this directory manually, Composer should use it.

I'm not sure why this is just affecting your Ubuntu 16.04 machine. My old laptop running a variant of Ubuntu 14.04 uses XDG_ environment variables.

I suspect that you installed Composer for the first time on that machine after the freedesktop.org logic was added in July of 2015 and that your other machines all had Composer first installed before then. Then their existing ~/.composer/ directories would ensure that Composer kept using that location.

like image 63
Chris Avatar answered Oct 17 '22 18:10

Chris