Installing, Updating, and Removing Software (Debian-based & RedHat-based System)
In Linux, most software is distributed as packages
—compressed files containing application code, dependencies, and configuration scripts.
- Managing these packages is essential for maintaining a healthy, secure, and functional system.
- Each Linux distribution (distro) has its own package manager to handle software.
Key Concepts
- Package Manager: A tool that automates the process of installing, updating, and removing software.
- Repositories (Repos): Remote storage locations that contain verified software packages.
- Dependencies: Additional software or libraries required by an application.
Package Formats:
- Debian-based systems:
.deb
files (e.g., Ubuntu, Debian). - Red Hat-based systems:
.rpm
files (e.g., RHEL, Fedora, CentOS).
1. Debian-based Systems (apt, dpkg)
1.1 Using APT
(Advanced Package Tool)
APT is a high-level package manager for Debian-based systems, designed for simplicity and automation.
Key Features of APT:
- Simplifies package installation, removal, and updates.
- Resolves and installs dependencies automatically.
- Downloads packages from remote repositories.
Basic APT Commands:
1. Update Package Lists:
Before installing or updating any software, refresh the local repository information:
sudo apt update
Explanation:
- Downloads the latest metadata (list of available software and versions).
- Ensures you get the latest software.
2. Upgrade Installed Packages
sudo apt upgrade
Explanation:
- Updates all installed software to the latest versions.
- Useful for applying security patches and bug fixes.
3. Install Software
sudo apt install <package_name>
Example: Install the text editor vim.
sudo apt install vim
4. Remove Software
sudo apt remove <package_name>
Example: Remove vim.
sudo apt remove vim
Example: For Complete Removal (including configuration files)
sudo apt purge vim
5. Search for Software
apt search <keyword>
Example: Search for web servers:
apt search nginx
6. Clean Up Unused Packages
sudo apt autoremove
Removes dependencies that are no longer needed by any installed software.
1.2 Using dpkg (Debian Package Manager)
dpkg
is a low-level tool for manually managing packages. Unlike APT, it does not resolve dependencies automatically.
1. Install a Local Package
sudo dpkg -i <package.deb>
Example: Installing google chrome.
sudo dpkg -i google-chrome-stable_current_amd64.deb
2. Check Installed Packages
dpkg -l | grep <package_name>
3. Remove a Package
sudo dpkg -r <package_name>
4. Fix Broken Installations
If dependencies are missing:
sudo apt install -f
2. Red Hat-based Systems (yum, dnf, rpm)
2.1 Using YUM (Yellowdog Updater Modified)
YUM is the older package manager for Red Hat-based systems.
Basic yum
Commands:
1. Install Software
sudo yum install <package_name>
Example: Install httpd
sudo yum install httpd
2. Remove Software
sudo yum remove <package_name>
3. Update Packages
sudo yum update
2.2 Using DNF (Dandified YUM)
DNF replaces YUM in modern Red Hat-based distributions and is faster and more efficient.
1. Install Software
sudo dnf install <package_name>
2. Remove Software
sudo dnf remove <package_name>
3. Update Software
sudo dnf update
2.3 Using RPM (Red Hat Package Manager)
rpm is a low-level tool similar to dpkg.
1: Install an RPM Package
sudo rpm -i <package.rpm>
2. Upgrade an RPM Package
sudo rpm -U <package.rpm>
3. Remove an RPM Package
sudo rpm -e <package_name>
Key Differences Between Package Managers
Feature | APT | DPKG | YUM | DNF | RPM |
---|---|---|---|---|---|
Dependency Handling | Yes | No | Yes | Yes | No |
Repository Support | Yes | No | Yes | Yes | No |
Local File Support | No | Yes | No | No | Yes |
Key Takeaways
- Use APT/DNF for everyday tasks as they handle dependencies automatically.
- Reserve DPKG/RPM for advanced scenarios like local installations.
- Regularly update and clean packages to ensure security and performance.