> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use RPM and YUM Package Management

> This guide covers using YUM and DNF for package management on RHEL, including system registration, repository configuration, and package installation.

Managing software on Red Hat Enterprise Linux (RHEL) relies on YUM (Yellowdog Updater, Modified) or its successor, `dnf`. In this guide, you’ll learn how to register your system, configure repositories, and install, update, or remove packages. Most `yum` commands work identically with `dnf`; just replace `yum` with `dnf` where desired.

<Callout icon="lightbulb" color="#1CB2FE">
  If you prefer `dnf` over `yum`, you can use it interchangeably, for example:

  ```bash theme={null}
  sudo dnf install httpd
  ```
</Callout>

***

## 1. Registering with Red Hat Subscription Management

Before accessing Red Hat repositories, register and attach your system to a subscription.

```bash theme={null}
sudo subscription-manager register \
  --username your-redhat-developer-username \
  --password your-redhat-password
```

Once registered, attach the system automatically:

```bash theme={null}
sudo subscription-manager attach --auto
```

<Callout icon="triangle-alert" color="#FF6B6B">
  Ensure your subscription is active; expired subscriptions will prevent you from installing or updating packages.
</Callout>

***

## 2. Listing and Inspecting Repositories

A repository (repo) is a storage location—online or on your network—containing RPM packages, metadata, and signing keys.

### 2.1 View Enabled Repositories

```bash theme={null}
sudo yum repolist
```

Sample output:

```text theme={null}
repo id                             repo name
rhel-8-for-x86_64-appstream-rpms    Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
rhel-8-for-x86_64-baseos-rpms       Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
```

### 2.2 View Repository Details

Add `-v` for verbose details, including each repo’s URL and configuration file:

```bash theme={null}
sudo yum repolist -v
```

Key fields in the output:

* **Repo-baseurl**: URL where YUM fetches packages
* **Repo-filename**: Local file under `/etc/yum.repos.d/`

***

## 3. Enabling and Disabling Repositories

Some packages reside in optional or specialized repos.

### 3.1 List All Repositories

```bash theme={null}
sudo yum repolist --all
```

### 3.2 Using Subscription Manager

Enable or disable by repo ID:

```bash theme={null}
sudo subscription-manager repos --enable   rhel-8-for-x86_64-codeready-builder-rpms
sudo subscription-manager repos --disable  rhel-8-for-x86_64-codeready-builder-rpms
```

### 3.3 Using yum-config-manager

First, install `yum-utils`:

```bash theme={null}
sudo yum install yum-utils
```

Then enable or disable:

```bash theme={null}
sudo yum-config-manager --enable  some-repo-id
sudo yum-config-manager --disable some-repo-id
```

***

## 4. Adding a Custom Repository

To add a third-party or local repo:

```bash theme={null}
sudo yum install yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
# Or from a local network path
sudo yum-config-manager --add-repo http://192.168.1.220/BaseOS.repo
```

This creates a `.repo` file in `/etc/yum.repos.d/`. Verify it:

```bash theme={null}
sudo yum repolist -v | grep Repo-filename
```

***

## 5. Understanding a `.repo` File

Open the Docker repo for inspection:

```bash theme={null}
sudo vi /etc/yum.repos.d/docker-ce.repo
```

```ini theme={null}
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/rhel/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/rhel/gpg
```

| Field       | Description                                       |
| ----------- | ------------------------------------------------- |
| `[repo-id]` | Unique identifier in brackets                     |
| `name=`     | Human-readable repository name                    |
| `baseurl=`  | URL to fetch packages                             |
| `enabled=`  | `1` to enable, `0` to disable                     |
| `gpgcheck=` | `1` enforces GPG signature checking (recommended) |
| `gpgkey=`   | URL or file path to the GPG public key            |

To completely remove a repository, delete its file:

```bash theme={null}
sudo rm /etc/yum.repos.d/docker-ce.repo
```

***

## 6. Searching for Packages

If you’re unsure of the exact name, use `yum search`. Single terms match any, quotes require both terms.

```bash theme={null}
# Matches "web" OR "server"
sudo yum search web server

# Matches packages containing both "web" AND "server"
sudo yum search 'web server'
```

Example result:

```text theme={null}
nginx.x86_64 : A high performance web server and reverse proxy server
```

***

## 7. Viewing Package Information

Inspect a package before installation:

```bash theme={null}
sudo yum info nginx
```

Sample output:

```text theme={null}
Name        : nginx
Version     : 1.20.1
Release     : 1.el8
Architecture: x86_64
Summary     : High performance web server and reverse proxy
Description : NGINX is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
              IMAP protocols with a focus on high concurrency, performance and low
              memory usage.
```

***

## 8. Installing, Reinstalling, and Removing Packages

Install a new package:

```bash theme={null}
sudo yum install nginx
```

Reinstall (e.g., to restore missing config files):

```bash theme={null}
sudo yum reinstall nginx
```

Remove a package and its dependencies:

```bash theme={null}
sudo yum remove nginx
```

Clean up unneeded dependencies:

```bash theme={null}
sudo yum autoremove
```

***

## 9. Managing Package Groups

YUM supports predefined groups (e.g., “Server with GUI”).

| Command                               | Description              |
| ------------------------------------- | ------------------------ |
| `sudo yum group list`                 | List available groups    |
| `sudo yum group list --hidden`        | Include hidden groups    |
| `sudo yum group install 'Group Name'` | Install a specific group |
| `sudo yum group remove 'Group Name'`  | Remove a specific group  |

Example:

```bash theme={null}
sudo yum group install 'Server with GUI'
```

***

## 10. Installing from a Local RPM File

After downloading an RPM:

```bash theme={null}
sudo wget https://download.nomachine.com/download/7.7/Linux/nomachine_7.7.4_1_x86_64.rpm
sudo yum install ./nomachine_7.7.4_1_x86_64.rpm
```

Remove it when no longer needed:

```bash theme={null}
sudo yum remove nomachine
```

***

## 11. Updating and Upgrading Packages

Check for available updates:

```bash theme={null}
sudo yum check-update
```

Apply all updates:

```bash theme={null}
sudo yum update
```

<Callout icon="triangle-alert" color="#FF6B6B">
  If a kernel or critical component is updated, reboot to ensure changes take effect:

  ```bash theme={null}
  sudo reboot
  ```
</Callout>

***

## Links and References

* [Red Hat Subscription Management](https://access.redhat.com/documentation/en-us/red_hat_subscription_management/)
* [YUM Official Documentation](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_packages_with_yum/index)
* [Docker CE Repository for RHEL](https://docs.docker.com/engine/install/centos/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/linux-professional-institute-lpic-1-exam-101/module/78ca0fa8-2083-408a-bf8a-2775b09fbf1d/lesson/4c5f841d-94ae-4b1d-bb25-4f3564494554" />
</CardGroup>
