Zypper is a powerful command-line package manager for SUSE and openSUSE Linux. It can be used to install, update, remove, and manage packages on your system. Zypper also provides features for managing repositories, resolving dependencies, and checking for security updates. This detailed guide presents a curated list of 16 useful Zypper Linux command examples for efficient package management in SUSE Linux operating system.
Through out this guide, you will learn how to use zypper to perform common tasks such as installing packages, updating your system, and removing packages. You will also learn about some of the more advanced features of zypper, such as managing repositories and resolving dependency conflicts.
By the end of this guide, you will be an expert in using zypper, with a handy Zypper command cheat sheet to help you along the way.
Heads Up: Some of the zypper and its sub-commands require root
user or sudo
privilege. Run the commands with sudo
privilege or with the root
user.
Table of Contents
Quick Lab Setup for Testing
To learn how to use the zypper command, you can install the OpenSUSE distribution on physical hardware or use a hypervisor solution like KVM, Vagrant, Virtualbox, or VMware.
My preferred way to set up OpenSUSE distribution for testing is to use Vagrant. If you have no idea about Vagrant, then we have an article on "Getting Started with Vagrant" to help you out.
If you already have Vagrant installed in your system, create a new file with the name 'Vagrantfile
' and add the following content to it.
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "opensuse/Tumbleweed.x86_64" end
Now run the following command to spin up the VM:
$ vagrant up
Connect to the VM by running the following command.
$ vagrant ssh
Or,
$ vagrant ssh id
Now that you have a machine to try out zypper commands, let's jump into learning zypper commands.
Zypper Terminal Mode
You can work with zypper in two modes.
The first and recommended mode is to run the zypper command from the linux terminal directly which is also shown in examples of this article.
The second way is to use the zypper shell
or sh
command to launch an interactive session where you can run zypper commands directly.
$ zypper shell
Or,
$ zypper sh
Zypper Command Examples
1. Accessing Help for Zypper Command
Remembering all the commands is not an easy task. Every linux command comes with a help section and man page to ease the usage. Similarly, the zypper
command comes with a help section which is nicely formatted with subsections and a great place to start with for starters.
Zypper has global options and also sub-commands which you will learn in detail in the upcoming sections.
To display zypper command help section, run:
$ zypper help
In the upcoming sections you will learn about subcommands like repos, install, search, etc. For each subcommand, there are multiple flags available. You can pass the -h
flag to each subcommand to get the details. For instance, you can get the help section of zypper install command by running the following command:
$ zypper install -h
There is also a man page for the zypper command which can be accessed by running the below command.
$ man zypper
2. View Repository Lists
Every package manager connects to a repository that was hosted by the distribution maintainers. In this case, the openSUSE maintains repositories for both open-source and non-open-source software along with other drivers and packages.
Run any of the following commands to see the repository list.
$ zypper repos
$ zypper lr
The output of the repos
command is formatted in the table structure. You can see the name of the repository, the status of the repository, and other sections.
You can pass the -u
flag to the repos
command which will display the URL tagged with the repository. This is where the packages are hosted and will be fetched during installation.
The priority in the repository decides which repository gets higher priority. Let’s say there is a package called X and it is available in two different repos. In this case, the repo with the highest priority will be chosen as the installation candidate. By default, all the repositories are enabled with the same priority. If needed you can tweak it by running the modifyrepo
command.
$ sudo zypper modifyrepo -p 1 repo-oss
Repository 'repo-oss' priority has been set to 1.
To list all the configured repositories along with their priorities, run:
$ zypper lr -p
You can also disable a repository by running the following command.
$ sudo zypper modifyrepo --disable repo-oss
Repository 'repo-oss' has been successfully disabled.
To enable the repository use the --enable
flag instead of disable command.
$ sudo zypper modifyrepo --enable repo-oss
3. Updating Zypper Package Database
Before installing or updating a package you need to update the local package database to get the latest package metadata from the repo server.
Run the following command to refresh the SUSE package database.
$ sudo zypper ref
Or,
$ sudo zypper refresh
If there are some issues with the package database, you can rebuild it by running the following command.
$ sudo zypper refresh --force --force-build --force-download
Or,
$ sudo zypper refresh -fdb
4. Search for Packages in Repos using Zypper
Before installing a package you should check if the package is available in any of the enabled repositories.
Run the following command to search for a package.
$ zypper search -v <package-name>
Example:
$ zypper search -v htop
5. Get Detailed Information about a Package using Zypper
You can get detailed information about a package using the info
flag. You can see the repository, package name and version, current status, and a few other details of a package using this command.
$ zypper info htop
6. Installing Packages using Zypper Command
You can install single or multiple packages with the install
command.
$ sudo zypper install htop
To install multiple packages, specify them with space-separated like below.
$ sudo zypper install htop vim
Alternatively, you can use 'in
' which is the short form for 'install
'.
$ sudo zypper in htop
The main advantage of the install process is the dependencies will be automatically installed. It will prompt you for confirmation during the process. Press 'Y
' to proceed with the installation. You can pass the -n
flag for the unattended install where it will not prompt for confirmation.
$ sudo zypper -n install htop
Or,
$ sudo zypper --non-interactive install htop
You can also install a specific version of package like below:
$ sudo zypper -n install package=version
7. Removing Packages using Zypper Command
You can remove single or multiple packages using the remove option. Alternatively, you can use ‘rm’ which is the short form for remove.
$ sudo zypper remove <package>
$ sudo zypper remove <package1> <package2>
The command will prompt for user confirmation similar to the install
command. You can pass the -n
or --non-interactive
flag to skip the confirmation process.
$ sudo zypper remove -n htop
8. Combining Package Installation and Removal
You can simplify your package management tasks by combining installation and removal using the +
/-
modifiers in Zypper. Here are practical examples of how to perform these actions seamlessly:
Install and Remove Simultaneously (e.g., Installing "gimp" while Removing "krita"):
To achieve a one-step install and remove operation, structure your command like this:
$ sudo zypper install gimp -krita
This command installs the "gimp" package while removing the "krita" package in one go.
Remove and Install Together (e.g., Removing "firefox" and Installing "chromium"):
For a cohesive removal and installation, use the +/- modifiers in this manner:
$ sudo zypper remove firefox +chromium
By executing this command, you'll remove the "firefox" package and install the "chromium" package simultaneously.
Remember these key points to ensure accurate execution:
- Always position the package name starting with the - as the second argument to avoid command option confusion.
- If this order isn't feasible, safeguard the package name by using -- before it.
Here are the correct and incorrect usage examples:
Correct:
$ sudo zypper install gimp -krita $ sudo zypper remove firefox +chromium $ sudo zypper install -- -gimp +krita
Incorrect:
$ sudo zypper install -gimp +krita # Incorrect
Leverage the power of Zypper's +/- modifiers to effectively manage your packages, making package installation and removal a more efficient.
9. Get a List of Installed Packages using Zypper
You can get a list of installed packages by running the following command.
$ zypper search --installed-only
10. Get the Available Package List for Updates using Zypper
To get the list of packages that are available for updates, you can run the following command.
$ zypper list-updates --all
This command will display the current version and the available version for updates.
11. Upgrade Packages using Zypper
Zypper offers three different options for package upgrades, and each of them has significant operational differences.
zypper update
orzypper up
zypper dist-upgrade
orzypper dup
zypper patch
Update - The update
command will search the enabled repos for any updates with respect to the installed versions and update the packages. The main advantage of this method is it will only update the packages that are installed and from enabled repositories.
Dist Upgrade - The dist-upgrade
command will update or remove packages that are necessary during the process. This command is best suitable for the Tumbleweed version which is the rolling release of the SUSE family. My recommendation is to not use the command in production systems unless you need this command in action.
Patch - Patch focuses on security and bug fixes and is available as part of the main update repository. Sometimes the next version of a package is released with bug fixes or released as a patch. In either, the decision is yours to either update the package or apply a patch if you wish to use the old version.
Let’s see all three methods in action.
11.1. Zypper Update Command to Update Packages
You can update a single, multiple, or all packages using the update
command. For example, I wish to update all the 'python311' packages by running the following command.
$ sudo zypper update python311*
To update all installed packages, run the update
command without any argument.
$ sudo zypper update
11.2. Zypper Dist Upgrade Command
The dist-upgrade
command is used in the Zypper package manager on Linux systems to perform a distribution upgrade. This means it will upgrade your entire operating system, including its core components, applications, and packages, to the latest available versions.
This command is typically used when you want to transition from one version of the distribution to the next, such as upgrading from OpenSUSE Leap 15.3 to a newer version.
During a distribution upgrade, Zypper will handle the installation of new packages, removal of obsolete packages, and updating of existing packages to ensure that your system remains up to date and compatible with the newer version of the distribution.
The dist-upgrade
command is best suited when there is a rolling release available to be updated.
It's important to note that a distribution upgrade can be a significant process that may require careful attention, as it involves changes to fundamental components of your operating system.
It's also highly recommended to have a backup of your data and configurations before performing a distribution upgrade to avoid any potential issues.
11.3. Apply Patches using Patch Command
The command zypper patches
is used to display a list of available patches for the installed packages in SUSE Linux. These patches are updates provided by the distribution to fix security vulnerabilities, bugs, or improve the functionality of software packages.
To list of available patches, run"
$ zypper patches
The patches that you are seeing above are just sample patches released as part of testing by the openSUSE team.
You can apply patches by running the following command.
$ sudo zypper patch Loading repository data... Reading installed packages... Resolving package dependencies... Nothing to do.
12. Adding New Repositories
When you want to include a new repository source, run the command:
$ sudo zypper addrepo URI ALIAS
The URI can be an Internet repository, network source, folder, CD, or DVD. You can find more information at https://en.opensuse.org/openSUSE:Libzypp_URIs.
The ALIAS is a quick and special name for the source, which needs to be distinct. You're free to choose it, except if it's already in use. If you select an alias already in use, Zypper will warn you.
13. Removing a Repository
When you wish to remove a repository from Zypper, follow these straightforward steps:
List Configured Repositories:
To identify the repository you want to remove, list the currently configured repositories. Open a terminal and execute:
$ sudo zypper repos
This command will display a list of repositories along with their aliases. Note down the alias of the repository you intend to remove.
Remove the Repository:
Once you have the repository's alias, use the following command to remove it:
$ sudo zypper removerepo ALIAS
Replace "ALIAS" with the alias of the repository you wish to remove.
Zypper will ask you to confirm the removal. Type 'y' and press Enter to proceed.
After confirmation, Zypper will remove the specified repository from your system.
Remember that removing a repository might impact the availability of specific packages or updates associated with it. It's a good practice to review your software needs before removing any repositories.
14. Find Orphaned Packages
After you remove a repository from Zypper or update your system, certain packages might end up as "orphaned." These orphaned packages don't have a home in any active repository. You can use this command to see them:
$ sudo zypper packages --orphaned
This will provide you with a list of these packages that need your attention.
15. Package Cache Management
Caching the rpm files will eliminate the time to download the packages from the remote repository. The rpm files are downloaded under /var/cache/zypp/packages
directory.
You have to first enable the caching for a particular repository or all repositories.
To enable caching for a single repository run the following command. Here mr
is the short form for the modifyrepo
flag.
$ sudo zypper mr -k
$ sudo zypper mr -k openSUSE-Tumbleweed-Oss
RPM files caching has been enabled for repository 'repo-oss'.
To enable caching for all repos just pass -k
and -a
as the argument without any repo names.
$ sudo zypper mr -k -a
Now go ahead and install any packages. Navigate to the /var/cache/zypp/packages
directory and you will see the cached rpm files.
To disable caching all you have to do is replace -k
with -K
flag for single or all repos.
$ sudo zypper mr -K -a
You can clean the cached files by passing the clean
argument.
$ sudo zypper clean
All repositories have been cleaned up.
16. Zypper Log Files
All the zypper operations will be recorded in the log file under /var/log/zypp/history
. This file will be very useful when you wish to see the history of operations performed.
$ sudo cat /var/log/zypp/history
Linux Zypper Command Cheat Sheet
Following cheat sheet contains essential Zypper commands. This will be handy whenever needed.
Command | Description |
man zypper | Access Zypper man page |
zypper -h (and) zypper [subcommand] -h | Access help section for zypper and subcommands. |
zypper sh (or) zypper shell | Launch interactive zypper shell |
zypper repos (or) zypper lr | List available repos. |
zypper repos -d (or) zypper lr -d | Show detailed information like URL, Priority, Status, Name, etc for the repos. |
zypper refresh (or) zypper ref | Refresh the package database. |
zypper refresh --force --force-build --force-download | Rebuild package database. |
zypper search -v [package-name] | Search for a package in repos. |
zypper search --installed-only | Print installed packages alone. |
zypper info [package-name] | Detailed information about a package like status, repo info, version, etc. |
zypper install [package-name] (or) zypper install [package1], [package2],[package N] (or) zypper in [package-name] | Install single or multiple packages. |
zypper install -n [package-name] | Install package without user confirmation. |
zypper remove -n [package-name] (or) zypper rm -n [package-name] | Remove package. |
zypper list-updates --all | All packages that are eligible for updates. |
zypper update | Updates the packages to the latest version. |
zypper dist-upgrade | Updates the packages but suitable for rolling release. |
zypper patches | List available patches. |
zypper patch | Apply security and bug-fix patches. |
zypper modifyrepo -k -a (or) zypper mr -k -a | Enable caching for all repos. |
zypper modifyrepo -K -a (or) zypper mr -K -a | Disable caching for all repos. |
zypper clean | Clean all cached RPM files. |
Frequently Asked Questions
Here is a list most commonly asked questions about Zypper command.
A: Zypper is a command-line package manager for Linux distributions like SUSE and openSUSE. It's used to install, update, and manage software packages on the SUSE-based systems.
A: To refresh repository metadata and fetch the latest package information, use the command: zypper refresh
.
A: To install a package, use the command: zypper install [package-name]
.
A: You can remove a package using: zypper remove [package-name]
.
A: Zypper offers a convenient way to install and remove packages together using the +/- modifiers. For instance, to install "gimp" while removing "krita," you can use the command: sudo zypper install gimp -krita
. Conversely, to remove "firefox" and install "chromium" at once, employ: sudo zypper remove firefox +chromium
. Always place the package name starting with - as the second argument to prevent confusion. If needed, use -- before the package name.
A: To search for packages based on a query, use: zypper search [search-query]
.
A: Update installed packages to their latest versions with: zypper update
.
zypper update
and zypper dist-upgrade
?A: zypper update
updates packages to their latest versions within the current distribution, while zypper dist-upgrade
upgrades the entire distribution to a newer version.
zypper patches
command?A: The zypper patches
command lists available patches to fix vulnerabilities and bugs in installed packages.
A: Use the command: zypper list-updates
.
A: Yes, you can add a repository using: zypper addrepo [repository-URL]
, and remove a repository using: zypper removerepo [repository-name]
.
A: To see detailed information about a package, use: zypper info [package-name]
.
A: You can see the list of repositories using: zypper repos
.
A: Orphaned packages are those that remain on your system after removing a repository from Zypper or performing a system upgrade, leaving them with no associated active repository. To pinpoint these orphaned packages, you can use the command: sudo zypper packages --orphaned
. This command will provide you with a list of packages that are in an orphaned state, allowing you to decide whether to remove them or take further action.
zypper clean
command?A: The zypper clean
command removes cached package files and temporary data, freeing up disk space.
A: Yes, you can upgrade your entire distribution using: zypper dist-upgrade
.
A: While Zypper is most commonly associated with SUSE and openSUSE, it's primarily designed for SUSE-based distributions. Other Linux distributions may have their own package managers, such as APT for Debian-based systems or YUM/DNF for Red Hat-based systems.
Conclusion
In conclusion, mastering Zypper commands opens up a world of efficient software management for your SUSE Linux system. Whether you're an experienced sysadmin or a newcomer, understanding these commands empowers you to handle packages, updates, and dependencies effortlessly.
The Zypper command cheat sheet provided at the end of this guide ensures quick reference whenever you need to navigate the essential Zypper commands.
Resource: