If you are a veteran Linux user like me, chances are you have come across the term SUSE Linux. It is one of the most powerful, enterprise-ready Linux distribution and is used by a plethora of companies worldwide. In fact, SUSE was the first Linux distribution marketed for businesses. SUSE has two variants – a free, open-source version called openSUSE and a commercial solution named SUSE Linux Enterprise. The zypper command-line utility is the de-facto package management solution for both of these variants. In this guide, we will provide some practical instructions on how to use this tool.
Zypper Commands for OpenSUSE and SUSE Enterprise
We have picked a total of 50 zypper commands that can be useful for anyone using a SUSE variant. If you are an absolute beginner, then this guide will provide a practical introduction to package management in SUSE. Those of you who are more experienced can bookmark this for future references.
1. Installing a Package
If you want to install new applications in your SUSE, you’ll likely need to install packages from repositories that have those available. The following single command can be used to install a fresh new package.
$ sudo zypper install git
Zypper will search its repositories for the specified package and proceed with the installation. It will solve any dependency issues, given the required packages are also available in your repositories. You can also use the short form instead of install.
$ sudo zypper in git
The downloaded packages are stored in the /var/cache/zypper/source-download directory.
2. Installing Local Packages
Both OpenSUSE and SUSE Linux use the rpm system as their package management system. Let’s say you have downloaded an rpm package using the Linux wget command.
$ wget http://220.127.116.11/download/3.5.0/Linux/nxclient-3.5.0-7.x86_64.rpm
You can install the downloaded package using the zypper install command. Make sure you provide the correct path to the file.
$ sudo zypper install nxclient-3.5.0-7.x86_64.rpm $ sudo zypper in nxclient-3.5.0-7.x86_64.rpm
3. Downloading Packages in Zypper
Sometimes you may want to download a package without proceeding to install it. The Zypper download command makes it easy to download remote packages to your local machine.
$ sudo zypper download nmap
When you issue this command, it will download the Nmap package onto your machine but do not install it. By default, zypper places locally downloaded packages in the /var/cache/zypp/packages/<repo>/<arch>/ directory of your Linux file system.
4. Displaying Available Repositories
As discussed already, packages reside on repositories, and when you issue a download, the package management tool fetches the applications from there. You can view the repository information for SUSE Linux using one of the following zypper commands.
$ sudo zypper lr $ sudo zypper repos
The output contains information like the actual repo name, aliases, enabled status, and so on. You can get detailed information about the repos by using the -d flag.
$ sudo zypper lr -d $ sudo zypper repos -d
Use the -p option to include repository priorities and sort by it.
$ sudo zypper lr -p $ sudo zypper repos -p
5. Adding a Repository
You can add additional repositories for your SUSE machine by using the following simple syntax.
zypper addrepo <options> <URI> <alias>
The URI is the path of the repository, and the alias is the name. The short-form option for addrepo is ar. Check out the following commands to learn how to add a repository in OpenSUSE and SUSE Enterprise.
$ sudo zypper ar http://download.opensuse.org/update/11.1/ update $ sudo zypper addrepo http://download.opensuse.org/update/11.1/ update
6. Creating Local Repositories
It is very easy to create local repositories using zypper. Simply place all your local rpm files into a directory and then follow the below syntax.
zypper addrepo <Path-to-Dir> <Name-of-Repository>
The following zypper commands will create a local repository named test-repo.
$ sudo zypper ar ~/repos-dir test-repo $ sudo zypper addrepo ~/repos-dir test-repo
7. Updating Repositories in SUSE
You should update the repository list after adding new repos. It can be done very easily by using the zypper refresh command.
$ sudo zypper ref $ sudo zypper refresh
Specifying the repo name will refresh only that particular repository.
$ sudo zypper refresh repo-oss
You can simply list all the repositories to obtain the name of your available repositories. Use the -s or –services option to refresh services as well as repositories. It is disabled by default.
$ sudo zypper refresh -s $ sudo zypper refresh --services
8. Modifying Repositories in SUSE
Zypper allows users to modify repositories on the go. Check out the following examples to see how you can use the modifyrepo command for such tasks.
$ sudo zypper modifyrepo --disable 6 $ sudo zypper mr -d 6
These commands will disable repository number 6. You can see that there are both short and long aliases available for the options.
$ sudo zypper mr -Ka
This command will disable rpm file caching for all the repositories – both remote and local. You can find out a list of all modification options by using the below commands.
$ sudo zypper modifyrepo --help $ sudo zypper mr --help
9. Renaming Repositories in SUSE
Renaming repositories is also very easy using zypper. The following commands illustrate how to use the zypper namerepo command to do this.
$ sudo zypper namerepo 6 primary $ sudo zypper nr 6 primary
Both of these commands change the name of the sixth repository to the primary. We can specify the repository using its number, name, or URL. However, the rename operation only works on the aliases.
10. Removing Repositories in SUSE
Removing a repository from your OpenSUSE machine is as simple as renaming it. Simply use the removerepo command of the zypper utility to do this. The following simple commands illustrate how to remove a repository named test.
$ sudo zypper removerepo main $ sudo zypper rr main
Use the below command if you want to remove only the local repositories.
$ sudo zypper removerepo --local $ sudo zypper rr -l
To remove all the remote repositories, use the following zypper commands.
$ sudo zypper removerepo --remote $ sudo zypper rr -t
11. Searching a Package
If you want to locate a package before installing it, you can use the zypper search command. The below commands will illustrate how to locate the Nmap package using this method.
$ sudo zypper search nmap $ sudo zypper se nmap
When you run one of these commands, it will display a list of all available Nmap packages alongside their effective name, type, and summary. Use the below command if you want to find an already installed package.
$ sudo zypper search --installed-only sed $ sudo zypper se -i sed
There are many more options supported by zypper search. You can view them by using the following command.
$ sudo zypper se --help
12. Viewing Information About a Package
You can view all the available information for a particular Linux package using the info sub-command of zypper. The short form replacement for info is if.
$ sudo zypper info nmap $ sudo zypper if nmap
This command will dump the information about the Linux nmap command on your terminal display. You should view information like the repository name, source package, version information, status, and package description. Users can also search for package information without knowing the exact package name.
$ sudo zypper info --match-substrings nma $ sudo zypper if -s nma
13. Installing Packages by Version
Zypper makes it easy to install SUSE Linux packages by their version. This allows admins to install stable versions of software packages which are unlikely to hamper the user experience. The below example shows how to install Zypper packages using a specific version.
$ sudo zypper in 'gcc<5.1' $ sudo zypper install 'gcc<5.1'
The above zypper commands will install the preceding version of GCC 5.1. If you know the exact version of the package, you can install it using that information.
$ sudo zypper in gcc48-4.8.3+r212056-2.2.4 $ sudo zypper install gcc48-4.8.3+r212056-2.2.4
14. Installing Packages by Architecture
Most personal computers today run on the amd64 or i386 architecture. If you’re using a 64-bit operating system, then you’re on amd64. 32-bit systems use the i386 design. The following command will install GCC for the i386 architecture.
$ sudo zypper in gcc.i386 $ sudo zypper install gcc.i386
The below command illustrates how we can download a specific version of a program for a required architecture.
$ sudo zypper in 'gcc.i386<5.1' $ sudo zypper install 'gcc.i386<5.1'
15. Installing Package by Pattern
Zypper allows SUSE admins to search and install packages by some pattern. First of all, we could always specify the package name using regular expressions. These should be familiar to users who have used the grep command or the sed utility in Linux.
$ sudo zypper in nfs* $ sudo zypper install nfs*
This command will install all packages that are related to NFS and contain the wildcard in their name. To download and install packages using the zypper install pattern, follow the below example.
$ sudo zypper in -t pattern file_server $ sudo zypper install -t pattern file_server
This command will install all packages required for setting up a file server system in SUSE.
16. Installing Packages from Specific Repos
By default, zypper will locate the desired package in whichever repositories it is available in. However, we can specify the repository name explicitly if we want. The below zypper commands shows this in action.
$ sudo zypper in amarok upd:libxine1 $ sudo zypper install amarok upd:libxine1
This can be helpful to users who want to install packages from a particular repository. Note that we are using the repository alias for specifying the repository. The next example installs the Nmap port scanner from the main repository.
$ sudo zypper in nmap main $ sudo zypper install nmap main
17. Installing and Removing Packages Simultaneously
SUSE Linux allows admins to install and remove packages using a single command combination. Check out the following zypper commands to see how it works in practice.
$ sudo zypper in nano -vi $ sudo zypper install nano -vi
If you copy and run one of the above commands in your Linux terminal emulator, it will first install the nano editor and then remove the vi text editor for Linux. Make sure you have the required permissions needed to delete the package.
18. Removing Packages in SUSE
If you want to remove applications that are no longer needed, you can remove them from your SUSE machine using the zypper remove command. The below example removes the apache2 package using the zypper utility.
$ sudo zypper rm apache2 $ sudo zypper remove apache2
You can also use patterns for selecting the packages. The following simple command will remove all packages that form the file server.
$ sudo zypper rm -t pattern file_server $ sudo zypper remove -t pattern file_server
19. Removing Packages alongside Dependencies
Linux applications use a combination of packages for providing their functionalities. Thus, your system will often contain packages used by an uninstalled package and are no longer needed. You can get around this issue by removing the dependencies during package removals.
$ sudo zypper rm -u apache2 $ sudo zypper remove --clean-deps apache2
So, you can use the -u or –clean-deps option of the remove command for removing package dependencies in OpenSUSE or SUSE Enterprise.
20. Updating System using Zypper
The following zypper commands will illustrate how we can update all the packages installed in our SUSE distribution. We will need to use the zypper update or up command for performing this task.
$ sudo zypper up $ sudo zypper update
When you run one of the above commands, zypper will update all your system packages, given updates are available. You can use this command in your Linux crontab for making system-wide updates automated. If you don’t know how Cron works yet, look at our guide on Linux crontab commands.
21. Installing Source and Build Dependencies
If you want to build an application from the source, you can use zypper to do so. The zypper source-install command allows admins to install the source as well as their dependencies for SUSE packages. The following command illustrates how to do this.
$ sudo zypper si mariadb $ sudo zypper source-install mariadb
The above commands will download all packages required to compile the MariaDB database management system for Linux. By default, zypper will install the source packages in the /usr/src/packages/ location of your file system.
22. Installing only Source for Packages
If you are ever in a situation where you want to download only the source for a package, not the dependencies, use the following simple commands.
$ sudo zypper in -D mariadb $ sudo zypper install -D mariadb
These commands will download only the source files for MariaDB.
23. Installing only Build Dependencies
Similarly, you can download the build dependencies for a package without installing the application right away. We will make use of the -d option of zypper source-install for this task. Check out the below examples to see what we mean.
$ sudo zypper si -d mariadb $ sudo zypper source-install --build-deps-only mariadb
These commands also make it simple for admins to inspect what packages are required for a particular application. This helps to tune the system performance and helps in auditing.
24. Installing Packages in Quiet Mode
The quiet mode of zypper allows admins to suppress long text outputs in the terminal screen. This is very useful when you are working on remote machines or Linux containers. Take a close look at the below example to understand how this works in practice.
$ sudo zypper --quiet in mariadb $ sudo zypper --quiet install mariadb
When you run one of the above commands, zypper will download and install the MariaDB package. However, it will not show any information regarding the package but will only ask for confirmation.
25. Removing Packages in Quiet Mode
The quiet mode works the same for software removals. The following simple command will delete the apache2 package from the SUSE machine. It will not display any additional information about the package and its dependencies.
$ sudo zypper –quiet rm apache2
$ sudo zypper –quiet remove apache2
If you also want to skip the confirmation stage, use the -y or –no-confirm option of the rm command. The following zypper commands show this for the MariaDB package.
$ sudo zypper --quiet rm -y mariadb $ sudo zypper --quiet remove --no-confirm mariadb
26. Setting Custom Priorities for Repositories
Earlier, we illustrated how to display the active repositories of your SUSE machine based on their priorities. Now, we will show you how to set custom priorities for a SUSE repository. Check out the below example to learn how we do this.
$ sudo zypper mr -p 100 repo-oss $ sudo zypper modifyrepo --priority 100 repo-oss
You can verify the effect of this command by running the below command before and after executing the above example.
$ sudo zypper lr -p $ sudo zypper repos --priority
27. Enabling RPM File Caching in SUSE
If you want to enable rpm file caching for your SUSE repositories, use the -k or –keep-packages option of zypper modifyrepo command. The next example will enable RPM caching for all active repositories for your SUSE machine.
$ sudo zypper mr -ka $ sudo zypper modifyrepo --keep-packages --all
You may choose to enable rpm caching only for specific repositories. To do this, specify the repo name by using their alias, number, or URI.
$ sudo zypper mr -ka repo-non-oss $ sudo zypper modifyrepo --keep-packages 6
28. Enabling RPM Caching for Remote Repositories Only
Suse admins can enable rpm file caching for only the remote repositories. This is a fairly simple thing to do, as shown in the following example command.
$ sudo zypper mr -kt $ sudo zypper mr --keep-packages --remote
The following command will enable rpm caching and enable automatic refresh for all the remote SUSE repositories.
$ sudo zypper mr -ktf $ sudo zypper mr --keep-packages --remote --refresh
29. Installing LAMP Server on SUSE
The LAMP server is a backend stack comprising of Linux(L), Apache(A), MySQL(M), and PHP(P). You do not need to install the database and backend applications individually. The following simple command will take care of it for you.
$ sudo zypper in -t pattern lamp_server $ sudo zypper install --type pattern lamp_server
You can use one of the above zypper commands to install the required packages for your LAMP server. This saves time as well as configuration efforts.
30. Downgrading Packages in SUSE
If you want to rollback to an earlier version of a zypper package, you can the –oldpackage option of the zypper install command. Take a close look at the below examples to see how it works.
$ sudo zypper in --oldpackage flash-player-gnome=18.104.22.168-15.1 $ sudo zypper install --oldpackage flash-player-gnome=22.214.171.124-15.1
You may also use the -f or –force option. This forces zypper to reinstall a specific version.
$ sudo zypper in -f flash-player-gnome=126.96.36.199-15.1 $ sudo zypper install --force flash-player-gnome=188.8.131.52-15.1
31. Viewing Available Updates
Admins need to manage their packages carefully to sustain a working machine. The list-updates command of zypper makes it very easy to find out which updates are available for your machine. You can then install the required updates as per your requirements.
$ sudo zypper lu $ sudo zypper list-updates
However, the above zypper commands will only show the updates that are readily installable, meaning packages that do not have any dependency issues. You can use the –all option to display all available updates.
$ sudo zypper lu -a $ sudo zypper list-updates --all
Use the below commands to display package updates that come from a specific repository.
$ sudo zypper lu -r repo-oss $ sudo zypper list-updates --repo repo-oss
32. Viewing Available Patches
You can use one of the following commands to view a list of all available patches for your SUSE machine. They will display patches that are readily applicable to your system.
$ sudo zypper lp $ sudo zypper list-patches
If you want to view all available patches, add the -a or –all option to your command.
$ sudo zypper lp -a $ sudo zypper list-patches --all
The following zypper commands illustrate how to get a list of all available patches by Bugzilla issues and CVE numbers.
$ sudo zypper list-patches --bugzilla=972197 $ sudo zypper list-patches --bugzilla=CVE-2016-2315
33. Installing Patches in SUSE
Once you have viewed the patches available for downloads, you can install them by issuing the following command. This will install all the patches required by your OpenSUSE or SUSE Enterprise machine.
$ sudo zypper patch
You can use the –auto-agree-with-licenses option for installing patches without requiring confirmation first.
$ sudo zypper patch --auto-agree-with-licenses
Add the -D or –dry-run flag to view what zypper will do without applying the changes directly.
$ sudo zypper patch -D $ sudo zypper patch -dry-run
34. Adding User Data to Logs
The global –userdata option allows admins to specify a string that gets written to the log file of zypper. This will help you mark and identify zypper transactions in the log and be used by ZYpp plugins.
$ sudo zypper --userdata security-patch patch
The above command will append the text ‘security-patch’ to the zypper log file for this specific transaction. It will help keep track of your zypper workflow and document why certain commands were used.
35. Using Zypper in Scripts
If you want to use zypper in Linux shell scripts, use the global option –non-interactive before your subcommand. This suppresses any confirmation prompt and thus works smoothly even from inside scripts.
$ sudo zypper --non-interactive in nmap $ sudo zypper --non-interactive install nmap
Additionally, many zypper commands provide this functionality using the -y or –no-confirm option. You can also use them when using zypper inside shell scripts.
$ sudo zypper install -y nmap $ sudo zypper remove --no-confirm vim
36. Verifying Package Dependencies Using Zypper
You can use the zypper verify command to check if all dependencies for your installed packages are met or not. The output will also indicate whether to install or remove certain packages for maintaining dependencies.
$ sudo zypper ve $ sudo zypper verify
Add the –details flag to the above zypper commands if you want to view additional information about your dependencies.
$ sudo zypper ve --details $ sudo zypper verify --details
37. Installing Patches for Zypper
The –updatestack-only option of the zypper patch command allows admins to install patches for only the zypper package management tool. This is useful if your package management system is broken or missing crucial packages.
$ sudo zypper patch --updatestack-only
However, when you use the above command, it will drop the other command options that would typically update any other zypper repositories.
38. Viewing Orphaned Packages
When you remove an application without removing the packages, it depended on them, and these dependencies become orphaned packages. They not only take up disk space but can also cause other issues. You can view a list of all such SUSE packages using the following simple command.
$ sudo zypper packages --orphaned
The output of this command can help users determine whether they still need certain packages or should remove them altogether.
39. Viewing Processes That are Using Deleted Files
During updating or removing packages, zypper may delete certain files that are still being used by some other processes. You can use the zypper ps command to list such processes.
$ sudo zypper ps
This will display a list of processes that are using deleted files and the filenames. You can then simply restart the processes. It will use the new files upon restart. Use the below command to show only system processes that are using deleted files.
$ sudo zypper ps-ss
40. Searching Packages by Capabilities
Zypper makes it very simple to locate packages that offer certain functionalities. Simply use the global option what-provides to find out which package provides a specific module.
$ sudo zypper what-provides 'perl(SVN::Core)'
This command will display the package name that offers the Perl module ‘SVN::Core’. It is very similar to rpm -q –whatprovides. However, contrary to the rpm command, the zypper version can show which remote packages provide the desired capabilities.
41. Viewing Required/Recommended Modules
Users can use the zypper info command to view which modules are required or recommended for a SUSE package. The following example displays the required modules for the MozillaFirefox package.
$ sudo zypper if --requires MozillaFirefox $ sudo zypper info --requires MozillaFirefox
You will need to use the –recommends flag to view the recommended modules for MozillaFirefox. The below command illustrates this.
$ sudo zypper if --recommends MozillaFirefox $ sudo zypper info --recommends MozillaFirefox
42. Using the Zypper Shell
The zypper shell is an interactive interface to the ZYpp package manager. It allows admins to manage and configure SUSE packages using an intuitive shell session. You can open a zypper shell by using the following simple command.
$ sudo zypper sh $ sudo zypper shell
Here, you can issue standard zypper commands to manage your applications. Simply type help in this interactive shell if you want to view all the available options and their functionalities.
43. Generating XML Output for Zypper
The global option -x or –xmlout allows admins to print the output of zypper commands in XML format. This is very useful for graphical frontends that use zypper or for documenting purposes.
$ sudo zypper -x $ sudo zypper --xmlout
The above commands will display the output in an XML format. You can easily redirect the output generated by the above command to a file for storing.
$ sudo zypper --xmlout > output
44. Cleaning Zypper Caches
The zypper clean command helps users in cleaning the local cache for all or selected repositories. However, it will only clean the caches of downloaded packages by default.
$ sudo zypper cc $ sudo zypper clean
The following command will clean both the repository metadata and package cache for the repository repo-oss.
$ sudo zypper clean --all repo-oss
45. Upgrading SUSE Using Zypper
If you want to upgrade your OpenSUSE or SUSE Enterprise distribution to a new version, simply use the dist-upgrade subcommand of zypper.
$ sudo zypper dup $ sudo zypper dist-upgrade
The above command applies the state of all active repositories and installs, upgrades, or downgrades packages as needed by the target version of your distribution.
46. Importing and Exporting Repositories
You can import and export your zypper repositories to and from a file. The below commands illustrate how to export all the defined repositories to a file named backups/repos/foo.repo.
$ sudo zypper --export backups/repos/foo.repo $ sudo zypper lr --export backups/repos/foo.repo
You can then import the repositories by using the addrepo command of zypper. The next command shows users how to import the repositories from the file we exported to.
$ sudo zypper ar backups/repos/foo.repo $ sudo zypper addrepo backups/repos/foo.repo
47. Viewing Locked Packages
Zypper allows admins to lock packages on their SUSE machine. This prevents anyone from removing or upgrade these packages until the locks are removed. You can use the following zypper command to display a list of all locked packages.
$ sudo zypper ll $ sudo zypper locks
When a Linux user tries to install, upgrade, or remove these locked packages, they will get a dialogue stating dependency resolving the problem. Thus, package locks can help users maintain a specific version of packages for their system.
48. Adding and Removing Package Locks
You can add a new package lock by using the addlock command of zypper. The following example shows users how to lock the main repository using this method.
$ sudo zypper al MozillaFirefox $ sudo zypper addlock MozillaFirefox
To remove the lock from a package, use the removelock command. It also takes a lock number, which can be obtained by running the zypper locks command.
$ sudo zypper rl MozillaFirefox $ sudo zypper rl MozillaFirefox
49. Viewing the Help Page
The help page of Linux terminal commands provides a great way to look up a command. It contains summarized information on all the possible options and their features. The help section in zypper can be invoked by simply running the zypper command.
$ sudo zypper
It will list all the available global options and commands provided by the package manager. You can get help information for specific zypper commands by using the following.
$ sudo zypper help install $ sudo zypper update --help
50. Viewing the Man Page
The man page or manual contains in-depth information about Linux programs. You can learn everything you need to know about a command from there. The man page of zypper can be invoked by using the following.
$ sudo man zypper
This will print out the manual showing the available command-line options and how to use the options.
We have covered a lot of useful zypper commands in this guide. These should be more than enough for anyone who’s trying SUSE for the first time in their life. Moreover, if you are a professional system admin working with a variety of Linux distributions, this could save a huge amount of time. So, make sure to bookmark this guide for the future and let us know your thoughts about the overall guide in the comment section. Hopefully, the above commands will make your transition from a different system to SUSE much more smooth.