This commit is contained in:
2025-06-04 18:30:20 +03:30
parent a7509c6285
commit ac1d0dfdeb
3 changed files with 148 additions and 26 deletions

148
Linux/LPIC1/5-apt.md Normal file
View File

@@ -0,0 +1,148 @@
# 📦 Managing Packages with `apt` on Debian/Ubuntu
The `apt` (Advanced Package Tool) command-line utility allows you to manage software on Debian-based Linux systems. Below are essential `apt` commands grouped by purpose, with clear explanations for each.
---
## 🔄 1. Updating and Upgrading the System
### `sudo apt update`
Fetches the latest package lists from repositories. This ensures your system is aware of the newest available versions of packages.
```bash
sudo apt update
```
---
### `apt upgrade`
Installs the newest versions of all installed packages based on the updated package lists. It does **not** remove or install any other packages.
```bash
apt upgrade
```
---
## 🔍 2. Searching and Viewing Packages
### `apt show <package>`
Displays detailed information about a specific package, including version, dependencies, description, and more.
```bash
apt show <package>
```
---
### `apt list`
Lists packages based on various filters (e.g., installed, upgradable, available). Running it without arguments shows all packages.
```bash
apt list
```
---
### `apt-cache search <pkg name>`
Searches the package cache for packages matching the given name or description. Useful for discovering packages related to a topic or function.
```bash
apt-cache search <pkg name>
```
---
## 📥 3. Installing and Reinstalling Packages
### `apt install <pkg name>`
Installs a package and its dependencies from the repositories.
```bash
apt install <pkg name>
```
---
### `apt reinstall <package>`
Reinstalls the specified package. This is useful if files from a package are accidentally deleted or corrupted.
```bash
apt reinstall <package>
```
---
## ❌ 4. Removing Packages
### `apt remove <package>`
Removes the specified package but **retains configuration files**. Useful when planning to reinstall later without losing settings.
```bash
apt remove <package>
```
---
### `apt purge <package>`
Completely removes the package **along with its configuration files**. Use when you want a clean uninstallation.
```bash
apt purge <package>
```
---
### `apt autoremove`
Automatically removes packages that were installed as dependencies but are no longer needed.
```bash
apt autoremove
```
---
## 🛠️ 5. Advanced Package Handling
### `apt install -f`
Attempts to **fix broken dependencies** by installing missing packages. Often used after a failed install.
```bash
apt install -f
```
---
### `apt install --download-only <package>`
Downloads a package without installing it. The downloaded `.deb` files are saved in:
```bash
/var/cache/apt/archives/
```
Example:
```bash
apt install --download-only <package>
```
---
## ✅ Final Notes
* Always start with `sudo apt update` before any install or upgrade.
* Use `apt-cache search` when unsure of a packages exact name.
* Be cautious with `purge` as it deletes config files too.