≡ Menu

20 Zypper Command Examples to Manage Packages on SUSE Linux

SUSE Linux Logoyum is for CentOS and Redhat.

apt-get is for Debian and Ubuntu.

In the same way, zypper is for SUSE Linux.

Zypper is a command line tool for package management in OpenSUSE and SUSE Enterprise Linux platforms.

On a high-level, you can manage two different things using zypper command:

  1. Manage Packages: Zypper is used to install, remove, update and query the software packages of local or remote media.
  2. Manage Repositories: Zypper also has the ability to work with repositories. You can add, remove, enable or disable repositories from command line. It also has the ability to prioritize your repositories during installation process.

I. Manage Packages using Zypper

1. Install a Package using zypper

To install a package using zypper command, use the following syntax:

zypper install <package Name>

For example, to install the Mozilla firefox and all its dependencies, execute the following:

# zypper install MozillaFirefox
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following NEW packages are going to be installed:
  MozillaFirefox MozillaFirefox-branding-SLED
The following packages are not supported by their vendor:
  MozillaFirefox MozillaFirefox-branding-SLED
2 new packages to install.
Overall download size: 964.0 KiB. After the operation, additional 3.4 MiB will be used.
Continue? [y/n/?] (y): y
Retrieving package MozillaFirefox-3.6.16-0.2.1.x86_64 (1/2), 949.0 KiB (3.4 MiB unpacked)
Retrieving: MozillaFirefox-3.6.16-0.2.1.x86_64.rpm [done]
Installing: MozillaFirefox-3.6.16-0.2.1 [done]
Retrieving package MozillaFirefox-branding-SLED-3.5-1.1.5.x86_64 (2/2), 15.0 KiB (34.0 KiB unpacked)
Retrieving: MozillaFirefox-branding-SLED-3.5-1.1.5.x86_64.rpm [done]
Installing: MozillaFirefox-branding-SLED-3.5-1.1.5 [done]

2. Install Source Package

To install source package in a repository, use the source-install option as shown below.

# zypper source-install apache2-mod_nss
Reading installed packages...
Loading repository data...
Resolving package dependencies...
Retrieving package mozilla-nss-devel-3.12.8-1.2.1.x86_64 (2/3), 473.0 KiB (2.6 MiB unpacked)
Retrieving: mozilla-nss-devel-3.12.8-1.2.1.x86_64.rpm [done]
Installing: mozilla-nss-devel-3.12.8-1.2.1 [done]
Retrieving: apache2-mod_nss-1.0.8-17.5.src.rpm [done]

3. Update a Package

Once a package is installed, you can upgrade it to a new version when it becomes available using the update command as shown below.

The following will upgrade only MozillaFirefox package.

zypper update MozillaFirefox

The following will upgrade all the packages on your system to the latest version.

zypper update

You can also view all the available updates using the list-updates option as shown below.

zypper list-updates

4. System Wide Full Distribution Upgrade

To perform a full distribution upgrade on the system, use the dup option along with zypper as shown below:

# zypper dup
Warning: You are about to do a distribution upgrade with all enabled repositories. Make sure these repositories are compatible before you continue. See 'man zypper' for more information about this command.
Loading repository data...
Reading installed packages...
Computing distribution upgrade...

The following NEW packages are going to be installed:
  drbd-xen libsoftokn3-32bit mozilla-nspr-32bit mozilla-nss-32bit mozilla-nss-certs-32bit suseRegister xen yast2-registration
  yast2-registration-branding-SLE
The following packages are going to be upgraded:
  libfreebl3-32bit libnsssharedhelper0 libnsssharedhelper0-32bit
The following packages are going to change vendor:
  libfreebl3-32bit           SUSE LINUX Products GmbH, Nuernberg, Germany -> openSUSE Build Service
  libnsssharedhelper0        SUSE LINUX Products GmbH, Nuernberg, Germany -> openSUSE Build Service
  libnsssharedhelper0-32bit  SUSE LINUX Products GmbH, Nuernberg, Germany -> openSUSE Build Service

5. Delete a Package

To remove a package, use the remove option as shown below. This will also remove all the depedencies.

# zypper remove MozillaFirefox
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following packages are going to be REMOVED:
  MozillaFirefox MozillaFirefox-branding-SLED
2 packages to remove.
After the operation, 3.4 MiB will be freed.
Continue? [y/n/?] (y): y
Removing MozillaFirefox-branding-SLED-3.5-1.1.5 [done]
Removing MozillaFirefox-3.6.16-0.2.1 [done]

6. Search for a Specific Package

To search for a package from a repository use the following command. You can also use wild card in the keyword.

