ChatGPT解决这个技术问题 Extra ChatGPT

Where to find composer's global packages?

For a plugin for Sublime Text I was required to install a composer package globally.

In order to do this I had to run the following command:

composer global require "asm89/twig-lint" "@stable"

The installation started running and a few seconds later the package was installed. Voila! Well, not really.

Step two was to add some lines to my Sublime Text configuration file:

{
    "user": {
        "paths": {
            "windows": ["C:\\Users\\yourname\\.composer\\vendor\\bin"]
        },
    }
}

However, the plugin is not working. So I decided to check the path. And it appears there is no .composer directory in my profile directory. It isn't in my php directory either. And I can't find it anywhere.

I would like to know if there's a way to locate this directory and would appreciate any suggestions that can help me get this plugin to work.


h
hakre

You can query Composer to find where it has set the user $COMPOSER_HOME directory.

composer config --list --global

The [home] ... line refers to the default value of $COMPOSER_HOME.

The word home can be used as a single parameter as well to show the configuration value.

Example (Windows):

> composer -n config --global home                
C:\Users\<user>\AppData\Roaming\Composer

Example (Linux):

$ composer -n config --global home                
/home/<user>/.composer

Just as a final confirmation - the 'yourname' part in the configuration, would very likely need to be updated with your own Windows username - composer config will say where it puts the files.


About the yourname part. I figured :)
You can just run composer config home.
I believe in this instance it would actually be composer global config home
@EdwardSammutAlessi The global command allows you to run other commands like install, remove, require or update as if you were running them from the COMPOSER_HOME directory. Documentation: Composer. global command
I get /data/.composer but there is no /data/ folder in my Ubuntu install...
g
glen

You can use

composer global config bin-dir --absolute

Example

PATH=$(composer global config bin-dir --absolute --quiet):$PATH

You need --absolute to get value expanded, and --quiet to discard diagnostics of composer global changing working directory. This was tested with composer 1.10.16 and 2.0.1.

See https://github.com/composer/composer/issues/9354#issuecomment-716827067


J
Jay Soni

You may find in ~/.config/composer/vendor/bin


This is the case with my settings in Ubuntu 18
O
Ostap Brehin

Ubuntu 20.04:

~/.config/composer/vendor


This depends on composer version and environment configuration. You can also have it on Ubuntu 18.04 as you show it on Ubuntu 16.04 and vice-versa, even with the latest composer version IIRC.
M
Madan Sapkota

Run the command

composer config --list --global | grep -w home

You can find the find the [home] with composer path, similar to this one.

[home] /home/example_username/.config/composer

Better even not filter with grep but just return from the command directly. I edited the accepted answer to show it, it was also in the comments there.
A
Alies

For composer v2:

composer global config --list

Check the output and find [vendor-dir] parameter. Or use grep:

composer global config --list | grep "vendor-dir"

T
Taylor Evanson

On Windows, mine was /Users/taylor/AppData/Roaming/Composer/bin


E
Eren Sertkaya

~/.config/composer/vendor/bin/laravel adding this to my bashrc file as a alias works on ubuntu 20.04