9.1 Using Zypper

Zypper is a command line package manager for installing, updating and removing packages as well as for managing repositories. It is especially useful for accomplishing remote software management tasks or managing software from shell scripts.

9.1.1 General Usage

The general syntax of Zypper is:

zypper [global-options]command[command-options][arguments] ...

The components enclosed in brackets are not required. The simplest way to execute Zypper is to type its name, followed by a command. For example, to apply all needed patches to the system type:

zypper patch

Additionally, you can choose from one or more global options by typing them just before the command. For example, --non-interactive means running the command without asking anything (automatically applying the default answers):

zypper --non-interactive patch

To use the options specific to a particular command, type them right after the command. For example, --auto-agree-with-licenses means applying all needed patches to the system without asking to confirm any licenses (they will automatically be accepted):

zypper patch --auto-agree-with-licenses

Some commands require one or more arguments. When using the install command, for example, you need to specify which package(s) to install:

zypper install mplayer

Some options also require an argument. The following command will list all known patterns:

zypper search -t pattern

You can combine all of the above. For example, the following command will install the mplayer and amarok packages from the factory repository while being verbose:

zypper -v install --from factory mplayer amarok

The --from option makes sure to keep all repositories enabled (for solving any dependencies) while requesting the package from the specified repository.

Most Zypper commands have a dry-run option that does a simulation of the given command. It can be used for test purposes.

zypper remove --dry-run MozillaFirefox

9.1.2 Installing and Removing Software with Zypper

To install or remove packages use the following commands:

zypper install package_name
zypper remove package_name

Zypper knows various ways to address packages for the install and remove commands:

by the exact package name (and version number)
zypper install MozillaFirefox

or

zypper install MozillaFirefox-3.5.3
by repository alias and package name
zypper install mozilla:MozillaFirefox

Where mozilla is the alias of the repository from which to install.

by package name using wildcards

The following command will install all packages that have names starting with Moz. Use with care, especially when removing packages.

zypper install 'Moz*'
by capability

For example, if you would like to install a perl module without knowing the name of the package, capabilities come in handy:

zypper install 'perl(Time::ParseDate)'
by capability and/or architecture and/or version

Together with a capability you can specify an architecture (such as i586 or x86_64) and/or a version. The version must be preceded by an operator: < (lesser than), <= (lesser than or equal), = (equal), >= (greater than or equal), > (greater than).

zypper install 'firefox.x86_64'
zypper install 'firefox>=3.5.3'
zypper install 'firefox.x86_64>=3.5.3'
by path to the RPM file

You can also specify a local or remote path to a package:

zypper install /tmp/install/MozillaFirefox.rpm
zypper install http://download.opensuse.org/repositories/mozilla/SUSE_Factory/x86_64/MozillaFirefox-3.5.3-1.3.x86_64.rpm

To install and remove packages simultaneously use the +/- modifiers. To install emacs and remove vim simultaneously, use:

zypper install emacs -vim

To remove emacs and install vim simultaneously, use:

zypper remove emacs +vim

To prevent the package name starting with the - being interpreted as a command option, always use it as the second argument. If this is not possible, precede it with --:

zypper install -emacs +vim       # Wrong
zypper install vim -emacs        # Correct
zypper install -- -emacs +vim    # same as above
zypper remove emacs +vim         # same as above

If (together with a certain package) you automatically want to remove any packages that become unneeded after removing the specified package, use the --clean-deps option:

rm package_name --clean-deps

By default, Zypper asks for a confirmation before installing or removing a selected package, or when a problem occurs. You can override this behavior using the --non-interactive option. This option must be given before the actual command (install, remove, and patch) as in the following:

zypper --non-interactive install package_name

This option allows the use of Zypper in scripts and cron jobs.

WARNING: Do not Remove Mandatory System Packages

Do not remove packages such as glibc, zypper, kernel, or similar packages. These packages are mandatory for the system and, if removed, may cause the system to become unstable or stop working altogether.

Installing Source Packages

If you want to install the corresponding source package of a package, use:

zypper source-install package_name

That command will also install the build dependencies of the specified package. If you do not want this, add the switch -D. To install only the build dependencies use -d.

zypper source-install -D package_name # source package only
zypper source-install -d package_name # build dependencies only

Of course, this will only work if you have the repository with the source packages enabled in your repository list (it is added by default, but not enabled). See Section 9.1.4, Managing Repositories with Zypper for details on repository management.

A list of all source packages available in your repositories can be obtained with:

zypper search -t srcpackage

Utilities

To verify whether all dependencies are still fulfilled and to repair missing dependencies, use:

zypper verify