In this example, it will search for all packages that starts with the keyword “usb”.

# zypper search usb*
Loading repository data...
Reading installed packages...
S | Name           | Summary                                                        | Type
--+----------------+----------------------------------------------------------------+--------
  | usb_modeswitch | A mode switching tool for controlling multiple-device USB gear | package
i | usbutils       | Tools and libraries for USB devices                            | package

7. View Details about a Package

To display information about a specific package, use the info option with zypper as shown below:

# zypper info usbutils
Loading repository data...
Reading installed packages...
Information for package usbutils:
Repository: @System
Name: usbutils
Version: 0.73-38.19
Arch: x86_64
Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Support Level: unknown
Installed: Yes
Status: up-to-date
Installed Size: 461.0 KiB
Summary: Tools and libraries for USB devices
Description:
This package contains a utility for inspecting devices connected to USB
ports.
It requires kernel version 2.3.99-pre7 or newer, or the USB backport
which was introduced in 2.2.18 (supporting the /proc/bus/usb
interface).

8. Install Patches using Zypper

You can also use zypper to install patches on your system.

First, view all available patches using patches option as shown below:

zypper patches

Next, you can install a specific patch from the above output using the patch option as shown below.

zypper patch <patch name>

9. Lock a Specific Package

Package lock prevents the changes to the package on the system. Once this lock is set, you cannot remove, upgrade the package.

The following example shows how to setup the package locks and remove it when needed.

Add a package lock to ypbind package using “al” option. al stands for “Add Lock”

# zypper al ypbind
Specified lock has been successfully added.

To view all the packages that are locked, use the “ll” option. ll stands for “List Locks”. The following output indicates that “ypbind” package is currently locked, and you cannot remove or upgrade this package.

# zypper ll
# | Name   | Type    | Repository
--+--------+---------+-----------
1 | ypbind | package | (any)

10. Remove Lock from a Package

Remove the package lock from ypbind package using “rl” option. rl stands for “Remove Lock”

# zypper rl ypbind
Loading repository data...
Reading installed packages...
1 lock has been successfully removed.

As you see below, currently no packages are locked.

# zypper ll
There are no package locks defined.

II. Manage Repositories using Zypper

11. Add a Repository using Zypper

The general syntax to add a repository using http URI is as follows:

zypper addrepo <options> <URI> <alias>

For example, to add a repository using the URI do the following:

# zypper addrepo --check --refresh --name "Mozilla-repo" http://download.opensuse.org/repositories/mozilla/SLE_11/ "Mozillarepo"
Adding repository 'Mozilla-repo' [done]
Repository 'Mozilla-repo' successfully added
Enabled: Yes
Autorefresh: Yes
URI: http://download.opensuse.org/repositories/mozilla/SLE_11/

12. Create a Local Repository

You can also create a local repository from a local directory on your server that has all the rpm files using the following syntax:

zypper addrepo <Path_to_dir> <Repo Name>

For example, to add a repository called myrepo with the local directory that has all the rpms use the below command:

# zypper addrepo /var/stormgt/dsminst mylocalrepo
Adding repository 'mylocalrepo' [done]
Repository 'mylocalrepo' successfully added
Enabled: Yes
Autorefresh: No
URI: dir:///var/stormgt/dsminst
# zypper search --repo mylocalrepo
Loading repository data...
Reading installed packages...
S | Name        | Summary                                 | Type
--+-------------+-----------------------------------------+--------
i | TIVsm-API   | the API                                 | package
i | TIVsm-API64 | the API                                 | package
i | TIVsm-BA    | the Backup Archive Client               | package
i | gskcrypt32  | IBM GSKit Cryptography Runtime          | package
i | gskcrypt64  | IBM GSKit Cryptography Runtime          | package
i | gskssl32    | IBM GSKit SSL Runtime With Acme Toolkit | package
i | gskssl64    | IBM GSKit SSL Runtime With Acme Toolkit | package

You can also add the NFS or FTP location to the repositories using the above command.

13. View Repositories

Your can view all the repositories using the following zypper command:

# zypper lr
# | Alias                                            | Name                                             | Enabled | Refresh
--+--------------------------------------------------+--------------------------------------------------+---------+--------
1 | Mozillarepo                                      | Mozilla-repo                                     | Yes     | Yes
2 | SUSE-Linux-Enterprise-Server-11-SP1 11.1.1-1.152 | SUSE-Linux-Enterprise-Server-11-SP1 11.1.1-1.152 | Yes     | Yes

To display the complete URI for the repo, use the following:

