Run Vendor Binaries w/o Typing vendor/bin


In this tutorial I will explain how to execute composer vendor binaries without typing vendor/bin every time.

Vendor binaries are command line scripts come with the composer packages you install. Some vendor binary examples are PHPUnit, Behat, PHPSpec, Doctrine. I will use Behat in the tutorial.

Normally when Behat is required a symlink is created in vendor/bin. To execute it you need to type the relative path of the Behat executable (vendor/bin/behat).

What I want to do is type behat instead. To achive this all you need to do is to add vendor/bin into your PATH:

export PATH="$PATH:vendor/bin"

To avoid typing this every time you log in to the command line you need to add it to your .bash_profile. Here is the change on mine:

--- a/.bash_profile Sun Sep 7 00:37:30 2014
+++ b/.bash_profile Sun Sep 7 00:37:35 2014
@@ -7,6 +7,6 @@

# User specific environment and startup programs


export PATH

Now when you type behat your shell will find Behat executable in vendor/bin directory.

Note 1: You will be able to execute behat only when your current working directory (cwd) is project root.

Note 2: If you have another behat in a directory that has higher precedence (e.g /usr/bin) that will be executed instead.


One thought on “Run Vendor Binaries w/o Typing vendor/bin

  1. Thanks for the tip, it was what I was loooking for, didn’t know you can add relative paths into the path.

    However, I don’t know why this was working before in same machine same user, I have build logs where it got the scripts and executed.


Leave a Reply

Your email address will not be published. Required fields are marked *