In addition to dependencies that must be fulfilled, some packages recommend other packages. These recommended packages are only installed if actually available and installable. In case recommended packages were made available after the recommending package has been installed (by adding additional packages or hardware), use the following command:

zypper install-new-recommends

This command is very useful after plugging in a webcam or WLAN device. It will install drivers for the device and related software, if available. Drivers and related software are only installable if certain hardware dependencies are fulfilled.

9.1.3 Updating Software with Zypper

There are three different ways to update software using Zypper: by installing patches, by installing a new version of a package or by updating the entire distribution. The latter is achieved with the zypper dist-upgrade command which is discussed in Section 16.1, Upgrading the System.

Installing Patches

To install all officially released patches applying to your system, just run:

zypper patch

In this case, all patches available in your repositories are checked for relevance and installed, if necessary. The above command is all you must enter in order to apply them when needed.

Zypper knows three different commands to query for the availability of patches:

zypper patch-check

Lists the number of needed patches (patches, that apply to your system but are not yet installed)

~ # zypper patch-check
Loading repository data...
Reading installed packages...
5 patches needed (1 security patch)
zypper list-patches

Lists all needed patches (patches, that apply to your system but are not yet installed)


~ # zypper list-patches
Loading repository data...
Reading installed packages...
 
Repository                          | Name      | Version | Category | Status
------------------------------------+-----------+---------+----------+-------
Updates for openSUSE 11.3 11.3-1.82 | lxsession | 2776    | security | needed
zypper patches

Lists all patches available for openSUSE, regardless of whether they are already installed or apply to your installation.

It is also possible to list and install patches relevant to specific issues. To list specific patches, use the zypper list-patches command with the following options:

--bugzilla[=number]

Lists all needed patches for Bugzilla issues. Optionally, you can specify a bug number if you only want to list patches for this specific bug.

--cve[=number]

Lists all needed patches for CVE (Common Vulnerabilities and Exposures) issues, or only patches matching a certain CVE number, if specified.

To install a patch for a specific Bugzilla or CVE issue, use the following commands:

zypper patch --bugzilla=number

or

zypper patch --cve=number

For example, to install a security patch with the CVE number CVE-2010-2713, execute:

zypper patch --cve=CVE-2010-2713

Installing Updates

If a repository contains only new packages, but does not provide patches, zypper patch does not show any effect. To update all installed packages with newer available versions, use:

zypper update

To update individual packages, specify the package with either the update or install command:

zypper update package_name
zypper install package_name

A list of all new installable packages can be obtained with the command:

zypper list-updates

Note that this command only packages lists packages that match the following criteria:

  • has the same vendor like the already installed package,

  • is provided by repositories with at least the same priority than the already installed package,

  • is installable (all dependencies are satisfied).

A list of all new available packages (regardless whether installable or not) can be obtained with:

zypper list-updates --all

To find out why a new package cannot be installed, just use the zypper install or zypper update command as described above.

Upgrading to a New Product Version

To easily upgrade your installation to a new product version (for example, from openSUSE 11.4 to openSUSE 12.1), first adjust your repositories to match the current openSUSE repositories. For details, refer to Section 9.1.4, Managing Repositories with Zypper. Then use the zypper dist-upgrade command with the required repositories. This command ensures that all packages will be installed from the repositories currently enabled. For detailed instructions, refer to Section 16.1.4, Distribution Upgrade with zypper.

To restrict the distribution upgrade to packages from a certain repository while considering also the other repositories for satisfying dependencies, use the --from option and specify the repository by either its alias, its number or URI.

NOTE: Differences between zypper update and zypper dist-upgrade

Choose zypper update to update packages to newer versions available for your product version while maintaining system integrity. zypper update will honor the following rules:

  • no vendor changes
  • no architecture changes
  • no downgrades
  • keep installed packages

When executing zypper dist-upgrade, all packages will be installed from the repositories currently enabled. This rule is enforced, so packages might change vendor or architecture or even might get downgraded. All packages that have unfulfilled dependencies after the upgrade will be uninstalled.

9.1.4 Managing Repositories with Zypper

All installation or patch commands of Zypper rely on a list of known repositories. To list all repositories known to the system, use the command:

zypper repos

The result will look similar to the following output:

Example 9-1 Zypper—List of Known Repositories


# | Alias                 | Name                  | Enabled | Refresh
--+-----------------------+-----------------------+---------+--------
1 | Updates               | Updates               | Yes     | Yes
2 | openSUSE 11.2-0       | openSUSE 11.2-0       | No      | No
3 | openSUSE-11.2-Debug   | openSUSE-11.2-Debug   | No      | Yes
4 | openSUSE-11.2-Non-Oss | openSUSE-11.2-Non-Oss | Yes     | Yes
5 | openSUSE-11.2-Oss     | openSUSE-11.2-Oss     | Yes     | Yes
6 | openSUSE-11.2-Source  | openSUSE-11.2-Source  | No      | Yes

