How to fix composer global modules that don’t work

When trying to add the Laravel installer to composer global I would use the following to add the installer module globally.

composer global require laravel/installer

However when I tried to run laravel the command wasn’t working.

─ laravel new laravel
zsh: command not found: laravel

The reason for global modules not working when you run the commands is that the directory for the global composer modules isn’t added to the main PATH variable so it’s not available.

Run the following command to get the correct path for the composer global modules.

composer global config bin-dir --absolute

For me the returned path was the following.

/home/mesh/.config/composer/vendor/bin

The above directory needs to be added to the main PATH variable like so.

PATH="$HOME/.config/composer/vendor/bin:$PATH"

After updating the PATH the laravel command worked after running it.