Use Zypper to Manage Packages in openSUSE

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Zypper is a command-line package management system for the openSUSE and SUSE Linux Enterprise (SLE) distributions. Zypper builds on the software-management functions of ZYpp (libzypp) for installing, removing, and managing packages, as well as managing package repositories on your system. ZYpp also underlies YaST, a graphical (GUI) tool that provides similar functions to command-line package managers like Zypper.

In this guide, you learn how to use Zypper to execute common package management tasks from the command line on your openSUSE or other supported systems. The guide covers Zypper’s commands for installing, managing, and navigating packages. Additionally, the guide shows you how you can add and update repositories in Zypper.

Before You Begin

Before running the commands within this guide, you need:

  1. A system running on openSUSE. Other Linux distributions that employ the Zypper package manager can also be used. Review the Creating a Compute Instance guide if you do not yet have a compatible system.

  2. Login credentials to the system for either the root user (not recommended) or a standard user account (belonging to the sudo group) and the ability to access the system through SSH or Lish . Review the Setting Up and Securing a Compute Instance guide for assistance with creating and securing a standard user account.

    Note
    Some commands in this guide require elevated privileges and are prefixed with the sudo command. If you are logged in as the root user (not recommended), you can omit the sudo prefix if desired. If you’re not familiar with the sudo command, see the Linux Users and Groups guide.

Install Packages

Zypper’s install command installs or updates a given package along with the package’s associated dependencies. The command takes the package name as its argument. The example here installs the php8 package.

sudo zypper install php8

Zypper can also specify a particular version of a package. Take a look further at the section on viewing package information for a method to get a list of available versions for a given package.

Once you have a specific version, append it after the package name using a comparison operator. The simplest form of this is using the = operator to specify the exact version.

sudo zypper install php8=8.0.29

Zypper also supports the use of greater-than and lesser-than comparisons. Just be sure to wrap the package name and version information in single quotes to avoid the shell interpreting the special characters.

sudo zypper install 'php8>=8.0.29'

Update Packages

Zypper has two kinds of updates for installed packages. The first, using the update command, updates packages to their latest versions. Usually, this is what other package managers mean by “update,” and with Zypper it is known as package-wise updating.

The other kind of update available in Zypper uses the patch command. Known as patch-wise updating, the process does not necessarily update a package to its latest version. Instead, stable patches may be applied that address security issues or other vulnerabilities.

The addition of patch-wise updating can be especially helpful when maintaining a production environment. Such an environment places a premium on maintaining stability and compatibility. Patches help keep things stable while still ensuring protection against possible vulnerabilities in your installed packages.

Package-Wise Updates

The update command manages package-wise updates. Running the command without any arguments updates all installed packages to their latest versions.

sudo zypper update

You can also provide a package name as an argument to target a specific package for updating.

sudo zypper update python3

Before applying updates, you may want to preview what packages an update would impact. The list-updates command gives you a full list of installed packages with newer versions available.

sudo zypper list-updates

Patch-Wise Updates

The patch command applies patch-wise updates. Running the command applies all necessary patch updates to your installed packages.

sudo zypper patch

As with the package-wise updates, you can use a command — list-patches — to list necessary patch-wise updates. You can in this way get a preview of packages that would be impacted by a patch command.

sude zypper list-patches

The list-patches command only lists necessary patches — that is, patches that are deemed applicable to you and have not otherwise been applied. But you can use the patches command to get a list of all patches for your installed packages.

sudo zypper patches

Uninstall Packages

Packages can be uninstalled with Zypper using the remove command. Doing so also uninstalls recommended packages that were installed with the named package.

sudo zypper remove php8

You can add the --clean-deps option to ensure that the command also uninstalls package dependencies that are no longer needed by any other installed packages.

sudo zypper remove --clean-deps php8

Search Through Packages

Zypper’s search command allows you to query packages available in your Zypper repositories. The command takes the search string as an argument.

