Linux Basics: Zypper Usage On openSUSE

What is Zypper?

As you may know already, Zypper is most powerful command line package manager for installing, updating and removing packages as well as for managing repositories. Zypper is an open source project sponsored by Novell, and licensed under GNU GPL v2. It has been used in openSUSE since version 10.2.

Unlike other popular package managers such as APT and YUM, Zypper uses the SAT solver, which is the best available dependency solution. In my personal experience, I never ever got a dependency problem while using Zypper. If you encounter with any dependency problems, Zypper will present you multiple choices to resolve them wisely. So you never end up with any dependency problems, and it displays the output more informative in a tabular format.

One more notable feature of Zypper is it has the best syntax format. You can use commands either in full or short format.

For example, you can install VLC package using zypper in two methods.

Method 1:

# zypper install vlc

Method 2:

Also, you can use the above command in a short format as shown below.

# zypper in vlc

Here I used “in” instead of “install”.

To update system, you can use “zypper up” instead of zypper update”.

Likewise, Almost all commands have such a shortcut.

Zypper Usage

Now, let us see some practical examples of zypper usage.

The syntax of Zypper is:

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

The components enclosed in brackets are not mandatory.

Installing Packages

Zypper usage is simple and straight forward. To install a package, enter the following command:

# zypper install <package-name>

Or

# zypper in <package-name>

Example:

# zypper in vlc

Sample output:

sk@sk: ~_001

Enter “y” to continue installation. If you want to continue the installation without asking anything, use “–non-interactive” global option just before command. Zypper will not ask you any confirmation from you, and will install the packages by automatically by applying the default answers.

# zypper --non-interactive in vlc

Or

# zypper -n in vlc

The above command will install VLC package without asking anything from you by accepting the default answers.

We can use wildcards with zypper command to install packages starting with particular letters. For example, to install packages starting with letters abc, use the following command:

# zypper install 'abc*'

If you want to install the source package of a particular package, enter the following command:

# zypper source-install vlc

The above command will install the source package of vlc along with build dependencies.

If you do not want this, use -D option.

# zypper source-install -D vlc

To install only the build dependencies, use -d option.

# zypper source-install -d vlc

Removing packages

To remove a package, use either one of the following commands:

# zypper remove vlc

Or

# zypper -n remove vlc

Installing and removing packages simultaneously

Wouldn’t be better, if it possible to install and remove packages simultaneously? Yes, you can do this using +/- modifiers.

For example, To install mplayer and remove vlc simultaneously, enter the following command:

# zypper install mplayer -vlc

Just like above, you remove mplayer and install vlc simultaneously as shown below.

# zypper remove mplayer +vlc

Searching packages

To search a particular package, use the following command:

# zypper -n search vlc

Or

# zypper -n se vlc

Sample output:

sk@sk: ~_003

Installing Patches and Patterns

To install all officially released patches to your system, run the following command:

# zypper patch

To list all available patches, use the following command:

# zypper patches

Sample output:

 Loading repository data...
 Reading installed packages...
 Catalog                      | Name               | Version | Category    | Status
 -----------------------------+--------------------+---------+-------------+---------------
 openSUSE-13.1-Update         | openSUSE-2013-1002 | 1       | security    | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1003 | 1       | security    | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1004 | 1       | security    | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1005 | 1       | recommended | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1007 | 1       | recommended | Needed
 openSUSE-13.1-Update         | openSUSE-2013-1008 | 1       | recommended | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1009 | 1       | recommended | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1010 | 1       | recommended | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1011 | 1       | recommended | Needed
 openSUSE-13.1-Update         | openSUSE-2013-1012 | 1       | recommended | Not Applicable
 openSUSE-13.1-Update         | openSUSE-2013-1013 | 1       | recommended | Needed
 openSUSE-13.1-Update         | openSUSE-2013-1016 | 1       | recommended | Needed
 openSUSE-13.1-Update         | openSUSE-2013-1017 | 1       | recommended | Not Applicable
 [...]

To check the number of required patches, enter the following command:

# zypper patch-check

Sample output:

Loading repository data...
Reading installed packages...
122 patches needed (26 security patches)

Also, you can list all patches which are not yet installed, using the following command:

