find composer global install path as root

15,155

Solution 1

The problem, as you can notice in the path difference, is that me's path includes /home/me/.composer/vendor/bin. Sudo does not inherit the user's environment.

You would need to manually import it. It's unclear why you'd want root to see a specific user's files in its path though.

To find a file, you can use the find command such as find /home -name FileName.

Solution 2

Thanks to Julie's suggestion and some other answers on SO I came up with

 path="$(PATH=$PATH:/home/me/.composer/vendor/bin which phpcs)"

which works nicely

Share:
15,155

Related videos on Youtube

myol
Author by

myol

Updated on September 18, 2022

Comments

  • myol
    myol over 1 year

    I have some php packages installed globally using php composer within a script

    sudo -u me composer global require "phpmd/phpmd"
    

    I want to find the path of these globally installed php packages. When I run which phpmd as user me I get the full path.

    /home/me/.composer/vendor/bin/phpcs

    However when I try and run the command as sudo I get nothing. I think this is because composer has been added globally and is in my user mes PATH while it is not present in sudo's PATH.

    Instead I have tried

     path="$(sudo -u me which phpcs)"
    

    But this also fails. However it succeeds for any program not installed through composer. How can I find the globally installed php packages through composer as sudo?

    me's path

    /home/me/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    

    sudo (su's) path

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    
    • Julie Pelletier
      Julie Pelletier about 8 years
      To troubleshoot, please show me's and root's path. That's probably where the problem is.
    • myol
      myol about 8 years
      updated the question @JuliePelletier
  • myol
    myol about 8 years
    Manually import the composer path?