Lab 10.1 - Installation and Use of apt
Lab Objectives
By the end of this lab, you will be able to:
- Use apt to install packages
- Update the Ubuntu 24.04 system
- Manage repositories
- Resolve dependency issues
- Search for and obtain information about packages
Estimated Duration
30-45 minutes
Prerequisites
- Ubuntu 24.04 installed and operational
- Sudo access
- Internet connection
- Open terminal
Exercise 1: System Update
Step 1: Update the Package List
# Update the list of available packages
sudo apt update
# See packages to be upgraded
apt list --upgradable
Step 2: Upgrade Packages
# Upgrade all installed packages
sudo apt upgrade
# Full upgrade (includes dependency changes)
sudo apt full-upgrade
# Upgrade without confirmation
sudo apt upgrade -y
Step 3: Verify Updates
# See packages to be upgraded
apt list --upgradable
# See update information
apt show package-name
Exercise 2: Package Installation
Step 1: Simple Installation
# Install a package
sudo apt install htop
# Install multiple packages
sudo apt install vim git curl
# Install without confirmation
sudo apt install -y package-name
Step 2: Specific Version Installation
# See available versions
apt-cache madison package-name
# Install a specific version
sudo apt install package-name=version
# Example
sudo apt install nginx=1.18.0-0ubuntu1.4
Step 3: Installation from .deb File
# Download a .deb
wget https://example.com/package.deb
# Install
sudo apt install ./package.deb
# Or with dpkg
sudo dpkg -i package.deb
sudo apt install -f # Resolve dependencies
Exercise 3: Search and Information
Step 1: Search for Packages
# Search by name
apt search nginx
# Search by description
apt search "web server"
# Exact search
apt search --names-only nginx
Step 2: Package Information
# Detailed information
apt show nginx
# Dependencies
apt depends nginx
# Packages depending on nginx
apt rdepends nginx
# Content of a package
dpkg -L nginx
Step 3: Package List
# Installed packages
apt list --installed
# Available packages
apt list --available
# Packages to be upgraded
apt list --upgradable
Exercise 4: Repository Management
Step 1: View Repositories
# View sources
cat /etc/apt/sources.list
# View additional sources
ls /etc/apt/sources.list.d/
# View all sources
cat /etc/apt/sources.list.d/*.list
Step 2: Add a Repository
# Method 1: File in sources.list.d/
echo "deb http://repo.example.com/ubuntu noble main" | \
sudo tee /etc/apt/sources.list.d/my-repo.list
# Add the GPG key
wget -qO - http://repo.example.com/key.gpg | sudo apt-key add -
# Update
sudo apt update
Step 3: PPA Repository (Ubuntu)
# Add a PPA
sudo add-apt-repository ppa:name/ppa
# Remove a PPA
sudo add-apt-repository --remove ppa:name/ppa
# Update
sudo apt update
Exercise 5: Removal and Cleaning
Step 1: Remove Packages
# Remove a package (keeps config)
sudo apt remove package-name
# Remove package and configuration
sudo apt purge package-name
# Remove multiple packages
sudo apt remove package1 package2 package3
Step 2: Cleaning
# Remove unused dependencies
sudo apt autoremove
# Clean the cache
sudo apt clean
# Automatic cleaning
sudo apt autoclean
# Clean everything
sudo apt autoremove -y
sudo apt autoclean
Exercise 6: Troubleshooting
Step 1: Broken Dependencies
# Repair dependencies
sudo apt --fix-broken install
# Fully repair
sudo apt --fix-missing install
sudo dpkg --configure -a
Step 2: Corrupted Cache
# Clean the cache
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*
# Rebuild the cache
sudo apt update
Step 3: Locked Package
# See processes using a package
sudo lsof | grep package-name
# Force reinstallation
sudo apt install --reinstall package-name
Exercise 7: Complete Practice
Step 1: Web Server Installation
# Install nginx
sudo apt update
sudo apt install -y nginx
# Verify installation
systemctl status nginx
nginx -v
# See installed files
dpkg -L nginx | head -20
Step 2: System Update
# Full update script
cat > update-system.sh << 'EOF'
#!/bin/bash
echo "Updating package list..."
sudo apt update
echo "Upgrading packages..."
sudo apt upgrade -y
echo "Cleaning..."
sudo apt autoremove -y
sudo apt autoclean
echo "Done!"
EOF
chmod +x update-system.sh
./update-system.sh
Verification
Checklist
Verify that you can:
- Update the system (apt update, upgrade)
- Install packages (apt install)
- Search for packages (apt search)
- View information (apt show)
- Manage repositories
- Remove packages (apt remove, purge)
- Clean the system (autoremove, clean)
- Resolve dependency issues
Reflection Questions
-
What is the difference between apt update and apt upgrade?
- update: Updates the list of available packages
- upgrade: Upgrades installed packages
-
Why use apt autoremove?
- Removes unused dependencies
- Frees up disk space
-
When to use apt purge vs apt remove?
- remove: Removes the package, keeps config
- purge: Removes the package and config
Next Steps
- Lab 10.2: Repository Management
- Lab 10.3: Compilation from Sources
- Lab 10.4: Snap and Flatpak
- Chapter 10.1: apt (Debian/Ubuntu)
Ubuntu 24.04 Resources
- Ubuntu Packages
man apt- apt Documentationapt-cache search- Advanced search
Lab created on: December 2024 - Tested on Ubuntu 24.04