# zypper list-patches

Sample output:

 Loading repository data...
 Reading installed packages...
 The following software management updates will be installed first:

 Repository           | Name             | Version | Category    | Status | Summary
 ---------------------+------------------+---------+-------------+--------+---------------------------------------
 openSUSE-13.1-Update | openSUSE-2014-22 | 1       | recommended | needed | Softwarestack update for openSUSE 13.1
 openSUSE-13.1-Update | openSUSE-2014-89 | 1       | recommended | needed | Softwarestack update for openSUSE 13.1

 The following updates are also available:

 Repository           | Name               | Version | Category    | Status | Summary
 ---------------------+--------------------+---------+-------------+--------+-----------------------------------------------------------------------------------
 openSUSE-13.1-Update | openSUSE-2013-1007 | 1       | recommended | needed | gtk3: fix the scroll events from the external mouse
 openSUSE-13.1-Update | openSUSE-2013-1011 | 1       | recommended | needed | kernel-firmware: already load AMD CPU microcode in the initial ramdisk
 openSUSE-13.1-Update | openSUSE-2013-1013 | 1       | recommended | needed | systemd: Two fixes
 openSUSE-13.1-Update | openSUSE-2013-1016 | 1       | recommended | needed | SDL: resolve an issue with resizing
 openSUSE-13.1-Update | openSUSE-2013-1018 | 1       | recommended | needed | x11-tools: fix other IM can't input in gnome when ibus
 openSUSE-13.1-Update | openSUSE-2013-1019 | 1       | recommended | needed | ca-certificates: Fixed typo in advice for CA Certificates install
 openSUSE-13.1-Update | openSUSE-2013-1020 | 1       | recommended | needed | openssl: fix compression disabling side effects
 openSUSE-13.1-Update | openSUSE-2013-1031 | 1       | security    | needed | aaa_base: fixed root users default group and /etc/shadow permissions
 openSUSE-13.1-Update | openSUSE-2013-1033 | 1       | security    | needed | xorg-x11-server: fixed an overflow in trapezoid handling
 [...]

Pattern is something similar to “yum groupinstall” command that saves your time by installing a group of software packages easily without having to install them manually one by one.

To search for a group package, enter the following command:

# zypper search -t pattern

For more details about patterns, refer the following link.

Patterns: A Quick Introduction

Installing Updates

To list all new available updates, use the following command:

# zypper list-updates --all

Sample output:

