Last active
September 13, 2024 16:45
-
-
Save Brandon7CC/3389c6c3012a3e845c3d12d672084738 to your computer and use it in GitHub Desktop.
Install `pyenv` on Linux in Bash shell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Update package lists | |
sudo apt update | |
# Install dependencies for building Python versions | |
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ | |
libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils \ | |
tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev | |
# Install Pyenv if not already installed | |
if [ ! -d "$HOME/.pyenv" ]; then | |
curl https://pyenv.run | bash | |
fi | |
# Define environment variables in ~/.profile | |
if ! grep -q 'export PYENV_ROOT' ~/.profile; then | |
cat << 'EOF' >> ~/.profile | |
# Pyenv configuration | |
export PYENV_ROOT="$HOME/.pyenv" | |
export PATH="$PYENV_ROOT/bin:$PATH" | |
eval "$(pyenv init --path)" | |
EOF | |
fi | |
# Add Pyenv initialization to ~/.bashrc | |
if ! grep -q 'eval "$(pyenv init -)"' ~/.bashrc; then | |
cat << 'EOF' >> ~/.bashrc | |
# Pyenv initialization | |
eval "$(pyenv init -)" | |
EOF | |
fi | |
# Reload the shell environment | |
source ~/.profile | |
source ~/.bashrc | |
# Verify Pyenv installation | |
pyenv --version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment