Upgrade Python Linux [updated] < FRESH × 2027 >
conda install python=3.12 # Or create a new environment conda create -n py312 python=3.12 conda activate py312 After upgrading, ensure pip is updated for the new Python version:
cd /tmp wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz tar -xzf Python-3.12.2.tgz cd Python-3.12.2 ./configure --enable-optimizations # Optimizes the binary (slower compile, faster Python) make -j $(nproc) # Use all CPU cores sudo make altinstall # Crucial: use altinstall, NOT install Why altinstall ? It prevents overriding the default python3 binary. It installs as python3.12 specifically. Step 4: Verify Installation python3.12 --version # Output: Python 3.12.2 To use this version, always call python3.12 or create a virtual environment. Method 2: Using pyenv (Best for Multiple Versions) pyenv lets you install and switch between multiple Python versions per-user, without affecting the system. Installation # Install pyenv dependencies (same as Method 1) # Then install pyenv curl https://pyenv.run | bash Add to your ~/.bashrc (or ~/.zshrc ): upgrade python linux
Upgrading Python on Linux can be approached in several ways, depending on your Linux distribution, whether you want to replace the system Python, and your need for multiple Python versions. This guide covers the safest and most common methods. Important Warning: Don't Replace the System Python Most modern Linux distributions (Ubuntu, Debian, Fedora, CentOS, etc.) rely on their default Python installation for critical system tools like apt , yum , and gnome-terminal . conda install python=3
export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init -)" Restart your shell. # List available Python versions pyenv install --list Install a specific version pyenv install 3.12.2 Set global (user-wide) Python version pyenv global 3.12.2 Set local (project-specific) version pyenv local 3.12.2 Verify python --version Step 4: Verify Installation python3
pyenv automatically manages python and pip to point to your chosen version without touching system Python. Ubuntu / Debian (via deadsnakes PPA) sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install python3.12 python3.12-venv python3.12-dev Usage: python3.12 Fedora sudo dnf install python3.12 Usage: python3.12 Arch Linux sudo pacman -S python Arch is rolling-release, so python is usually up-to-date. Method 4: Using Conda (Data Science Focus) If you use Anaconda or Miniconda: