zypper package management tool examples for managing packages on SUSE Linux

zypper package management tool examples for managing packages on SUSE Linux

zypper title

Introduction

The zypper package management tool performs the same function for SUSE Linux as yum and apt perform for RedHat and Debian based systems respectively. SUSE (Software and System Entwicklung (Germany) meaning Software and System Development, in English) Linux runs on top of the open-source Linux kernel. The SUSE Linux distribution is available in two variants, a community-driven project named OpenSUSE and a commercial version named SUSE Linux Enterprise. Zypper and YaST are the two command line tools used for package management in OpenSUSE and SUSE Enterprise Linux platforms. Both tools work on top of RPM. Zypper uses the libzypp library which provides the ZYpp package manager. ZYpp is a Linux software management engine and open source project originally sponsored by Novell and provides a powerful dependency resolver and a convenient package management API.

In this article, we will show you how to use the zypper package management tool to search for, install and remove packages along with a few other uses. We will be using the SUSE Enterprise Linux version 12 for the examples demonstrated in this article.

 

Example 1: Search for a Specific Package
To search for a package from a repository we use the zypper search command followed by the package name we want to search for. To demonstrate, let’s search for the package name git.

linuxnix:~ # zypper search git
Loading repository data...
Reading installed packages...

S | Name | Summary | Type
--+----------+-----------------------------------------------------+-----------
| git | Fast, scalable, distributed revision control system | srcpackage
| git-core | Core git tools | package
linuxnix:~ #

This gives us the two search results that zypper was able to find matching our search criterion.
Note that you can use wildcards while searching for packages using zypper.

 

Example 2: Install a package
We use the zypper install command followed by the package name to install a package. Let’s install the git-core package to demonstrate.

linuxnix:~ # zypper install git-core
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 NEW packages are going to be installed:
git-core perl-Error
2 new packages to install.
Overall download size: 4.4 MiB. Already cached: 0 B. After the operation, additional 29.6 MiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package perl-Error-0.17021-1.18.noarch (1/2), 28.3 KiB ( 49.8 KiB unpacked)
Retrieving package git-core-2.12.3-26.1.x86_64 (2/2), 4.4 MiB ( 29.5 MiB unpacked)
Checking for file conflicts: .........................................................................................................................................................................[done]
(1/2) Installing: perl-Error-0.17021-1.18.noarch .....................................................................................................................................................[done]
(2/2) Installing: git-core-2.12.3-26.1.x86_64 ........................................................................................................................................................[done]
linuxnix:~ #

 

Example 3: Uninstall a package
To uninstall or erase a package, we use the zypper remove command followed by the package name. Let’s uninstall the git-core package we installed in the previous example.

linuxnix:~ # zypper remove git-core
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following package is going to be REMOVED:
git-core

1 package to remove.
After the operation, 29.5 MiB will be freed.
Continue? [y/n/...? shows all options] (y): y
(1/1) Removing git-core-2.12.3-26.1.x86_64 ...........................................................................................................................................................[done]
linuxnix:~ #

Observe that zypper remove command did not remove that dependencies that were installed during the zypper install command.

 

Example 4: Query information about a package
To view available information about a package, we use the zypper info command followed by the package name. Let’s query information about that git-core package.

linuxnix:~ # zypper info git-core
Loading repository data...
Reading installed packages...
Information for package git-core:
---------------------------------
Repository : SLES12-SP3-12.3-0
Name : git-core
Version : 2.12.3-26.1
Arch : x86_64
Vendor : SUSE LLC 
Support Level : Level 3
Installed Size : 29.5 MiB
Installed : No
Status : not installed
Source package : git-2.12.3-26.1.src
Summary : Core git tools
Description :
Git is a fast, scalable, distributed revision control system with an
unusually rich command set that provides both high-level operations and
full access to internals.
These are the core tools with minimal dependencies.

 

Example 5: Check for available updates
To list packages available for update, use the zypper list-updates command.

linuxnix:~ # zypper list-updates
Loading repository data...
Reading installed packages...
No updates found.
linuxnix:~ #

Since I’m using the latest version of the OS available, zypper didn’t find any updates available.

 

Example 6: Update a single package
To update a package, we use the zypper update command followed by the package name. Let’s try this out on the openssh package.

linuxnix:~ # zypper update openssh
Loading repository data...
Reading installed packages...
No update candidate for 'openssh-7.2p2-69.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
linuxnix:~ #

 

Example 7: Update entire system
To update all packages on the system, use the zypper update command.

linuxnix:~ # zypper update
Loading repository data...
Reading installed packages...
Nothing to do.
linuxnix:~ #

 

Example 8: Update distribution
The zypper dup command will upgrade your system from the current SUSE Linux version to the latest version available through the repositories you are connected to.

linuxnix:~ # zypper dup
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
Nothing to do.

Since I’m using the latest version, there was nothing for zypper to update when I ran the command.

 

