Gracefully installing global Composer libraries
Recently, I happened to install the Laravel Envoy library in my Linux-powered machine. Now, if you don’t know, Envoy is a task runner that can be used to define and run common tasks on your remote (and local) servers. You can set up tasks for your application deployment such as Git commands, artisan commands, and a lot of other CLI-based things.
Now, coming to the issue I faced. To use Envoy, you’d need to install it globally using Composer using the
global require like so.
$ composer global require laravel/envoy
I ran the above command and I got the following error and the installation got terminated.
Essentially, the error is saying that the intended version of Envoy that we’re installing is dependent on another library called
symfony/console which needs to be installed first.
So, I tried to install the required version of
symfony/console as suggested in the error message but then again I ran into another dependency-related error. And this is where this library called consolidation\cgr came to my rescue.
In a nutshell,
cgr(named after “composer global require”) is a drop-in replacement for the
composer global require command which can be used for installing PHP command line tools globally that is functionally equivalent (nearly) to the existing command, but much safer. It solves the dependency related issues while installing packages/libraries globally.
cgr, run the following command.
$ composer global require consolidation/cgr
Once installed, I tried to install the Laravel Envoy using
cgr like so.
$ cgr laravel/envoy
And boom! it successfully/gracefully installed it without any sort of dependency related issues. And as a bonus, I didn’t have to put
$HOME/.composer/vendor/bin to make the
envoy command work in the terminal and that is also managed by
This is one example but you should consider using
cgr if you happen to install Composer libraries globally for painless installations.
You can learn more about
consolidation/cgr at its official documentation.