Linux zypper Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the zypper command, a powerful package management tool used in SUSE-based Linux distributions. We will learn how to install and update packages, as well as search for and remove packages using zypper. The lab covers the basic usage of zypper, including checking the version, viewing available commands, and performing common package management tasks.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux/BasicSystemCommandsGroup -.-> linux/help("`Command Assistance`") subgraph Lab Skills linux/help -.-> lab-423024{{"`Linux zypper Command with Practical Examples`"}} end

Introduction to the zypper Command

In this step, we will explore the zypper command, a powerful package management tool used in SUSE-based Linux distributions. Zypper is the default package manager for SUSE Linux Enterprise, openSUSE, and other SUSE-derived distributions.

The zypper command provides a wide range of functionality for managing software packages, including installing, updating, searching, and removing packages. Let's start by understanding the basic usage of the zypper command.

First, let's check the version of zypper installed on the system:

sudo zypper --version

Example output:

zypper 1.14.57 [...]

Next, we can use the zypper help command to see the available subcommands and options:

sudo zypper help

This will display a list of all the available zypper commands and a brief description of each.

Some of the most commonly used zypper commands are:

  • zypper install <package>: Install a package
  • zypper update <package>: Update a package
  • zypper search <package>: Search for a package
  • zypper remove <package>: Remove a package
  • zypper refresh: Refresh the package repository information
  • zypper list-updates: List available package updates

In the following steps, we will explore these commands in more detail and see practical examples of using zypper for package management.

Installing and Updating Packages with zypper

In this step, we will learn how to use zypper to install and update packages on the system.

First, let's install a new package using the zypper install command. We'll install the htop package, which is a popular system monitoring tool:

sudo zypper install htop

Example output:

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  htop

1 new package to install.
Overall download size: 105.0 KiB. After the operation, additional 326.0 KiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package htop-3.0.5-2.1.x86_64 (1/1), 105.0 KiB (326.0 KiB unpacked)
Installing: htop-3.0.5-2.1.x86_64 [done]

Now, let's verify that the htop package has been successfully installed:

which htop

Example output:

/usr/bin/htop

Next, let's update all the installed packages on the system using the zypper update command:

sudo zypper update

Example output:

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following packages are going to be upgraded:
  bash coreutils glibc grep gzip hostname iproute2 libacl1 libattr1 libcap2 libgcc_s1 libselinux1 libstdc++6 libudev1 libz1 login ncurses-utils openssl pam readline sed systemd systemd-sysvinit tar util-linux zlib

16 packages to upgrade.
Overall download size: 6.9 MiB. After the operation, additional 1.1 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package bash-5.1.16-3.1.x86_64 (1/16), 1.4 MiB (3.0 MiB unpacked)
Retrieving package coreutils-8.32-4.1.x86_64 (2/16), 1.2 MiB (3.8 MiB unpacked)
...

The zypper update command will update all installed packages to their latest versions.

Searching and Removing Packages with zypper

In this step, we will learn how to use zypper to search for packages and remove installed packages.

First, let's search for a package using the zypper search command. We'll search for the vim package:

sudo zypper search vim

Example output:

Loading repository data...
Reading installed packages...

S | Name | Summary | Type
--+------+---------+------
i | vim | Vi IMproved - enhanced vi editor | package
  | vim-data | Data files for VIM - Vi IMproved | package
  | vim-data-common | Common data files for VIM - Vi IMproved | package
  | vim-data-en | English language files for VIM - Vi IMproved | package
  | vim-data-en_GB | British English language files for VIM - Vi IMproved | package
  | vim-data-fr | French language files for VIM - Vi IMproved | package
  | vim-data-it | Italian language files for VIM - Vi IMproved | package
  | vim-data-pl | Polish language files for VIM - Vi IMproved | package
  | vim-data-ru | Russian language files for VIM - Vi IMproved | package

The search results show that the vim package is installed on the system (indicated by the i in the first column).

Now, let's remove the vim package using the zypper remove command:

sudo zypper remove vim

Example output:

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following package is going to be REMOVED:
  vim

1 package to remove.
After the operation, 14.1 MiB will be freed.
Continue? [y/n/? shows all options] (y): y
Removing: vim-8.2.5402-3.1.x86_64 [done]

The zypper remove command has successfully removed the vim package from the system.

Summary

In this lab, we first introduced the zypper command, which is the default package manager for SUSE-based Linux distributions. We learned how to check the version of zypper, explore the available subcommands, and understand the most commonly used zypper commands for installing, updating, searching, and removing packages. We then demonstrated how to install a new package, the htop system monitoring tool, using the zypper install command. Finally, we covered how to update packages with the zypper update command.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like