> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/package-management/red-hat-enterprise-linux-rhel.md).

# Red Hat Enterprise Linux (RHEL)

## **Package Management**

CentOS, as a distribution based on Red Hat Enterprise Linux (RHEL), primarily uses the **Red Hat Package Manager (RPM)** for package management.

CentOS also provides **YUM (Yellowdog Updater, Modified)** and **DNF (Dandified YUM)** as high-level package managers that handle dependencies automatically, whereas RPM works at a lower level.

***

## **Red Hat Package Manager (RPM)**

RPM is a low-level package management tool designed for managing `.rpm` packages in RHEL-based distributions like CentOS and Fedora. It does not handle dependencies automatically, so users may need to resolve them manually.

### **Types of RPM Packages**

1. **Binary RPM (RPM)** – Contains precompiled binaries of an application.
2. **Source RPM (SRPM)** – Includes the source code, configuration files, and build instructions, allowing users to compile the package manually.

***

### **RPM Package Architecture**

RPM packages are designed for different system architectures:

* **i386** – Built for 32-bit systems.
* **x86\_64** – Built for 64-bit systems (most modern systems).
* **noarch** – Platform-independent package that does not rely on a specific architecture.

***

### **Contents of an RPM Package**

An RPM package consists of multiple components, including:

* **Application binaries or libraries** – The main software files.
* **Documentation files** – Manuals, license agreements, and release notes.
* **Configuration files** – Predefined settings for the application.
* **SPEC File (`.spec`)** – Defines how the package is built, installed, and maintained.
* **RPM Database Location** – Stores information about installed RPM packages in `/var/lib/rpm`.

***

### **RPM Package Management Commands**

#### **Querying Installed RPM Packages**

To check the details of installed packages, use the following commands:

* Query if a package is installed

```sh
rpm -q <package-name>
```

* List all installed packages

```
rpm -qa                 
```

* Show all files installed by a package

  ```
  rpm -ql <package-name>
  ```
* Display the state of package files

  ```
  rpm -qs <package-name>
  ```
* List documentation files of a package

  ```
  rpm -qd <package-name>
  ```
* Display configuration files of a package

  ```
  rpm -qc <package-name>
  ```
* Show license files of a package

  ```
  rpm -qL <package-name>
  ```
* List dependencies required by a package

  ```
  rpm -qR <package-name>
  ```
* Show detailed package information

  ```
  rpm -qi <package-name>
  ```

***

#### **Verifying RPM Packages**

* Verify integrity of a specific package

  ```sh
  rpm -V <package-name>
  ```
* Verify all installed packages

  ```
  rpm -Va
  ```
* Verify which package a file belongs to

  ```
  rpm -Vf <file-path>
  ```
* Verify package without checking digital signature

  ```
  rpm -V --nodigest
  ```

***

#### **Installing, Upgrading, and Removing Packages**

* Install a package

  ```sh
  rpm -i package.rpm 
  ```
* Install with verbose and progress indicators

  ```
  rpm -ivh package.rpm
  ```
* Reinstall an already installed package

  ```
  rpm -ih --replacepkgs package.rpm 
  ```
* Upgrade or install a package

  ```sh
  rpm -U package.rpm
  ```
* Upgrade only if the package is already installed

  ```
  rpm -F package.rpm
  ```
* Remove a package

  ```sh
  rpm -e <package-name>
  ```

⚠️ **Removing an RPM package does not automatically remove its dependencies.**

***

#### **Viewing an RPM Package Without Installing**

You can inspect the contents of an RPM package before installation:

* Query package details without installing

  ```sh
  rpm -qp package.rpm
  ```
* List files contained in the package

  ```
  rpm -qpl package.rpm
  ```
* Show detailed package information

  ```
  rpm -qpi package.rpm
  ```

***

## **YUM (Yellowdog Updater, Modified)**

YUM (Yellowdog Updater, Modified) is a high-level package manager developed by **Duke University** to simplify the installation, updating, and removal of **RPM** packages. Unlike **RPM**, which does not handle dependencies automatically, YUM resolves dependencies and ensures smooth package management.

### **Understanding Repositories**

A **repository** is a storage location that contains software packages and metadata used by YUM to install and manage applications.

#### **Types of Repositories**

1. **Offline Repository** – Used in **isolated networks** (e.g., **banks, data centers**) where internet access is restricted.
2. **Online Repository** – Used for internet-based package management.

#### **Why Use a Repository?**

* Ensures a structured method to manage software packages.
* Automatic dependency resolution.
* Provides access to the latest software updates and security patches.

***