Loading repository data...
Reading installed packages...
S | Repository                       | Name                                 | Current Version             | Available Version           | Arch  
--+----------------------------------+--------------------------------------+-----------------------------+-----------------------------+-------
v | openSUSE-13.1-Update             | Mesa                                 | 9.2.2-61.6.1                | 9.2.3-61.9.1                | i586  
v | openSUSE-13.1-Update             | Mesa-libEGL1                         | 9.2.2-61.6.1                | 9.2.3-61.9.1                | i586  
v | openSUSE-13.1-Update             | Mesa-libGL1                          | 9.2.2-61.6.1                | 9.2.3-61.9.1                | i586  
v | openSUSE-13.1-Update             | Mesa-libGLESv2-2                     | 9.2.2-61.6.1                | 9.2.3-61.9.1                | i586  
v | openSUSE-13.1-Update             | Mesa-libglapi0                       | 9.2.2-61.6.1                | 9.2.3-61.9.1                | i586  
v | openSUSE-13.1-Update             | ModemManager                         | 1.0.0-3.1.3                 | 1.0.0-3.4.1                 | i586  
v | openSUSE-13.1-Update             | MozillaFirefox                       | 25.0-1.1                    | 27.0-8.1                    | i586  
v | openSUSE-13.1-Update             | NetworkManager-gnome                 | 0.9.8.4-2.1                 | 0.9.8.4-20.3                | i586  
v | openSUSE-13.1-Oss                | PackageKit                           | 0.8.7-4.5.1                 | 0.8.11-2.3.1                | i586  
v | openSUSE-13.1-Oss                | PackageKit-backend-zypp              | 0.8.7-4.5.1                 | 0.8.11-2.3.1                | i586  
v | openSUSE-13.1-Oss                | PackageKit-branding-openSUSE         | 12.3-4.2.1                  | 13.1-2.2.1                  | noarch
v | openSUSE-13.1-Update             | aaa_base                             | 13.1-16.17.1                | 13.1-16.34.1                | i586  
v | openSUSE-13.1-Update             | aaa_base-extras                      | 13.1-16.17.1                | 13.1-16.34.1                | i586  
v | openSUSE-13.1-Update             | accountsservice                      | 0.6.34-2.2.1                | 0.6.34-2.4.1                | i586  
v | openSUSE-13.1-Update             | alsa                                 | 1.0.27.2-3.2.1              | 1.0.27.2-3.5.1              | i586  
v | openSUSE-13.1-Update             | apache2                              | 2.4.6-6.3.1                 | 2.4.6-6.10.1                | i586  
v | openSUSE BuildService - PHP      | apache2-mod_php5                     | 5.5.6-191.1                 | 5.5.9-212.1                 | i586  
v | openSUSE-13.1-Update             | apache2-prefork                      | 2.4.6-6.3.1                 | 2.4.6-6.10.1                | i586  
v | openSUSE-13.1-Update             | apache2-utils                        | 2.4.6-6.3.1                 | 2.4.6-6.10.1                | i586  
v | openSUSE-13.1-Update             | apparmor-docs                        | 2.8.2-4.8.1                 | 2.8.2-4.13.1                | noarch
v | openSUSE-13.1-Update             | apparmor-parser                      | 2.8.2-4.8.1                 | 2.8.2-4.13.1                | i586  
v | openSUSE-13.1-Update             | apparmor-profiles                    | 2.8.2-4.8.1                 | 2.8.2-4.13.1                | noarch
v | openSUSE-13.1-Update             | apparmor-utils                       | 2.8.1-3.1.1                 | 2.8.2-4.13.1                | noarch
v | openSUSE-13.1-Update             | at                                   | 3.1.13-5.1.2                | 3.1.13-5.4.1                | i586  
v | openSUSE-13.1-Update             | at-spi2-atk-common                   | 2.10.0-1.1                  | 2.10.2-12.1                 | i586  
v | openSUSE-13.1-Update             | at-spi2-atk-gtk2                     | 2.10.0-1.1                  | 2.10.2-12.1                 | i586  
v | openSUSE-13.1-Update             | at-spi2-core                         | 2.10.1-1.1                  | 2.10.2-12.1                 | i586  
v | openSUSE-13.1-Update             | autofs                               | 5.0.7-19.1.1                | 5.0.7-19.4.1                | i586  
v | openSUSE-13.1-Update             | bind                                 | 9.9.3P2-2.1.2               | 9.9.4P2-2.8.1               | i586  
v | openSUSE-13.1-Update             | bind-chrootenv                       | 9.9.3P2-2.1.2               | 9.9.4P2-2.8.1               | i586  
v | openSUSE-13.1-Update             | bind-libs                            | 9.9.3P2-2.1.2               | 9.9.4P2-2.8.1               | i586
[...]

To update all installed packages with newer available versions, enter the following command:

# zypper update

To update a particular package, specify the package with either the update or install command:

# zypper update vlc

Or

# zypper install vlc

Upgrade

Upgrading to a new product version (ex.12.3 to 13.1) is very easy.

Refer the following link to easily upgrade to the new product version.

How to upgrade from openSUSE 12.3 to 13.1

Repository management

To list all installed repositories, enter the following command:

# zypper repos

Or

# zypper lr

Sample output:

 #  | Alias                          | Name                               | Enabled | Refresh
 ---+--------------------------------+------------------------------------+---------+--------
 1 | download.opensuse.org-database | openSUSE BuildService - Database   | Yes     | Yes
 2 | download.opensuse.org-php      | openSUSE BuildService - PHP        | Yes     | Yes
 3 | ftp.gwdg.de-suse               | Packman Repository                 | Yes     | Yes
 4 | repo-debug                     | openSUSE-13.1-Debug                | Yes     | Yes
 5 | repo-debug-update              | openSUSE-13.1-Update-Debug         | Yes     | Yes
 6 | repo-debug-update-non-oss      | openSUSE-13.1-Update-Debug-Non-Oss | Yes     | Yes
 7 | repo-oss                       | openSUSE-13.1-Oss                  | Yes     | Yes
 8 | repo-source                    | openSUSE-13.1-Source               | Yes     | Yes
 9 | repo-update                    | openSUSE-13.1-Update               | Yes     | Yes
 10 | repo-update-non-oss            | openSUSE-13.1-Update-Non-Oss       | Yes     | Yes

To add a new repository, enter the following command:

# zypper addrepo URI alias

Example:

To install VLC repository on openSUSE 13.1, enter the following command:

# zypper addrepo http://download.videolan.org/pub/vlc/SuSE/13.1 VLC

Sample output:

 Adding repository 'VLC' .................................................................................................................................[done]
 Repository 'VLC' successfully added
 Enabled: Yes
 Autorefresh: No
 GPG check: Yes
 URI: http://download.videolan.org/pub/vlc/SuSE/13.1

To update repository list, enter command:

# zypper refresh

Or

# zypper ref

Sample output:

 Retrieving repository 'VLC' metadata -----------------------------------------------------------------------------------------------------------------------[\]

 New repository or package signing key received:
 Key ID: 33DE8FB7C8DA93D2
 Key Name: Dominique Leuenberger (VLC openSUSE Repository) <dominique-vlc.suse@leuenberger.net>
 Key Fingerprint: BC8D780DE3308581B2E0708533DE8FB7C8DA93D2
 Key Created: Monday 07 November 2011 03:33:13 PM IST
 Key Expires: Wednesday 06 November 2013 03:33:13 PM IST (EXPIRED)
 Repository: VLC

 Do you want to reject the key, trust temporarily, or trust always? [r/t/a/?] (r): a
 Retrieving repository 'VLC' metadata ....................................................................................................................[done]
 Building repository 'VLC' cache .........................................................................................................................[done]
 Repository 'openSUSE BuildService - Database' is up to date.
 Repository 'openSUSE BuildService - PHP' is up to date.
 Repository 'Packman Repository' is up to date.
 Repository 'openSUSE-13.1-Debug' is up to date.
 Repository 'openSUSE-13.1-Update-Debug' is up to date.
 Repository 'openSUSE-13.1-Update-Debug-Non-Oss' is up to date.
 Repository 'openSUSE-13.1-Oss' is up to date.
 Repository 'openSUSE-13.1-Source' is up to date.
 Repository 'openSUSE-13.1-Update' is up to date.
 Repository 'openSUSE-13.1-Update-Non-Oss' is up to date.
 All repositories have been refreshed.

The alias is a shorthand and unique identifier of the repository. You can choose the alias name as per your liking, 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.

To see, if VLC repository is added successfully, enter the following command:

# zypper repos

Or

# zypper lr

Sample output:

 #  | Alias                          | Name                               | Enabled | Refresh
 ---+--------------------------------+------------------------------------+---------+--------
 1 | VLC                            | VLC                                | Yes     | No
 2 | download.opensuse.org-database | openSUSE BuildService - Database   | Yes     | Yes
 3 | download.opensuse.org-php      | openSUSE BuildService - PHP        | Yes     | Yes
 4 | ftp.gwdg.de-suse               | Packman Repository                 | Yes     | Yes
 5 | repo-debug                     | openSUSE-13.1-Debug                | Yes     | Yes
 6 | repo-debug-update              | openSUSE-13.1-Update-Debug         | Yes     | Yes
 7 | repo-debug-update-non-oss      | openSUSE-13.1-Update-Debug-Non-Oss | Yes     | Yes
 8 | repo-oss                       | openSUSE-13.1-Oss                  | Yes     | Yes
 9 | repo-source                    | openSUSE-13.1-Source               | Yes     | Yes
 10 | repo-update                    | openSUSE-13.1-Update               | Yes     | Yes
 11 | repo-update-non-oss            | openSUSE-13.1-Update-Non-Oss       | Yes     | Yes

As you see in the above output, the VLC repository has been successfully added to alias VLC and repository number 1 (one).

To remove a repository, enter the following command with alias name or repository number as shown below.

# zypper removerepo VLC

or

# zypper rr VLC

Or

