Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

php - 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>AppDataRoamingComposer 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...