How to use the command 'zypper' (with examples)
- Linux
- December 25, 2023
The ‘zypper’ command is a package management utility used in SUSE and openSUSE operating systems. It allows users to install, update, remove, and manage packages in a convenient and efficient way. In this article, we will explore various use cases of the ‘zypper’ command with examples.
Use case 1: Synchronize list of packages and versions available
Code:
zypper refresh
Motivation: It is important to keep the package list up to date in order to ensure that you have access to the latest versions and packages available. By synchronizing the package list, you can make sure that you have the most recent information about package availability.
Explanation: The ‘zypper refresh’ command is used to synchronize the package list with the repositories configured in the system. It fetches the latest package metadata from the repositories and updates the package list.
Example output:
Repository 'openSUSE-Leap-15.3-Oss' is up to date.
Repository 'openSUSE-Leap-15.3-Update' is up to date.
Repository 'openSUSE-Leap-15.3-Non-Oss' is up to date.
Repository 'openSUSE-Leap-15.3-Debug-Update' is up to date.
All repositories have been refreshed.
Use case 2: Install a new package
Code:
zypper install package
Motivation: Installing new packages is a common task in a Linux environment. Whether you need to install additional software or dependencies for an application, the ‘zypper install’ command makes it easy to add new packages to your system.
Explanation: The ‘zypper install’ command installs a new package on your system. You need to replace ‘package’ with the name of the package you want to install. The command will automatically resolve dependencies and download the necessary files from the configured repositories.
Example output:
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 1 NEW package is going to be installed:
wget
Overall download size: 1.2 MiB. Already cached: 0 B. After the operation, additional 5.9 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package wget-1.20.3-lp152.19.1.x86_64 (1/1), 1.2 MiB (5.9 MiB unpacked)
Retrieving: wget-1.20.3-lp152.19.1.x86_64.rpm .....................................[done (305.0 KiB/s)]
Installing: wget-1.20.3-lp152.19.1 ....................................................................[done]
Use case 3: Remove a package
Code:
zypper remove package
Motivation: There may be situations where you want to remove a package from your system. It could be due to the package being no longer needed, conflicts with other packages, or simply to free up disk space. The ‘zypper remove’ command allows you to easily uninstall packages.
Explanation: The ‘zypper remove’ command removes a package from your system. Replace ‘package’ with the name of the package you want to remove. The command will also remove any dependencies that are no longer needed.
Example output:
Resolving package dependencies...
The following 1 package is going to be REMOVED:
wget
1 package to remove.
After the operation, 5.9 MiB will be freed.
Continue? [y/n/v/...? shows all options] (y): y
Removing wget-1.20.3-lp152.19.1.x86_64 ................................................................................[done]
Use case 4: Upgrade installed packages to the newest available versions
Code:
zypper update
Motivation: Keeping your system up to date with the newest versions of installed packages is important for security, bug fixes, and feature enhancements. The ‘zypper update’ command simplifies the process of upgrading installed packages to their latest available versions.
Explanation: The ‘zypper update’ command checks for updates for all installed packages and upgrades them to the newest available versions. It fetches the updated packages from the configured repositories and installs them.
Example output:
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
The following 10 NEW packages are going to be installed:
bash-completion-doc docbook_5 ghostscript-fonts-std git-core git-core-docs ghc http-parser-2.9.2 libqt5-qtquickcontrols2-imports oxygen-sounds qtbase-common-doc
10 new packages to install.
Overall download size: 15.6 MiB. Already cached: 0 B. After the operation, additional 93.3 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package toastui-1.15.3-lp153.1.1.noarch (1/10), 13.7 KiB (16.0 KiB unpacked)
...
Installing: toastui-1.15.3-lp153.1.1.noarch ................................................................................[done]
...
Use case 5: Search package via keyword
Code:
zypper search keyword
Motivation: When you want to find packages related to a specific topic, functionality, or keyword, the ‘zypper search’ command allows you to search for packages matching a keyword. This is useful for discovering new software or finding packages that may have similar names to what you are looking for.
Explanation: The ‘zypper search’ command searches for packages that match the specified keyword. Replace ‘keyword’ with the term you want to search for. The command will display a list of packages that match the keyword, along with additional information such as the package name, summary, and version.
Example output:
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+-------------------------------+--------------------------------------------------------------+-----------
| python3-django-contact-form | A generic contact-form application for Django | package
| python3-django-contact-form3 | A generic contact-form application for Django | package
| python3-django-forms-bootstrap | Bootstrap support for Django form rendering | package
| python3-django-formtools | A set of high-level abstractions for Django forms | package
| python3-django-formtools-doc | Documentation for python3-django-formtools | package
| python3-django-webtest | Webtest support for Django | package
| python3-flufl-i18n | I18N helpers for Python projects | package
Use case 6: Show information related to configured repositories
Code:
zypper repos --sort-by-priority
Motivation: Understanding the repositories configured on your system is important for managing packages and ensuring that you have access to the desired software. The ‘zypper repos’ command provides information about the configured repositories, their priorities, and other relevant details.
Explanation: The ‘zypper repos –sort-by-priority’ command displays information about the repositories configured on your system, sorted by priority. It provides details such as the repository name, enabled status, URI, priority, and type.
Example output:
# | Alias | Name | Enabled | GPG Check | Refresh | Priority | URI
--+--------------------------------+------------------------------------------+---------+-----------+---------+----------+--------------------------------------------
| openSUSE-Leap-15.3-Oss | openSUSE-Leap-15.3-Oss | Yes | (r ) Yes | Yes | 99 | http://download.opensuse.org/distribution/leap/15.3/repo/oss/
| openSUSE-Leap-15.3-Update | openSUSE-Leap-15.3-Update | Yes | (r ) Yes | Yes | 99 | http://download.opensuse.org/update/leap/15.3/oss/
| openSUSE-Leap-15.3-Non-Oss | openSUSE-Leap-15.3-Non-Oss | Yes | (r ) Yes | Yes | 99 | http://download.opensuse.org/distribution/leap/15.3/repo/non-oss/
| openSUSE-Leap-15.3-Debug-Update| openSUSE-Leap-15.3-Debug-Update | No | ---- | ---- | 99 | http://download.opensuse.org/debug/update/leap/15.3/oss/
Conclusion:
The ‘zypper’ command provides a comprehensive package management solution for SUSE and openSUSE users. By mastering the various use cases of the command, you can easily install, update, remove, and search for packages on your system. The examples in this article demonstrate the versatility and power of the ‘zypper’ command, making it an indispensable tool for managing packages in SUSE and openSUSE.