sudo zypper search php
S | Name                        | Summary                                                               | Type
--+-----------------------------+-----------------------------------------------------------------------+-----------
...
  | php8                        | Interpreter for the PHP scripting language version 8                  | package
...

You can add the -i option to the command to limit the search to installed packages.

sudo zypper search -i python
S | Name                       | Summary                                                                 | Type
--+----------------------------+-------------------------------------------------------------------------+--------
...
i | python3                    | Python 3 Interpreter                                                    | package
...

For any search, an i in the left-most column indicates that a given package is already installed. A v in that same column would indicate that the given package is installed in a different version.

View Information About Packages

The Zypper command info can be used to get detailed information about a specific package. Using this can preview a package before installing it.

sudo zypper info php8
Information for package php8:
-----------------------------
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : php8
Version        : 8.0.29-150400.4.34.1
...

In some cases, the default (latest) version may not be what you need. For instance, the info command above shows that the php8 package installs version 8.0.29.

Use a honed version of the search command like the one below to get a list of available versions of a given package. The --details option provides detailed information about the results. The --match-exact option ensures that the results only include the named package.

sudo zypper search --details --match-exact php8
S | Name | Type       | Version              | Arch   | Repository
--+------+------------+----------------------+--------+-------------------------------------------------------------
  | php8 | package    | 8.0.29-150400.4.34.1 | x86_64 | Update repository with updates from SUSE Linux Enterprise 15
  | php8 | package    | 8.0.28-150400.4.31.1 | x86_64 | Main Repository
...

Add Package Repositories to Access More Packages

Zypper pulls packages, and package information, from its list of package repositories. Using the repos command gives you a list of Zypper’s current repositories.

sudo zypper repos

In some cases, a needed package may not be in one of the default repositories. For instance, the examples above show that the default repositories have only up to version 8.0.29 of the php8 package. But PHP has a version 8.2.8 available.

Using the addrepo command, you can add an additional repository by its URL. Extending the php8 example, openSUSE has a dedicated PHP repository that includes the package’s newer versions.

sudo zypper addrepo --refresh https://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_15.5/ php

The --refresh option enables auto refresh on the repository, which makes repository management easier. See the next section for more details.

Once you have added the repository, you can use the search command as shown earlier to see additional packages offered by the repository.

sudo zypper search --details --match-exact php8
S | Name | Type       | Version              | Arch   | Repository
--+------+------------+----------------------+--------+-------------------------------------------------------------
  | php8 | package    | 8.2.8-lp155.131.2    | x86_64 | php
  | php8 | package    | 8.0.29-150400.4.34.1 | x86_64 | Update repository with updates from SUSE Linux Enterprise 15
  | php8 | package    | 8.0.28-150400.4.31.1 | x86_64 | Main Repository
...

The search command also offers a --repo option that you can use to limit your search to a given repository.

sudo zypper search --repo php -s php8
S | Name                         | Type       | Version           | Arch   | Repository
--+------------------------------+------------+-------------------+--------+-----------
...
  | php8                         | package    | 8.2.8-lp155.131.2 | x86_64 | php
...

Update Package Repositories

Zypper does not usually require you to manually refresh repository metadata. This contrasts with some other package managers, like APT , that require manual repository refreshes.

Zypper accomplishes this with its auto refresh feature. This feature is enabled on all of the default repositories, and it ensures that the repositories are automatically refreshed whenever necessary.

Unless you need manual control of the refresh process for a repository, you should enable auto refresh whenever you add a new repository. This is done by using the --refresh option with the addrepo command, just as shown in the previous section.

If, however, you want to add a repository without auto refresh, you can do so by omitting the -r option when adding the repository.

sudo zypper addrepo https://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_15.5/ php

Zypper includes a refresh command to allow you to manually refresh repositories for updated metadata. Doing so is an important step should you opt not to enable auto refresh on added repositories.

sudo zypper refresh php

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.