Running the command sudo -u www-data composer install results in an error message, showing that the directory /home/dev/.composer is not writable. dev is user which called the command.

Why does composer use the home directory of dev and not www-data?

  • 1
    Would you settle for ‘‘some answer‘‘, or do you want one specific to your situation?    :-)    ⁠ Oct 31 '17 at 0:16
  • I want to understand why composer does not use /home/www-data/.composer
    – S. Denis
    Oct 31 '17 at 10:54

You are looking for the -H option.

From the man page:

    The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.

In your comment you specified that you want to know why this happens. The answer is that sudo has many compile-time options. Since you did not specify which distribution you are running, I'm going to assume your distribution has set the option to preserve the $HOME environment variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.