Package Management with APT
What is APT?
APT (Advanced Package Tool) is Debian's package management system. It handles installation, upgrade, and removal of software packages.
Basic Commands
Update Package Lists
sudo apt update
Updates the local package index with the latest changes from repositories.
Upgrade Packages
sudo apt upgrade
Upgrades all installed packages to their latest versions.
Full Upgrade
sudo apt full-upgrade
Performs upgrade and handles changing dependencies.
Install Packages
sudo apt install package_name
Installs a package and its dependencies.
Remove Packages
sudo apt remove package_name
Removes a package but keeps configuration files.
Purge Packages
sudo apt purge package_name
Removes a package and its configuration files.
Search Packages
apt search keyword
Searches for packages containing the keyword.
Show Package Information
apt show package_name
Displays detailed information about a package.
List Installed Packages
apt list --installed
Lists all installed packages.
Check for Upgrades
apt list --upgradable
Shows packages that can be upgraded.
Managing Repositories
Sources List
Located at /etc/apt/sources.list
Example entry:
deb http://deb.debian.org/debian/ bullseye main contrib non-free
Adding Repositories
- Edit
/etc/apt/sources.list - Or create files in
/etc/apt/sources.list.d/ - Add the repository line
- Import GPG keys if required
- Run
sudo apt update
Common Tasks
Install Development Tools
sudo apt install build-essential git curl wget
Install Ruby and Rails Dependencies
sudo apt install ruby ruby-dev zlib1g-dev libssl-dev libreadline-dev
Install Node.js
sudo apt install nodejs npm
Install PostgreSQL
sudo apt install postgresql postgresql-contrib
Install MySQL
sudo apt install mysql-server
Troubleshooting
Fix Broken Packages
sudo apt --fix-broken install
Clean Package Cache
sudo apt autoclean
sudo apt autoremove
Resolve Dependencies
sudo apt install -f
Backports and Testing
Enable Backports
Add to /etc/apt/sources.list:
deb http://deb.debian.org/debian bullseye-backports main contrib non-free
Install from backports:
bash
sudo apt install package/bullseye-backports
Package Priorities
APT uses priorities to decide which version to install: - 1001: Installed manually - 990: Not automatic - 500: Standard - 100: Not automatic, lower priority
Practice Exercises
- Update your package lists.
- Search for and install a text editor (e.g., vim or emacs).
- Check for upgradable packages.
- Install development tools.
- Remove an unused package.
Next, we'll explore user management and permissions.