Example 9: Non-interactive package management commands
When we install or remove a package using zypper, we get prompted for confirmation. To skip this prompt and let zypper assume the reply as yes, we can use the –non-interactive option with the zypper command. Let’s demonstrate this usage by installing and removing the git-core package while also using the –non-interactive flag.

linuxnix:~ # zypper --non-interactive install git-core
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
git-core

1 new package to install.
Overall download size: 4.4 MiB. Already cached: 0 B. After the operation, additional 29.5 MiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package git-core-2.12.3-26.1.x86_64 (1/1), 4.4 MiB ( 29.5 MiB unpacked)
Checking for file conflicts: .........................................................................................................................................................................[done]
(1/1) Installing: git-core-2.12.3-26.1.x86_64 ........................................................................................................................................................[done]
linuxnix:~ #
linuxnix:~ # zypper --non-interactive remove git-core
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following package is going to be REMOVED:
git-core

1 package to remove.
After the operation, 29.5 MiB will be freed.
Continue? [y/n/...? shows all options] (y): y
(1/1) Removing git-core-2.12.3-26.1.x86_64 ...........................................................................................................................................................[done]
linuxnix:~ #

 

Example 10: List repositories
To list available repositories being used by zypper to search for packages, we use the zypper lr command.
Here’s an example:

linuxnix:~ # zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias | Name | Enabled | GPG Check | Refresh
--+-------------------+-------------------+---------+-----------+--------
1 | SLES12-SP3-12.3-0 | SLES12-SP3-12.3-0 | Yes | (r ) Yes | No
linuxnix:~ #

 

Example 11: Refresh a repository
We should periodically refresh our system repository cache to ensure that all the latest updates made to the repositories are available to the system.
To do this we use the zypper refresh command as shown below.

linuxnix:~ # zypper refresh
Repository 'SLES12-SP3-12.3-0' is up to date.
All repositories have been refreshed.
linuxnix:~ #

 

Example 12: Clear zypper cache
If you wish to clean zypper cache, use the following command:

linuxnix:~ # zypper clean
All repositories have been cleaned up.
linuxnix:~ #

 

Example 13: Install patches
You can also use zypper to install patches on your system.
First, view all available patches using patches option as shown below:

linuxnix:~ # zypper patches
Loading repository data...
Reading installed packages...
No needed patches found.
linuxnix:~ #

If any patches were available, we could install a specific patch displayed in the output of the above command using the following command syntax:

zypper patch 

 

Example 14: View history
Zypper does not have a history sub-command like yum does but instead it stores its history in a plain text file /var/log/zypp/history which we can read. Let’s take a look at a snippet of the file.

linuxnix:~ # cat /var/log/zypp/history | grep -Ev '^#' | tail
2017-12-26 02:24:47|install|gnome-shell-extensions-common-lang|3.20.1-24.19.45|noarch||SLES12-SP3-12.3-0|c2edecff042b04bd673446d7fcf52aab3196c5a501401180198831523ab29d2c|
2017-12-26 02:24:49|install|gdm|3.10.0.1-52.5|x86_64||SLES12-SP3-12.3-0|eb9e4f92fe51b95319b51cdb7b1b85f35b13ed7ae1382ed8f20649acb76aba93|
2017-12-26 02:24:49|install|patterns-sle-gnome-basic|12-5.8|x86_64||SLES12-SP3-12.3-0|bb49e41309d45cdd7a8251da72974315391ba533fb20d1c82862790d02eebbcf|
2017-12-26 02:24:49|install|gdm-lang|3.10.0.1-52.5|noarch||SLES12-SP3-12.3-0|999fa1d87c3db372e247cd0df4625d90076ea4f07d2c71470683eca411782048|
2017-12-26 02:27:16|radd |SLES12-SP3-12.3-0|cd:///?devices=/dev/disk/by-id/ata-VMware_Virtual_SATA_CDRW_Drive_01000000000000000001|
2017-12-26 21:18:00|command|root@linuxnix|'zypper' 'install' 'git-core'|
2017-12-26 21:18:01|install|perl-Error|0.17021-1.18|noarch||SLES12-SP3-12.3-0|3790538ea2d409479f39a9c1f3677c724da4ce213cda7da10f60958e81da87ef|
2017-12-26 21:18:04|install|git-core|2.12.3-26.1|x86_64|root@linuxnix|SLES12-SP3-12.3-0|91851797d1fe372d3af00271f27974aba7b1e28255c53aed4fb493f4bdf3f409|
2017-12-26 21:18:58|command|root@linuxnix|'zypper' 'remove' 'git-core'|
2017-12-26 21:18:58|remove |git-core|2.12.3-26.1|x86_64|root@linuxnix|

 

Conclusion

This concludes our coverage of the zypper package management tool where we demonstrated how to use zypper to install, remove, update, search for and obtain information about packages. We also showed you how to view the history of package management operations performed using zypper.

The post zypper package management tool examples for managing packages on SUSE Linux appeared first on The Linux Juggernaut.

Administration Basics LinuxNix suse zypper