sodcalculator

10 Tech How-To

Install a Linux Package from a Specific Repository

Guide 10-39480 · Updated · Step by step

To install a package from a specific repository in Linux, first make sure that repository is configured and its package index is current, then use your distribution’s package manager to select the repository or package version. The exact command depends on whether you use Debian or Ubuntu, Fedora, openSUSE, Arch Linux, or another distribution.

How Repository Selection Works

A repository is a server or local source containing package files and metadata. The metadata tells a package manager which packages and versions are available, what other packages they require, and how to verify them. Adding a repository makes its packages available; it does not necessarily make that repository the source for every installation.

Package managers normally choose a candidate based on configured priorities, version rules, and dependencies. If two repositories contain the same package name, simply installing that name may select a version from the default or higher-priority source. To control the source, use a repository-specific option, a version selector, or a repository priority mechanism supported by your distribution.

Debian and Ubuntu: APT

APT reads repository definitions from /etc/apt/sources.list and files under /etc/apt/sources.list.d/. After adding a repository using its supported setup instructions, refresh metadata:

sudo apt update

To install a package version shown in APT’s package policy, specify the version explicitly:

apt-cache policy package-name
sudo apt install package-name=version

Replace package-name and version with the actual values. The version string must match one APT displays; it can include an epoch or distribution revision. Check the proposed transaction before confirming, especially if APT plans to remove or downgrade other packages.

APT does not generally provide a universal --repo switch that guarantees a package comes from a named repository. When a repository offers a distinct package version, choosing that version is often the simplest route. For stronger control over which repository supplies packages, configure APT pinning in a preferences file. A pin can assign a priority to a repository or package, but poorly chosen priorities may cause broad upgrades or downgrades, so target the rule narrowly and inspect apt-cache policy afterward.

Fedora and Other DNF Systems

On Fedora and many related systems, DNF can enable or disable repositories for one command. First list configured repositories, then install while enabling the intended one:

dnf repolist --all
sudo dnf --enablerepo=repository-id install package-name

If another repository would otherwise provide the package, you can disable it for that transaction with --disablerepo=repository-id, or disable all repositories and enable only the desired one:

sudo dnf --disablerepo='*' --enablerepo=repository-id install package-name

Use the exact repository ID shown by DNF, not necessarily its display name. DNF may still need packages from other repositories to satisfy dependencies. If those dependencies are unavailable, installation can fail; enabling only one repository is not appropriate when required dependencies come from the distribution’s normal repositories.

openSUSE, Arch, and Other Package Managers

On openSUSE, zypper supports selecting a repository with its repository option:

zypper repos
sudo zypper install --from repository-alias package-name

Confirm the alias with zypper repos. Review the changes zypper proposes, since repository selection can affect dependency choices as well as the named package.

Arch Linux’s standard pacman uses repositories configured in /etc/pacman.conf. Repository order and package availability influence which package is selected; pacman does not use the same per-command repository selector as DNF. Configure the intended repository, refresh its database as appropriate, and check the package’s repository and version with:

pacman -Si package-name
sudo pacman -S package-name

Repository configuration and synchronization can affect the system as a whole, so follow the distribution’s documentation rather than copying configuration intended for another release. Other systems, including Alpine Linux and Gentoo, have their own repository configuration and selection rules; use that system’s package-manager documentation for exact syntax.

Check the Source Before and After Installing

Before installation, identify the repository and candidate version. This helps distinguish a package that is merely available from one the package manager will actually choose.

  • APT: use apt-cache policy package-name to see versions and their sources.
  • DNF: use dnf info package-name or dnf repoquery --info package-name where available, and inspect repository IDs.
  • zypper: use zypper info package-name and confirm the selected repository.
  • pacman: use pacman -Si package-name to inspect repository and version information.

After installation, query the package manager’s installed-package records to check the installed version. Be aware that some systems do not retain a definitive record of the original repository for every installed package, particularly after repository changes. The package’s version and installation history may help, but they are not always proof of its source.

Common Problems and Safe Repository Use

If the package manager cannot find the repository or package, check that the repository is configured, enabled, and appropriate for your distribution release and architecture. Refresh the package index or repository metadata. A typo in a repository ID or package name is also common. If the requested version is not listed, the repository may not publish it for your release, or its metadata may be stale.

Dependency conflicts often mean the selected repository does not provide a compatible set of packages. Avoid forcing installation or mixing packages built for different distribution releases just to satisfy the command. A partial mix of package sources can leave core libraries or applications at incompatible versions. Prefer repositories intended for your exact distribution and release, and review any transaction that proposes removals or a large downgrade.

Repository signing checks protect against packages that do not match trusted metadata. Do not disable signature verification simply to make an installation proceed. If a signing-key warning appears, verify the repository’s current setup instructions and key through a trustworthy distribution or project source. Remove a repository you no longer need, since it may otherwise continue to influence future updates.

Frequently Asked Questions

Can I install a package directly from a repository URL?
Usually, configure the repository first so the package manager can verify metadata and resolve dependencies. A direct package-file installation may skip normal repository selection and can require you to handle dependencies separately.

Why did Linux install the package from a different repository?
The package manager may have selected a higher-priority source, a newer candidate version, or a repository needed to satisfy its rules. Inspect the package policy or repository information, then use the distribution’s supported selection or pinning method.

Can I install only one package from a repository without using it for updates?
Often, yes. DNF and zypper offer per-command selection options; APT can select an available version or use narrowly scoped pinning. The exact behavior depends on the distribution, and dependencies may still come from other configured sources.

Does installing from a specific repository also install dependencies from it?
Not necessarily. The package manager resolves dependencies from all eligible repositories unless you restrict them, and restricting them can make installation impossible. Review the proposed transaction to see where dependencies will come from.

How do I undo an installation from the wrong repository?
Removing the package may not restore older versions of dependencies or configuration files. Check the package manager’s transaction history and the distribution’s downgrade guidance before changing system packages; reinstalling the intended version may be safer than removing shared dependencies.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →