Search code examples
phpbashubuntucomposer-phpbehat

composer vendor/bin files not being detected on Ubuntu Terminal


Yesterday I've just installed Laravel with Behat on my VM Ubuntu 15.10. Everything works fine, running the command $ vendor/bin/behat --init successfully created the features/ folder

but today something is weird, when running the $ vendor/bin/behat its saying vendor/bin/behat: line 1: ../behat/behat/bin/behat: No such file or directory

What's inside the vendor/bin/behat file? This first single line ../behat/behat/bin/behat

accessing the actual location works $ vendor/behat/behat/bin/behat which basically means the file DOES exists

Please note that the issue is the same for the files in vendor/bin like doctrine phpspec etc..


Solution

  • You're having relative path problems. If your current directory contains vendor/ and you execute vendor/bin/behat, then ../behat/behat/bin/behat doesn't exist because it's going one directory up from your current directory, not vendor/bin/. For example:

    $ cd $HOME/project
    $ vendor/bin/behat
    vendor/bin/behat: line 1: ../behat/behat/bin/behat: No such file or directory
    

    That relative path becomes $HOME/project/behat/behat/bin/behat and not $HOME/project/vendor/behat/behat/bin/behat (note vendor present in the second path)

    You need to be inside vendor/bin/ when executing behat:

    $ cd $HOME/project/vendor/bin
    $ behat
    ...
    

    However, I don't see this being an issue with the latest behat install, line #1 is a well formed shebang. I think you might want to destroy your vendor install, update composer, etc, and reinstall Behat. Those files should not start with relative paths.

    EDIT:

    According to the composer docs, it creates symlinks to package binaries, as seen in the source code. You can verify this by running ls -l vendor/bin (all symlinks will have a -> pointing to their destination path). It would seem your original php composer.phar require ... was corrupt from the beginning.