# zypper lr --uri
# | Alias                                            | Name                                             | Enabled | Refresh | URI
--+--------------------------------------------------+--------------------------------------------------+---------+---------+----------------------------------------------------------
1 | Mozillarepo                                      | Mozilla-repo                                     | Yes     | Yes     | http://download.opensuse.org/repositories/mozilla/SLE_11/
2 | SUSE-Linux-Enterprise-Server-11-SP1 11.1.1-1.152 | SUSE-Linux-Enterprise-Server-11-SP1 11.1.1-1.152 | Yes     | Yes     | http://19.106.65.64/FUSELinux/600RC0

14. Search Packages Inside Repository

To list all the packages from the specific repository, use the following command:

# zypper search --repo Mozillarepo
Loading repository data...
Reading installed packages...

S | Name                                 | Summary                                                                 | Type
--+--------------------------------------+-------------------------------------------------------------------------+-----------
i | MozillaFirefox                       | Mozilla Firefox Web Browser                                             | package
i | MozillaFirefox-branding-SLED         | SLED branding of MozillaFirefox                                         | package  
  | MozillaFirefox-branding-openSUSE     | openSUSE branding of MozillaFirefox                                     | package
  | MozillaFirefox-branding-openSUSE     | openSUSE branding of MozillaFirefox                                     | srcpackage

15. Rename a Repository

To rename any repository, use the renamerepo option.

In this example, the repo name “mylocalrepo” has been renamed to “LOCALRPM-Repo”

# zypper renamerepo mylocalrepo LOCALRPM-Repo
Repository 'mylocalrepo' renamed to 'LOCALRPM-Repo'.

16. Delete a Repository

To delete a repository use the removerepo option as shown below.

# zypper removerepo LOCALRPM-Repo
Removing repository 'mylocalrepo' [done]
Repository 'mylocalrepo' has been removed.

17. Backup a Repository

You can backup the repository file that contains the list of repositories using the export option as shown below. This will store the repository list in the backup.repo file.

# zypper lr --export /var/tmp/backup.repo
Repositories have been successfully exported to /var/tmp/backup.repo.

18. Add Repositories from a Backup

If you have a previously exported repository file, you can use that to add new repositories using addrepo command as shown below.

zypper addrepo /var/tmp/backup.rep

19. Disable or Enable a Repository

To disable the repository use the modify repo option with -d flag as shown below. This will disable the Mozilla repository.

# zypper modifyrepo -d Mozillarepo
Repository 'Mozillarepo' has been successfully disabled.

To enable the repository that was previously disabled, use the -e flag along with modifyrepo option as shown below.

# zypper modifyrepo -e Mozillarepo
Repository 'Mozillarepo' has been successfully enabled.

20. Refresh a Repository

It is very important to refresh a repository, when it becomes out of date. You can either do a manual refresh as shown in the below example or set to refresh automatically when needed.

# zypper refresh Mozillarepo
Repository 'Mozilla-repo' is up to date.
Specified repositories have been refreshed.

To set auto refresh option for a specific repository, please use the command as shown in below example:

# zypper modifyrepo --refresh mylocalrepo
Autorefresh has been enabled for repository 'mylocalrepo'.
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • dipanjan mukherjee April 14, 2015, 3:45 am

    Excellent…. Very nice article.

  • Shrikanya April 14, 2015, 2:23 pm

    Very nice article. Thank you for sharing

  • Chandan April 17, 2015, 10:08 pm

    Very Good Article.

  • Arun April 22, 2015, 10:24 pm

    Hi Ramesh Natarajan,

    Each and every article looks great to learn.

    Do we have any article on how to write scripts also ?
    I’m interested to learn how to write scripts.

    Can you guide me.

    Thanks
    Arun

  • Jim August 4, 2015, 11:32 am

    Thanks for the wonderful article. When I try to install python-devel, I get the below error. Can you tell me how I should resolve this.

    /home/Installs/ODBC_14.10 # zypper in python-devel
    Loading repository data…
    Reading installed packages…
    ‘python-devel’ not found.
    Resolving package dependencies…

    Nothing to do.

  • Srinath August 28, 2015, 10:41 am

    Hi,
    I have small doubt that, how to configure zapped configuration…. Is it similar to YUM in Rhel.. Please let me… Thank you….

  • Vincent Moutoussamy January 4, 2016, 4:50 am

    Hi,
    very nice article man !
    However it’s openSUSE not OpenSUSE ; ).
    Regards,

  • Narottam Dey January 10, 2016, 9:34 pm

    Hi, Can u help me to install R 3.2.3 in opensuse platform
    regards

  • David Berryman March 17, 2019, 8:12 pm

    Thanks mate, just what I needed.
    Good job.