When specifying repositories in various commands, an alias, URI or repository number from the zypper repos command output can be used. A repository alias is a short version of the repository name for use in repository handling commands. Note that the repository numbers can change after modifying the list of repositories. The alias will never change by itself.

By default, details such as the URI or the priority of the repository are not displayed. Use the following command to list all details:

zypper repos -d

Adding Repositories

To add a repository, run

zypper addrepo URIalias

URI can either be an Internet repository, a network resource, a directory or a CD or DVD (see http://en.opensuse.org/openSUSE:Libzypp_URIs for details). The alias is a shorthand and unique identifier of the repository. You can freely choose it, with the only exception that is has to be unique. Zypper will issue a warning if you specify an alias that is already in use.

Removing Repositories

If you want to remove a repository from the list, use the command zypper removerepo together with the alias or number of the repository you want to delete. For example, to remove the repository listed as third entry in Example 9-1, use the following command:

zypper removerepo 3

Modifying Repositories

Enable or disable repositories with zypper modifyrepo. You can also alter the repository's properties (such as refreshing behavior, name or priority) with this command. The following command will enable the repository named updates, turn on auto-refresh and set its priority to 20:

zypper modifyrepo -er -p 20 'updates'

Modifying repositories is not limited to a single repository—you can also operate on groups:

  • -a: all repositories
  • -l: local repositories
  • -t: remote repositories
  • -m TYPE: repositories of a certain type (where TYPE can be one of the following: http, https, ftp, cd, dvd, dir, file, cifs, smb, nfs, hd, iso)

To rename a repository alias, use the renamerepo command. The following example changes the alias from Mozilla Firefox to just firefox:

zypper renamerepo 'Mozilla Firefox' firefox

9.1.5 Querying Repositories and Packages with Zypper

Zypper offers various methods to query repositories or packages. To get lists of all products, patterns, packages or patches available, use the following commands:

zypper products
zypper patterns
zypper packages
zypper patches

To query all repositories for certain packages, use search. It works on package names, or, optionally, on package summaries and descriptions. Using the wildcards * and ? with the search term is allowed. By default, the search is not case-sensitive.

zypper search firefox       # simple search for "firefox"
zypper search "*fire*"      # using wildcards
zypper search -d fire       # also search in package descriptions and summaries
zypper search -u firefox    # only display packages not already installed

To search for packages which provide a special capability, use the command what-provides. For example, if you would like to know which package provides the perl module SVN::Core, use the following command:

zypper what-provides 'perl(SVN::Core)'

To query single packages, use info with an exact package name as an argument. It displays detailed information about a package. To also show what is required/recommended by the package, use the options --requires and --recommends:

zypper info --requires MozillaFirefox

The what-provides package is similar to rpm -q --whatprovides package, but rpm is only able to query the RPM database (that is the database of all installed packages). Zypper, on the other hand, will tell you about providers of the capability from any repository, not only those that are installed.

9.1.6 Configuring Zypper

Zypper now comes with a configuration file, allowing you to permanently change Zypper's behavior (either system-wide or user-specific). For system-wide changes, edit /etc/zypp/zypper.conf. For user-specific changes, edit ~/.zypper.conf. If ~/.zypper.conf does not yet exist, you can use /etc/zypp/zypper.conf as template: copy it to ~/.zypper.conf and adjust it to your liking. Refer to the comments in the file for help about the available options.

9.1.7 Troubleshooting

In case you have problems to access packages from configured repositories (for example, zypper cannot find a certain package though you know that it exists in one the repositories), it can help to refresh the repositories with:

zypper refresh

If that does not help, try

zypper refresh -fdb

This forces a complete refresh and rebuild of the database, including a forced download of raw metadata.

9.1.8 Zypper Rollback Feature on btrfs File System

If the btrfs file system is used on the root partition and snapper is installed, zypper automatically calls snapper (via script installed by snapper) when committing changes to the file system to create appropriate file system snapshots. These snapshots can be used for reverting any changes made by zypper. For more information about snapper, see man snapper.

Zypper (and YaST) currently only make snapshots of the root filesystem. Other subvolumes cannot be configured. This feature is not supported on the default file system.

9.1.9 For More Information

For more information on managing software from the command line, enter zypper help, zypper help command or refer to the zypper(8) manpage. For a complete and detailed command reference, including cheat sheets with the most important commands, and information on how to use Zypper in scripts and applications, refer to http://en.opensuse.org/SDB:Zypper_usage. A list of software changes for the latest openSUSE version can be found at . .