Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CodeBradley opened this issue Dec 15, 2024 · 3 comments
Open

Comments

@CodeBradley
Copy link

CodeBradley commented Dec 15, 2024

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?

@native-api
Copy link
Member

native-api commented Dec 15, 2024

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
Copy link
Member

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

@CodeBradley
Copy link
Author

CodeBradley commented Dec 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants