What does '-H' flag in 'sudo -H' mean?

When I was installing Python 3 on Ubuntu 18.04, I came across the command

sudo -H pip install -U pip

What does -H do?


Solution 1:

From man sudo:

-H, --set-home
            Request that the security policy set the HOME environment variable 
            to the home directory specified by the target user's password 
            database entry.  Depending on the policy, this may be the default 
            behavior.

So the -H flag makes sudo assume root's home directory as HOME instead of the current user's home directory. Otherwise some files in the user's home directory would become owned by the root, which may lead to various problems.