# zypper removerepo 1

Or

# zypper rr 1

Sample output:

 Removing repository 'VLC' ...............................................................................................................................[done]
 Repository 'VLC' has been removed.

Modifying Repositories

Like adding and removing repositories, You can enable, disable with modifyrepo and rename repositories with renamerepo commands.

To disable a repository (ex.VLC) enter the following command:

# zypper modifyrepo -d 'VLC'

Sample output:

Repository 'VLC' has been successfully disabled.

Now check whether VLC repository is disabled using “zypper lr command:

# zypper lr

Sample output:

 #  | Alias                          | Name                               | Enabled | Refresh
 ---+--------------------------------+------------------------------------+---------+--------
  1 | VLC                            | VLC                                | No      | Yes    
 2 | download.opensuse.org-database | openSUSE BuildService - Database   | Yes     | Yes
 3 | download.opensuse.org-php      | openSUSE BuildService - PHP        | Yes     | Yes
 4 | ftp.gwdg.de-suse               | Packman Repository                 | Yes     | Yes
 5 | repo-debug                     | openSUSE-13.1-Debug                | Yes     | Yes
 6 | repo-debug-update              | openSUSE-13.1-Update-Debug         | Yes     | Yes
 7 | repo-debug-update-non-oss      | openSUSE-13.1-Update-Debug-Non-Oss | Yes     | Yes
 8 | repo-oss                       | openSUSE-13.1-Oss                  | Yes     | Yes
 9 | repo-source                    | openSUSE-13.1-Source               | Yes     | Yes
 10 | repo-update                    | openSUSE-13.1-Update               | Yes     | Yes
 11 | repo-update-non-oss            | openSUSE-13.1-Update-Non-Oss       | Yes     | Yes

As you see in the above output, VLC repository has been disabled.

Likewise, to enable a repository, use following command:

# zypper modifyrepo -e 'VLC'

Sample output:

Repository 'VLC' has been successfully enabled.

You can also change the repository’s name, priority and refreshing behavior with modifyrepo command.

To enable auto refresh, use “-r” switch:

# zypper modifyrepo -r 'VLC'

Sample output:

Autorefresh has been enabled for repository 'VLC'.

To change the priority of a repository, use “-p” switch.

# zypper modifyrepo -p 5 'VLC'

As per the above command, the priority of the VLC repository has been set to 5.

To rename a repository alias, use the renamerepo command. The following command renames the alias from VLC to VLC-Media-player:

# zypper renamerepo 'VLC' VLC-Media-player

Sample output:

Repository 'VLC' renamed to 'VLC-Media-player'

Check for the changes with the  following command:

# zypper lr

Sample output:

#  | Alias                          | Name                               | Enabled | Refresh
---+--------------------------------+------------------------------------+---------+--------
 1 | VLC-Media-player               | VLC                                | Yes     | Yes    
 2 | download.opensuse.org-database | openSUSE BuildService - Database   | Yes     | Yes    
 3 | download.opensuse.org-php      | openSUSE BuildService - PHP        | Yes     | Yes    
 4 | ftp.gwdg.de-suse               | Packman Repository                 | Yes     | Yes    
 5 | repo-debug                     | openSUSE-13.1-Debug                | Yes     | Yes    
 6 | repo-debug-update              | openSUSE-13.1-Update-Debug         | Yes     | Yes    
 7 | repo-debug-update-non-oss      | openSUSE-13.1-Update-Debug-Non-Oss | Yes     | Yes    
 8 | repo-oss                       | openSUSE-13.1-Oss                  | Yes     | Yes    
 9 | repo-source                    | openSUSE-13.1-Source               | Yes     | Yes    
10 | repo-update                    | openSUSE-13.1-Update               | Yes     | Yes    
11 | repo-update-non-oss            | openSUSE-13.1-Update-Non-Oss       | Yes     | Yes    

We came to the end of the tutorial. I think I covered all the important aspects of Zypper command usage. This is not a complete guide, but I hope you will get the basic idea of Zypper usage.

To know more about zypper usage, refer man pages:

# man zypper

And,

# zypper --help

For the complete and comprehensive guide, refer the official help documents.

Sources & References:

Zypper Usage