In the Linux world, installing software isn’t as straightforward as double-clicking an installer like in Windows or downloading from the App Store like on Mac. But don’t worry—Linux has two “capable assistants”: Yum and Apt. These are like intelligent software managers that make installing, updating, and managing system software a breeze.
Why Use a Package Manager?¶
Imagine trying to install software without a package manager: you’d have to compile from source code yourself (which involves writing code, configuring environments, and resolving dependencies)—a nightmare for beginners! A package manager acts like an “automatic delivery service” that:
- Automatically downloads software packages (no need to manually find installers);
- Automatically resolves dependencies between software (e.g., installing WeChat requires fonts and library files first);
- Automatically updates the system and software (keeps everything up-to-date and patches vulnerabilities).
Yum: The “Provisioner” for RHEL/CentOS/Fedora¶
Yum (Yellowdog Updater, Modified) is a package manager for RHEL (Red Hat Enterprise Linux), CentOS, Fedora, and other distributions. It manages .rpm-formatted packages (similar to Windows .exe files).
Use Case¶
- If you’re using CentOS 7/8, RHEL, or Fedora, Yum is your go-to tool.
Core Commands (Essential for Beginners)¶
-
Install Software:
sudo yum install 软件名
(Example: Install the text editorvim:sudo yum install vim;sudogrants administrator privileges) -
Update System/Software:
sudo yum update
(Updates all installed software to the latest version; use cautiously as it may alter system configurations) -
Search for Software:
yum search 关键词
(Example: Find a video player:yum search vlc) -
Uninstall Software:
sudo yum remove 软件名
(Uninstall an installed program; e.g.,sudo yum remove vimto uninstallvim) -
Clean Cache:
sudo yum clean all
(Clear cached downloaded packages to free up disk space)
Repositories: Yum’s “Warehouse Address”¶
Yum’s “software warehouse” is called a repository. It’s like an “online supermarket” with installable packages. The configuration file location is:
/etc/yum.repos.d/ (e.g., CentOS-Base.repo is the default repository config file).
To add additional repositories (e.g., the EPEL repo not included by default in CentOS), run:
sudo yum install epel-release (automatically adds the EPEL repository after installation).
Apt: The “Butler” for Debian/Ubuntu¶
Apt (Advanced Package Tool) is the package manager for Debian, Ubuntu, and other distributions. It manages .deb-formatted packages (similar to Mac .dmg files).
Use Case¶
- If you’re using Ubuntu, Debian, or Linux Mint, Apt is your dedicated tool.
Core Commands (Essential for Beginners)¶
-
Install Software:
sudo apt install 软件名
(Example: Install the Firefox browser:sudo apt install firefox) -
Update Repositories and System:
- First, update the repository list:sudo apt update
- Then update installed software:sudo apt upgrade
(updateonly refreshes repo metadata;upgradeactually installs updates) -
Search for Software:
apt search 关键词
(Example: Find an email client:apt search thunderbird) -
Uninstall Software:
sudo apt remove 软件名
(Uninstall a program; e.g.,sudo apt remove thunderbirdto uninstallthunderbird) -
Clean Cache:
sudo apt clean
(Clear cached packages more thoroughly thanyum clean)
Repositories: Apt’s “Warehouse Address”¶
Apt’s repository configurations are in:
- Main config file: /etc/apt/sources.list
- Additional repositories: /etc/apt/sources.list.d/ (e.g., .list files for third-party software)
Ubuntu’s default repositories (official) might be slow. You can replace them with domestic mirrors (e.g., Alibaba Cloud, Tsinghua University). Modify sources.list and run apt update to apply changes.
Yum vs Apt: Which Suits You?¶
| Comparison | Yum (RHEL/CentOS) | Apt (Debian/Ubuntu) |
|---|---|---|
| Package Format | .rpm (binary installer) |
.deb (binary installer) |
| Repository Path | /etc/yum.repos.d/ |
/etc/apt/sources.list |
| Core Command | yum install |
apt install |
| Dependency Handling | Automatically resolves dependencies (requires valid repos) | Automatically resolves dependencies (requires valid repos) |
Beginner Tips¶
-
Confirm Your Distribution:
Runcat /etc/os-releaseand check theIDfield (e.g.,ID=centosorID=ubuntu) to determine if you should use Yum or Apt. -
Troubleshoot Dependency Issues:
Yum and Apt auto-resolve dependencies if repos are configured correctly. If you get “package not found,” runapt updateoryum updateto refresh repos first, then retry. -
Fix Broken Repositories:
If repo configs are incorrect, installation may fail. Backup the default sources first (e.g.,sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak), then test withapt update.
Conclusion¶
Yum and Apt are both efficient tools for software installation in Linux, designed to “install with one click and auto-resolve dependencies.” Remember:
- RHEL/CentOS/Fedora → Yum (commands start with yum);
- Debian/Ubuntu → Apt (commands start with apt).
You might mix up commands at first, but practice installing a small program (e.g., vim or firefox) to master them quickly!