Running installer within sudobash script installs to /root/.pyenv?
I am creating a provisioning script that has to be ran with sudo, but when I do .pyenv ends up under the /root directory. How do I fix this? I don't see any documentation or recommendations online.
sudo provision.sh
sudo -E -u "$SUDO_USER" curl https://pyenv.run | bash
I'm guessing all I can do is run sudo -E -u provision.sh instead?
Sudo runs commands as root. So yes, the default installation path, ~/.pyenv, would resolve to /root/.pyenv.
You can overide that by manually setting the PYENV_ROOT envvar -- but the created dirs and files will still probably be owned by root.
If you want to install Pyenv not system-wide but for a specific non-root user -- why are you running the installation as root?
AFAIK, if you are root, you can run a command as any other user with runuser -u <user> -- <command line>
Sudo runs commands as root. So yes, the default installation path,
~/.pyenv, would resolve to/root/.pyenv.You can overide that by manually setting the
PYENV_ROOTenvvar -- but the created dirs and files will still probably be owned by root.If you want to install Pyenv not system-wide but for a specific non-root user -- why are you running the installation as root?
Like I said, I'm making a provisioning script that's setting up my entire OS in one shot. This is just a single step in the script. You can definitely prevent root with sudo -u "$SUDO_USER", I'm doing it for a number of things. It's the fact it's running the external installer file, or something, that's messing with it here.
AFAIK, if you are root, you can run a command as any other user with
runuser -u <user> -- <command line>
Thanks, this sounds dig worthy. Checking it out.