pyenv-installer icon indicating copy to clipboard operation
pyenv-installer copied to clipboard

Running installer within sudobash script installs to /root/.pyenv?

Open CodeBradley opened this issue 1 year ago • 3 comments

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?

CodeBradley avatar Dec 15 '24 08:12 CodeBradley

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?

native-api avatar Dec 15 '24 08:12 native-api

AFAIK, if you are root, you can run a command as any other user with runuser -u <user> -- <command line>

native-api avatar Dec 15 '24 08:12 native-api

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?

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.

CodeBradley avatar Dec 15 '24 09:12 CodeBradley