Where to find composer's global packages?

PhpSublimetext2Composer PhpSublimetext

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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 put the files.

Solution 2 - Php

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

Solution 3 - Php

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

Solution 4 - Php

Ubuntu 20.04:

~/.config/composer/vendor

Solution 5 - Php

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

Solution 6 - Php

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"

Solution 7 - Php

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

Solution 8 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeterView Question on Stackoverflow
Solution 1 - PhpAlister BulmanView Answer on Stackoverflow
Solution 2 - PhpglenView Answer on Stackoverflow
Solution 3 - PhpJay SoniView Answer on Stackoverflow
Solution 4 - PhpOstap BrehinView Answer on Stackoverflow
Solution 5 - PhpMadan SapkotaView Answer on Stackoverflow
Solution 6 - PhpAliesView Answer on Stackoverflow
Solution 7 - PhpTaylor EvansonView Answer on Stackoverflow
Solution 8 - PhpEren SertkayaView Answer on Stackoverflow