Skip to content

Instantly share code, notes, and snippets.

@iklobato
Last active January 12, 2024 01:46
Show Gist options
  • Save iklobato/00024ea81085b4c996fc2bf31def7617 to your computer and use it in GitHub Desktop.
Save iklobato/00024ea81085b4c996fc2bf31def7617 to your computer and use it in GitHub Desktop.
pyenv linux install
#!/bin/bash
#
# Pyenv Installer Script
#
# This script automates the installation of Pyenv and the latest Python versions
# on a Debian-based system or macOS. It installs necessary dependencies, sets up Pyenv,
# restarts the terminal, and installs the latest Python versions concurrently.
#
# Note: Ensure you have sudo privileges to install system dependencies.
#
# For more information on Pyenv, visit https://github.com/pyenv/pyenv
#
# Created by Henrique Lobato
# Date: Jan 11, 2024
#
# Detect operating system
if [[ "$(uname)" == "Darwin" ]]; then
# macOS
echo "Detected macOS. Installing dependencies using Homebrew..."
brew install openssl readline sqlite3 xz zlib
else
# Debian-based systems
echo "Detected Debian-based system. Installing dependencies using apt-get..."
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
fi
# Install pyenv
echo "Installing pyenv..."
curl -fsSL https://pyenv.run | bash
# Restart the terminal
echo "Restarting the terminal..."
exec "$SHELL" &
# Define Python versions
latest_versions=()
for version in "3.8" "3.9" "3.12"; do
latest_versions+=($(pyenv install --list | grep -E "^\s*$version" | grep -v "[a-z]" | tail -n 1))
done
# Install dependencies and Python versions concurrently
(
# Install dependencies in the background
for version in "${latest_versions[@]}"; do
if [ -n "$version" ]; then
echo "Installing Python $version..."
pyenv install "$version" &
fi
done
# Wait for background processes to finish
wait
# Display installed Python versions
echo "Installed Python versions:"
pyenv versions
) &
@iklobato
Copy link
Author

iklobato commented Jan 12, 2024

Oneliner installation

bash -c "$(curl -fsSL https://gist.githubusercontent.com/henriqueblobato/00024ea81085b4c996fc2bf31def7617/raw/983964f10546fee2586e7a09157da17ecabf5d34/pyenv_install.sh)"

Screenshot 2024-01-11 at 22 34 43

[ ... ]

Screenshot 2024-01-11 at 22 45 40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment