Take PHPUnit as an example. You can install it using Composer doing this :
composer require phpunit/phpunit
This will install a phpunit shortcut in vendor/bin directory. This obviously means you can run it. But, you would have to point to the exact location of the phpunit file to run :
But, that’s long and uncomfortable. And you would have to install PHPUnit separately for each projects.
I’m gonna tell you how to install binaries globally as well as running it simply.
Install Packages Globally
Same command, but add a “global” before “require” :
composer global require phpunit/phpunit
If you’re using Linux, this will install PHPUnit to :
This will also create the phpunit binary shortcut in vendor/bin directory.
Use It Simply
Now, let’s add the location so that we can use it like this in terminal :
For this, you simply enter this into your terminal session :
But this (^) is only temporary and will fade away when the terminal is closed.
To make it permanent, open any of the following files using your text editor :
Then, add the command we used before at the end of the file :
I added the link to this post, because in the future if you open this file, you shouldn’t confuse yourself. You should close all running terminals and re open before you test it out.
Now, you can use any binary shortcuts in “/home/username/.config/composer/vendor/bin” by simply typing it on your terminal. Also, make sure the Linux native programs doesn’t conflict with the file names of Composer binaries.