### **Creating an Offline YUM Repository**

Offline repositories are useful for networks that **lack internet access**, such as **corporate environments** and **secure facilities**.

#### **Requirements**

* `createrepo` must be installed.
* Access to the required RPM packages.

#### **Commands to Create an Offline Repository**

```bash
createrepo -d /path/to/package-folder/
```

#### **Repository Configuration File Location**

* `/etc/yum.repos.d/` (Stores repository configuration files)

#### **Steps to Create an Offline Repository**

1. **Mount the ISO file (if applicable):**

   ```bash
   mount -t iso9660 iso_filename /mnt/
   ```
2. **Move the contents to a new folder:**

   ```bash
   mv /mnt/* /new_folder_name/
   ```
3. **Unmount the ISO:**

   ```bash
   umount /mnt
   ```
4. **Create the repository metadata:**

   ```bash
   createrepo -v --database /package-folder-name/ -o /output-folder-name
   ```
5. **Configure the repository by creating a `.repo` file:**

   ```bash
   cd /etc/yum.repos.d/
   vim newrepo.repo
   ```

**Example `newrepo.repo` File**

```
[centos7]
name=CentOS 7 Repository
baseurl=file:///CentOS7-repo/Packages/
gpgcheck=0
enabled=1
```

#### **Updating the Repository List**

```bash
yum repolist all
```

#### **Removing an Offline Repository**

```bash
rm -rf /package-folder-name
yum clean all
rm -rf /etc/yum.repos.d/centos7
```

***

### **Online YUM Repositories**

Online repositories allow YUM to retrieve packages from the internet. Below are some commonly used repositories for CentOS.

#### **Installing and Removing Online Repositories**

**EPEL (Extra Packages for Enterprise Linux) Repository**

EPEL provides additional packages for CentOS and RHEL.

* **Install:**

  ```bash
  yum install epel-release.noarch
  yum repolist all
  ```
* **Remove:**

  ```bash
  yum remove epel-release.noarch
  yum clean all
  ```

**Remi Repository**

Used for installing newer versions of **PHP** and other applications.

* **Install:**

  ```bash
  yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
  ```

**RPMFusion Repository**

Provides additional **free and non-free software** for CentOS.

* **Install:**

  ```bash
  yum install https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
  ```

**ELRepo Repository**

Primarily used for **kernel and driver updates**.

* **Install:**

  ```bash
  yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
  yum repolist all
  ```

**NUX Desktop Repository**

Provides **multimedia applications** such as VLC.

* **Install:**

  ```bash
  yum install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
  yum repolist all
  ```

**IUS Repository**

Provides **up-to-date versions** of software such as Python and Git.

* **Install:**

  ```bash
  yum install https://repo.ius.io/ius-release-el$(rpm -E '%{rhel}').rpm
  yum repolist all
  ```

***

### **Essential YUM Commands**

YUM provides various commands for efficiently managing **packages** and **repositories** in CentOS.

#### **Repository Management**

Retrieve the installed YUM version:

```bash
yum version
```

List all enabled repositories:

```bash
yum repolist
```

List all repositories (enabled and disabled):

```bash
yum repolist all
```

Clear all cached repository data:

```bash
yum clean all
```

Generate repository cache for faster lookups:

```bash
yum makecache
```

#### **Package Querying**

List all available packages in the repositories:

```bash
yum list available
```

List all installed packages on the system:

```bash
yum list installed
```

Check for package updates:

```bash
yum check-update
```

#### **Package Installation and Removal**

Install a package:

```bash
yum install <package>
```

Remove an installed package:

```bash
yum remove <package>
```

Reinstall an existing package:

```bash
yum reinstall <package>
```

Downgrade a package to an older version:

```bash
yum downgrade <package>
```

Update all installed packages to the latest version:

```bash
yum update
```

Update a specific package:

```bash
yum update <package>
```

#### **Viewing Package Information**

Display detailed information about a package:

```bash
yum info <package>
```

Find which package provides a specific command or file:

```bash
yum provides <command>
```

#### **Working with YUM History**

View the transaction history of YUM:

```bash
yum history
```

List all past YUM transactions:

```bash
yum history list
```

Undo a specific transaction using its ID:

```bash
yum history undo <ID>
```

#### **Group Package Management**

List all available package groups:

```bash
yum groups list
```

Install a predefined group of packages (e.g., Development Tools):

```bash
yum groups install "Development Tools"
```

Remove a previously installed package group:

```bash
yum groups remove "Development Tools"
```

Installing Wine to Run Windows Applications

```bash
yum install wine
```
