Python Installation, Ubuntu


0:00
0:00

Installing Python 3.10+ on Ubuntu/Debian.


Shell Script: Install Python 3.10+ on Ubuntu/Debian

NOTE: This is for 3.10+, but the version can be for Python 3.11 or 3.12

#!/bin/bash

set -e  # Exit immediately if a command exits with a non-zero status

echo "🔄 Updating system packages..."
sudo apt update
sudo apt upgrade -y

echo "📦 Installing required dependencies..."
sudo apt install -y software-properties-common build-essential curl wget

echo "➕ Adding Deadsnakes PPA for newer Python versions..."
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update

echo "🐍 Installing Python 3.10 and dev tools..."
sudo apt install -y python3.10 python3.10-venv python3.10-dev

echo "✅ Verifying Python installation..."
python3.10 --version

echo "📥 Downloading get-pip.py..."
curl -O https://bootstrap.pypa.io/get-pip.py

echo "📦 Installing pip for Python 3.10..."
python3.10 get-pip.py
rm get-pip.py

echo "✅ Verifying pip installation..."
python3.10 -m pip --version

# Optional: Set default 'python3' and 'pip3' to Python 3.10 versions
# echo "🔗 Setting python3 and pip3 to point to Python 3.10 (optional)..."
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# sudo update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.10 1

echo "🎉 Python 3.10+ and pip installation complete!"

📝 Usage Instructions

  1. Save the script Save the above content to a file, e.g., install_python.sh.

  2. Make it executable

    chmod +x install_python.sh
    
  3. Run the script with sudo

    sudo ./install_python.sh
    

⚠️ Notes & Best Practices

  • Virtual Environments: After installation, create isolated project environments with:

    python3.10 -m venv myenv
    source myenv/bin/activate
    
  • Don't override python3 globally unless needed Avoid changing system default unless you're sure. Use python3.10 and pip3.10 explicitly.

  • For Python 3.11+ Replace python3.10 with python3.11 (if supported by deadsnakes).


Last updated on August 15, 2025

🔍 Explore More Topics

Discover related content that might interest you

TwoAnswers Logo

Providing innovative solutions and exceptional experiences. Building the future.

© 2025 TwoAnswers.com. All rights reserved.

Made with by the TwoAnswers.com team