3.3 Update from the Command Line with zypper

openSUSE comes with a command line tool for installing and updating packages—zypper. It is especially useful to accomplish remote software management tasks or to manage software from shell scripts.

3.3.1 Installing and Removing Software with Zypper

To install a package from registered repositories, use

zypper install package_name

To remove an installed package, use

zypper remove package_name

By default, zypper asks for confirmation before installing or removing a selected package. Override this behavior using the --non-interactive option. Note that this option must be given before the actual mode (install, remove, and update) as in

zypper --non-interactive install package_name

This option allows the use of zypper in scripts and cron jobs.

3.3.2 Updating Software with Zypper

There are two different ways to update software using zypper. To integrate all officially released patches into your system, just run the

zypper update

command. In this case, all patches that are available in your repositories are checked for relevance, and installed if necessary.

If a repository just has new packages, but does not provide patches, zypper update does not show any effect. To update all of these packages, you must specify to install updates of the type package:

zypper update -t package

To update individual packages, simply use the installation command:

zypper install package_name

A list of all new packages available can be obtained with the command

zypper list-updates -t package

3.3.3 Managing Repositories

All installation or update commands of zypper rely on a list of repositories known to zypper. To list all repositories known to the system, use the command

zypper repos

The result will look similar to the following output


# | Enabled | Refresh | Type  | Alias             | Name
--+---------+---------+-------+-------------------+-------------------
1 | Yes     | Yes     | yast2 | openSUSE-DVD 11.0 | openSUSE-DVD 11.0
2 | Yes     | No      | yast2 | Main (OSS)        | Main (OSS)
3 | Yes     | No      | yast2 | Main (Non-OSS)    | Main (Non-OSS)

If you want to remove a repository from the list, use the command zypper renamerepo together with the alias of the repository you want to delete. To remove the Main Repository (Non-OSS) from the example, use the following command:

zypper renamerepo Main Repository (Non-OSS)

To add a repository, run

zypper addrepo URI Alias

URI can either be an Internet repository (see http://en.opensuse.org/Additional_YaST_Package_Repositories for a list of available repositories), a directory, or a CD/DVD. The Alias a shorthand and a unique identifier of the repository. You can freely choose it, with the only exception that is has to be unique. zypper will issue a warning if you specify an alias that is already in use.

3.3.4 Using the Zypper Shell

Sometimes, several different zypper commands must be run in a sequence. To prevent zypper from rereading all the databases for each zypper command, it is possible to run zypper in shell mode: zypper shell.

When the shell is running, just issue the zypper commands with the respective parameters:

zypper shell
zypper> in zsh
...
zypper> exit

Using the zypper shell is usually faster, because all the relevant data stays in memory.

Zypper supports the readline library. This means that you can use all the command line editing functions in the zypper shell that are also available in the Bash shell. Zypper maintains its command history in file ~/.zypper_history.

3.3.5 For More Information

For more information about updating from the command line, enter zypper --help or see the zypper(8) man page. For examples and detailed information, visit http://en.opensuse.org/Zypper/Usage.