问题描述
我对作为可执行文件安装在 /usr 中的编程工具 composer 有疑问/local/bin/composer
在我在工作和家庭之间使用的 3 台不同的机器上.根据:
作曲家帮助全局
<块引用>
COMPOSER_HOME 在 Windows 上是 c:UsersAppDataRoamingComposer和/home//.composer 在 unix 系统上.注意:此路径可能因对 bin-dir 的自定义而异composer.json 或环境变量 COMPOSER_BIN_DIR.
但是这两个都是空的:
echo $COMPOSER_HOME回声 $COMPOSER_BIN_DIR
当我跑步时:
composer 全局要求 <package>
它会安装到我的 Ubuntu 16.04 桌面上的 /home/<user>/.config/composer/vendor/bin
only,但它会适当地安装到其他任何地方/home/<user>/.composer/vendor/bin
为什么它安装到 ~/.config
而不是 ~/.composer
而没有设置 COMPOSER_HOME
变量?
我注意到这一点是因为我获取了包含全局作曲家 bin 路径的常用点文件.我知道我可以通过在我的 bashrc 中手动设置 COMPOSER_HOME
来解决这个问题,但我宁愿首先理解为什么会发生这种情况.
源代码揭示了 Composer 主目录计算方式的一些额外复杂性.
如果您的系统使用 freedesktop.org 标准,它通过查找 环境变量以 XDG_
开头,然后 Composer 使用 $XDG_CONFIG_HOME/composer/
,回退到 $HOME/.config/composer/
如果没有设置.
您可能有兴趣看到有一个 特殊情况:如果 $HOME/.composer/
存在并且是一个目录,它将用于支持 freedesktop.org 逻辑.大概这是为了向后兼容.如果您手动创建此目录,Composer 应该会使用它.
我不确定为什么这只会影响您的 Ubuntu 16.04 机器.我运行 Ubuntu 14.04 变体的旧笔记本电脑使用 XDG_
环境变量.
我怀疑您是在 freedesktop.org 逻辑 之后首次在该计算机上安装 Composer在 2015 年 7 月添加,并且您的其他机器在此之前都首先安装了 Composer.然后他们现有的 ~/.composer/
目录将确保 Composer 继续使用该位置.
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.
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.
这篇关于为什么 COMPOSER_HOME 是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!