Subscribing to Different Yum Repositories

Oracle Linux uses modular yum repository configuration files that are made available as release packages that are maintained through yum. Release packages simplify repository management and also ensures that yum repository definitions are kept up-to-date automatically whenever you update the system.

On all Oracle Linux systems, the oraclelinux-release-el8 package is installed by default. This package contains the core repository configurations to access all the repositories required for an Oracle Linux system to install common OS software packages and the other release packages used to obtain other yum repository configurations.

A list of all available RPM files to manage all the possible yum repository configurations for a release can be obtained by running the following command, where n is the Oracle Linux release version of the RPM files, such as -el8.

dnf list "*release-eln*"

To install the yum repository configuration for a particular set of software, use the dnf command to install the corresponding package.

Editing Yum Repository Configuration Files

DNF uses yum repository configuration files to configure where to install different packages and their dependencies from. By default, repository configuration files are stored in the /etc/yum.repos.d directory. You can define another directory location to store repository configurations by setting the reposdir directive in the dnf.conf file.

Use the repository directory to define .repo files for repositories that you want to make available. A .repo file can contain entries for more than one yum repository. To subscribe to a repository, you can edit the enabled option to a value of 1 and save the configuration file. The change has immediate effect.

The following table describes the basic directives for a repository. Any other directive that appears in the repository file override the corresponding global definition in the [main] section of the DNF configuration file. See the dnf.conf(5) manual page for more information.

Directive Description
baseurl Location of the repository (expressed as a file://, ftp://, http://, or https:// address). This directive must be specified.
enabled Whether to enable dnf to use the repository. Set the value to 1 to enable the repository, or 0 to disable the repository.
name Descriptive name for the repository channel. This directive must be specified.

Example Repository Listing

The following listing shows an example repository section from a .repo configuration file.

[ol8_appstream]
name=Oracle Linux $releasever Application Stream ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL8/appstream/$basearch
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1

In this example, the values of gpgkey and gpgcheck override any global setting. dnf substitutes the name of the current system's architecture for the variable $basearch.

Configure Compute Instances Access to Regional Yum Server Repositories

Compute instances in Oracle Cloud Infrastructure have access to regional yum servers through the service gateway. The base URL of the repository uses the $ociregion variable to define which regional server to use and the $ocidomain variable to define the domain where the yum server is located. By using variables, configuration can remain relatively standard across Oracle Linux deployments but provide access to extra resources available to Oracle Cloud Infrastructure customers.

For example, the base URL to the ol8_baseos_latest repository for Oracle Linux 8 is:

baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL8/baseos/latest/$basearch

You can set the $ociregion variable by populating content in /etc/dnf/vars/ociregion. For example, if $ociregion is set to -phx, the base URL expands to point to the regional yum server located in Phoenix.

Typically, when you create an instance, this value is set to point to the closest regional yum server on the Oracle Cloud Infrastructure service network. If the /etc/dnf/vars/ociregion file doesn't exist, or the file is empty, the base URL points to the publicly accessible Oracle Linux yum server.

Using the DNF config-manager Plugin

The dnf-plugins-core package includes several utilities that can help you to manage configuration and safely apply updates to existing configuration. The most significant of these utilities is the dnf config-manager plugin.

You can use dnf config-manager to add repositories, either at a specified URL or within a specified repository file. For example, to add a repository configuration file for Oracle Linux that's hosted on a remote server, you can run the following command:

sudo dnf config-manager --add-repo https://example.com/my_yum_config.repo

You can use the same command to automatically generate a repository configuration file for a valid yum repository by pointing to the URL of which the repository is hosted. For example, to create a configuration file in /etc/repos.d for an example repository, run the following command:

sudo dnf config-manager --add-repo https://example.com/repo/el-release/myrepo/x86_64

To enable a repository by using dnf config-manager, use the --enable option. For example, to enable a repository named myrepo, run the following command:

sudo dnf config-manager --enable myrepo

You can use the --disable option in a similar way to disable a repository.

You can also use the dnf config-manager tool to set other configuration options by specifying the --setopt and --save options. See the dnf.plugin.config_manager(8) manual page for more information.

How to Recover the Base Yum Repository Configuration

Perform this task if the system's base repository configuration has been corrupted or otherwise lost.
  1. Create a temporary repository configuration file in /etc/yum.repos.d.
    sudo mkdir /etc/yum.repos.d/temp_base.repo
  2. Populate the file with entries corresponding to the system's OS version.
    • For Oracle Linux 9:

      [ol9_baseos_latest]
      name=Oracle Linux 9 BaseOS Latest ($basearch)
      baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL9/baseos/latest/$basearch/
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
      gpgcheck=1
      enabled=1
    • For Oracle Linux 8:

      [ol8_baseos_latest]
      name=Oracle Linux 8 BaseOS Latest ($basearch)
      baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL8/baseos/latest/$basearch/
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
      gpgcheck=1
      enabled=1
  3. Reinstall the required release packages of the system's OS version to set up the standard yum repository configurations.
    sudo dnf reinstall oraclelinux-release-olrelease-nbr
  4. Verify that the recovery is successful.
    ls /etc/yum.repos.d/oraclelinux-release-olrelease-nbr
  5. Remove the temporary configuration file.
    rm /etc/yum.repos.d/temporary_base.repo
  6. Reinstall other required release packages to obtain the correct repository configurations.
    sudo dnf reinstall repository
  7. Enable the repositories that you need.
    sudo dnf config-manager --enable repository