Quiz 2
Registry Synced

Package Management

652 words
3 min read

Reading compass

Now · 🎯 Learning Objectives

Package Management

🎯 Learning Objectives

  • Install/update/remove packages with apt
  • Manage Python packages with pip
  • Use conda for data science environments
  • Understand snap packages
  • Build software from source

1. apt — Debian/Ubuntu Package Manager

bash
# Update package index (always do this first!)
sudo apt update
# Upgrade all packages
sudo apt upgrade
# Install packages
sudo apt install nginx
sudo apt install python3 python3-pip git curl
# Remove packages
sudo apt remove nginx              # Remove (keep config files)
sudo apt purge nginx               # Remove completely (incl. config)
sudo apt autoremove                # Remove unused dependencies
# Search for packages
apt search "web server"
apt show nginx                     # Show package details
# List installed packages
apt list --installed
apt list --installed | grep python

2. pip — Python Package Manager

bash
# Install packages
pip install flask
pip install flask==2.0.1          # Specific version
pip install 'flask>=2.0'          # Minimum version
pip install -r requirements.txt    # From file
# List installed
pip list
pip list --outdated                # Show outdated packages
# Update packages
pip install --upgrade pip
pip install --upgrade flask
# Remove
pip uninstall flask
# Virtual environments (recommended)
python -m venv venv                # Create environment
source venv/bin/activate           # Activate (Linux/Mac)
venv\Scripts\activate              # Activate (Windows)
pip install -r requirements.txt    # Install in environment
deactivate                         # Exit environment

3. Conda — Data Science Package Manager

bash
# Create environment
conda create -n myenv python=3.10
conda create -n tf-env tensorflow
# Activate/deactivate
conda activate myenv
conda deactivate
# Install packages
conda install numpy pandas matplotlib
conda install -c conda-forge scikit-learn
# List environments
conda env list
conda list                         # Packages in current env
# Export environment
conda env export > environment.yml
# Create from file
conda env create -f environment.yml
# Remove environment
conda remove -n myenv --all

4. Practice Questions

Q1: What does sudo apt update do?
Answer: Updates the package index from repositories. It downloads the latest package lists but doesn't install/upgrade anything. Run this before apt upgrade or apt install. Q2: What's the difference between apt remove and apt purge?
Answer: apt remove uninstalls the package but leaves configuration files in /etc. apt purge removes everything including config files. Use purge when you want a completely clean removal. Q3: Why use Python virtual environments?
Answer: Isolate project dependencies. Different projects can have different versions of the same package without conflicts. Prevents "works on my machine" problems. Standard practice for Python development. Q4: What does pip freeze do?
Answer: Outputs installed packages in requirements.txt format: pip freeze > requirements.txt. This creates a snapshot of dependencies that can be installed elsewhere with pip install -r requirements.txt. Q5: How do you search for a package in Ubuntu repositories?
Answer: apt search keyword or apt-cache search keyword. Shows matching package names and short descriptions. Q6: What is the difference between pip and conda?
Answer: pip installs Python packages from PyPI. Conda is a cross-platform package manager that can install packages in any language (Python, R, C++). Conda also manages non-Python dependencies (like CUDA, BLAS libraries) and creates isolated environments natively. Q7: How do you install a specific version of a package with pip?
Answer: pip install package==1.2.3 or pip install 'package>=1.0,<2.0'. Version specifiers: == (exact), >= (minimum), <= (maximum), ~= (compatible release). Q8: What does a requirements.txt file look like?
Answer:
pseudo
flask==2.0.1
requests>=2.25
numpy~=1.21
gunicorn
Each line is a package with optional version specification. Created via pip freeze > requirements.txt.

📐 Key Concepts

ManagerScopeKey Commands
aptSystem packages (Ubuntu/Debian)install, remove, update
pipPython packages (PyPI)install, list, freeze
condaMulti-language environmentscreate, install, activate
snapUniversal Linux packagesinstall, remove, list

🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.