14

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?

pomsky
  • 67,112
  • 21
  • 233
  • 243
Akash Raju M
  • 179
  • 1
  • 6
  • 3
    Related, on running `pip` as root: [Is \`sudo pip install\` still a broken practice?](https://askubuntu.com/q/802544), [How to set up and use a virtual python environment in Ubuntu?](https://askubuntu.com/q/244641) See also [pipenv](https://github.com/pypa/pipenv). More broadly related, on `sudo` and `-H`: [Why should users never use normal sudo to start graphical applications?](https://askubuntu.com/q/270006), [What specific bad things happen when gedit is used with sudo?](https://askubuntu.com/q/632798), [How does sudo handle $HOME differently since 19.10?](https://askubuntu.com/q/1186999) – Eliah Kagan Jan 27 '20 at 19:24

1 Answers1

30

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.

pomsky
  • 67,112
  • 21
  • 233
  • 243