SUSE linux的软件管理工具-zypper

发布于:2024-06-21 ⋅ 阅读:(78) ⋅ 点赞:(0)

zypper:openSUSE中用于在CLI下管理软件包的安装,升级和删除。同时可以管理软件仓库。

1 常规用法

zypper的语法结构如下:

zypper [--global-options] COMMAND [--command-options] [arguments]

zypper command

最简单的使用方式就是输入名称,然后跟参数,例如,应用所有补丁到系统,使用下面的命令:

SUSE15:~ # zypper patch

Global options

另外,在zypper命令后面可以跟一个或多个全局选项,例如:

SUSE15:~ # zypper --non-interactive patch

上面例子的选项代表这是非交互式命令。

Command-specific options

如果要指定特定的功能,需要在后面指定参数:

SUSE15:~ # zypper patch --auto-agree-with-licenses

在上面的列子中,选项的意思是在应用补丁时不再需要任何许可的确认,意思是许可被自动接收。

Arguments

一些命令需要一个或多个参数,例如,使用命令install,你需要指定你需要要安装的软件包:

SUSE15:~ # zypper install mplayer

有些选项也需要一些参数,下面的命令用于先列出所有已知的模式:

SUSE15:~ # zypper search -t pattern

上面所有的选项/参数都可以混合使用。例如,下面的命令将会从factory仓库安装mcvim软件包,并显示详细信息:

SUSE15:~ # zypper -v install --from factory mc vim

--from参数在所有的仓库都不关闭的情况下指定安装软件包的仓库。--repo是它的一个别名,可以任意使用其中一个。
大多数的zypper命令会有dry-run选项,用于模拟后面给出来的命令,多用于测试:

SUSE15:~ # zypper remove --dry-run MozillaFirefox

zypper支持全局的--userdata STRING选项。你可以指定一个字符串,这个字符串会写入到zypper的日志文件中,主要是起标记作用。

SUSE15:~ # zypper --userdata STRING patch

2 使用zypper子命令

zypper的子命令是一些可执行文件,存放在zypper可执行文件目录/usr/lib/zypper中。如果在这里没有找到,zypper会自动搜索你的$PATH。通过下面的命令列出可用的子命令:

SUSE15:~ # zypper help subcommand

...
Available zypper subcommands in '/usr/lib/zypper/commands'

      appstream-cache       <No manual entry for zypper-appstream-cache>
      lifecycle             products and packages lifecycle information


Zypper subcommands available from elsewhere on your $PATH

      log                   Zypper logfile reader


Type 'zypper help <subcommand>' to get subcommand-specific help if available.

3 使用zypper安装和删除软件

命令格式如下:

SUSE15:~ # zypper install openvpn
SUSE15:~ # zypper remove openvpn

3.1 选择具体需要安装或删除的软件包

有很多方式来寻找软件包,例如:

指定软件包的具体名称

SUSE15:~ # zypper install MozillaFirefox

指定软件包的名称和版本

SUSE15:~ # zypper install MozillaFirefox-52.2

指定使用的仓库和软件包名

SUSE15:~ # zypper install mozilla:MozillaFirefox

使用正则表达式的来匹配包名

如果不清楚软件包的具体名字,可以输入部分字符,其他字符以*代替。或者需要删除很多相关联的软件包时,也可以采用这种方式。

SUSE15:~ # zypper install Mozilla*

当debug某个问题时,可能需要临时安装大量的- debuginfo软件包,这些软件包会输出大量的有用信息。在完成debug后,需要清空环境,可以使用命令zypper remove '*-debuginfo'

按功能(capability)

例如,如果安装一个不太清楚具体名字的软件包,可以根据提供的功能来进行模糊名称安装:

SUSE15:~ # zypper install firefox

按功能、硬件架构或版本

  1. 指定功能,以及运行的硬件架构
SUSE15:~ # zypper install 'firefox.x86_64'
  1. 指定版本范围,有一些选项可供使用:

< (lesser than), <= (lesser than or equal), = (equal), >= (greater than or equal), > (greater than).

SUSE15:~ # zypper install 'firefox>=74.2'
  1. 也可以将上面两种选项混合使用
SUSE15:~ # zypper install 'firefox.x86_64>=74.2'

给出RPM文件的路径

可以指定本地或远程的软件包路径:

SUSE15:~ # zypper install /tmp/install/MozillaFirefox.rpm
SUSE15:~ # zypper install http://download.example.com/MozillaFirefox.rpm

类似CentOS的yum localinstall

3.2 安装和删除结合

要同时安装和删除软件包,可以使用+-符号。例如在安装emacs的同时删除vim

SUSE15:~ # zypper install emacs -vim

删除emacs的同时安装vim

SUSE15:~ # zypper remove emacs +vim

为了避免混淆(如以-开头的包),符号建议用在第二个参数中,如果必须使用,需要添加--参数

SUSE15:~ # zypper install -emacs +vim # Wrong
SUSE15:~ # zypper install vim -emacs # Correct
SUSE15:~ # zypper install -- -emacs +vim # Correct
SUSE15:~ # zypper remove emacs +vim # Correct

3.3 清除已删除软件的依赖包

SUSE15:~ # zypper rm --clean-deps MozillaFirefox

3.4 在脚本中使用zypper

默认情况下,zypper在使用时会有一些交互选项。添加下面的选项后变成非交互式:

SUSE15:~ # zypper --non-interactive install MozillaFirefox

这样就可以用在脚本或者定时任务中了。

3.5 安装或下载源码包

SUSE15:~ # zypper source-install nginx

以root身份执行时,安装源包的默认位置是/usr/src/packages/,以用户身份运行时则在~/rpmbuild。 这些值可以在本地rpm中修改。

安装时会自动安装依赖包,如果不需要,可以添加-D选项。

如果只是安装依赖包,使用-d选项。

上面的命令仅限于添加了源码包的仓库。

下面的命令列出仓库中所有可用的源码包:

SUSE15:~ # zypper search -t srcpackage
Loading repository data...
Reading installed packages...

S | Name                          | Summary                                  | Type
--+-------------------------------+------------------------------------------+-----------
  | atftp                         | Advanced TFTP Server and Client          | srcpackage
  | createrepo_c                  | RPM repository metadata generation uti-> | srcpackage
  | discord                       | Voice and Text Chat for Gamers           | srcpackage
  | gstreamer-plugins-bad         | GStreamer Streaming-Media Framework Pl-> | srcpackage
  | lsb                           | LSB Fake Package                         | srcpackage
  | openSUSE-Addon-NonOss-release | openSUSE Leap 15.3 NonOSS Addon          | srcpackage
  | openSUSE-release              | openSUSE Leap 15.3                       | srcpackage
  | opera                         | Proprietary web browser                  | srcpackage
  | product-builder               | SUSE Product Builder                     | srcpackage
  | rpm-repos-openSUSE            | openSUSE package repositories            | srcpackage
  | rpmlint-mini                  | RPM file correctness checker             | srcpackage
  | steam                         | Installer for Valve's digital software-> | srcpackage
  | virtualbox                    | VirtualBox is an Emulator                | srcpackage
  | virtualbox-kmp                | Kernel modules for VirtualBox            | srcpackage
  | xfce4-branding-openSUSE       | openSUSE Branding of the Xfce Desktop -> | srcpackage
  | xfce4-panel                   | Panel for the Xfce Desktop Environment   | srcpackage
  | xfce4-settings                | Tools for Managing Xfce Settings         | srcpackage

也可以所用下面的命令将所有的源码包下载到本地

SUSE15:~ # zypper source-download

默认下载到/var/cache/zypper/source-download/,该命令的额外选项:

  • --directory:在下载时修改目录。
  • --status:只显示丢失或无关的包,不下载或删除任何内容
  • --delete:删除无关包
  • --no-delete:禁用删除

3.6 从关闭的仓库安装包

正常来讲,只能从启用的仓库安装软件。--plus-content选项可以指定需要使用的仓库,在当前命令中临时启用,完成后会禁用。
例如:临时开启debug仓库,并安装-debuginfo包,使用下面的选项:

SUSE15:~ # zypper --plus-content debug install "debuginfo(build-id)=eb844a5c20c70a59fc693cd1061f851fb7d046f4"

由于缺少debuginfo包,gdb会报告build-id字符串。

4 使用zypper升级软件

有三种方式升级软件:安装补丁,安装新版本的软件或升级整个系统。

4.1 安装所有补丁

很粗犷的做法就是直接安装补丁

SUSE15:~ # zypper patch
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 NEW patches are going to be installed:
  openSUSE-2021-820 openSUSE-2021-863

The following 2 packages are going to be upgraded:
  openSUSE-release openSUSE-release-dvd

The following product is going to be reinstalled:
  "openSUSE Leap 15.3"

2 packages to upgrade.
Overall download size: 694.9 KiB. Already cached: 0 B. After the operation, additional
895.0 B will be used.

    Note: Package manager restart required. (Run this command once again after the update
    stack got updated)
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package openSUSE-release-dvd-15.3-lp153.146.1.x86_64
                                                    (1/2),   8.1 KiB (   66   B unpacked)
Retrieving delta: ./x86_64/openSUSE-release-dvd-15.3-lp153.138.1_lp153.146.1.x86_64.drpm, 3.8 KiB
Retrieving: openSUSE-release-dvd-15.3-lp153.138.1_lp153.146.1.x86_64.drpm .....................................[done]
Applying delta: ./openSUSE-release-dvd-15.3-lp153.138.1_lp153.146.1.x86_64.drpm ...............................[done]
Retrieving package openSUSE-release-15.3-lp153.146.1.x86_64                     (2/2), 686.8 KiB (231.6 KiB unpacked)
Retrieving: openSUSE-release-15.3-lp153.146.1.x86_64.rpm .........................................[done (89.6 KiB/s)]

Checking for file conflicts: ..................................................................................[done]
(1/2) Installing: openSUSE-release-dvd-15.3-lp153.146.1.x86_64 ................................................[done]
(2/2) Installing: openSUSE-release-15.3-lp153.146.1.x86_64 ....................................................[done]
Executing %posttrans scripts ..................................................................................[done]
Warning: One of the installed patches affects the package manager itself. Run this command once more to install any other needed patches.

检查计算机上配置的存储库中的所有可用补丁是否与您的安装相关。如果它们是相关的(并且未归类为optionalfeature),则会立即安装它们。
简单的zypper patch命令不会应用来自第三方存储库的补丁。要更新第三方存储库,使用with-update命令选项:

SUSE15:~ # zypper patch --with-update

安装所有可选的补丁

SUSE15:~ # zypper patch --with-optional

安装相关问题的补丁,需要指定具体的问题,如

SUSE15:~ # zypper patch --bugzilla=NUMBER
SUSE15:~ # zypper patch --cve=NUMBER

例如,安装一个指定CVE号码的补丁

SUSE15:~ # zypper patch --cve=CVE-2019-15232
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW patch is going to be installed:
  openSUSE-2021-1004

The following 2 packages are going to be upgraded:
  libBasicUsageEnvironment1 libUsageEnvironment3

2 packages to upgrade.
Overall download size: 160.1 KiB. Already cached: 0 B. No additional space will be used
or freed after the operation.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package libBasicUsageEnvironment1-2021.05.22-bp153.2.3.1.x86_64
                                                    (1/2),  85.4 KiB ( 89.5 KiB unpacked)
Retrieving: libBasicUsageEnvironment1-2021.05.22-bp153.2.3.1.x86_64.rp[done (41.0 KiB/s)]
Retrieving package libUsageEnvironment3-2021.05.22-bp153.2.3.1.x86_64
                                                    (2/2),  74.7 KiB ( 52.2 KiB unpacked)
Retrieving: libUsageEnvironment3-2021.05.22-bp153.2.3.1.x86_64.rpm ................[done]

Checking for file conflicts: ......................................................[done]
(1/2) Installing: libBasicUsageEnvironment1-2021.05.22-bp153.2.3.1.x86_64 .........[done]
(2/2) Installing: libUsageEnvironment3-2021.05.22-bp153.2.3.1.x86_64 ..............[done]

仅安装影响Zypper和包管理本身的补丁:

SUSE15:~ # zypper patch --updatestack-only
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 4 NEW patches are going to be installed:
  openSUSE-SLE-15.3-2021-1833 openSUSE-SLE-15.3-2021-1879 openSUSE-SLE-15.3-2021-2273
  openSUSE-SLE-15.3-2021-2682

The following 9 packages are going to be upgraded:
  libsolv-tools libzypp python3-rpm python3-solv rpm ruby-solv zypper zypper-log
  zypper-needs-restarting

9 packages to upgrade.
...

该选项可能会删除或更新其他存储库的其他命令选项。

4.2 列出补丁

列出补丁数量

SUSE15:~ # zypper patch-check
Loading repository data...
Reading installed packages...

Found 123 applicable patches:
Category    | Patches
------------+--------
security    | 40
recommended | 81
optional    | 2

2 patches optional                    (use '--with-optional' to include optional patches)
121 patches needed (40 security patches)

该命令可以和--updatestack-only选项混用。

列出需要的补丁

SUSE15:~ # zypper list-patches

列出所有补丁

SUSE15:~ # zypper patches

Bugzilla issues

列出和Bugzilla相关的补丁:

SUSE15:~ # zypper list-patches --bugzilla=1186483,1188973
Loading repository data...
Reading installed packages...

The following matches in issue numbers have been found:

Issue    | No.     | Patch                       | Category | Severity  | Interactive | Status | Since | Summary
---------+---------+-----------------------------+----------+-----------+-------------+--------+-------+-------------------------------------
bugzilla | 1186483 | openSUSE-SLE-15.3-2021-2687 | security | important | reboot      | needed | -     | Security update for the Linux Kernel
bugzilla | 1188973 | openSUSE-SLE-15.3-2021-2687 | security | important | reboot      | needed | -     | Security update for the Linux Kernel

cve号码

SUSE15:~ # zypper list-patches --all --cve
Loading repository data...
Reading installed packages...

The following matches in issue numbers have been found:

Issue | No.            | Patch                       | Category | Severity  | Interactive | Status     | Since | Summary
------+----------------+-----------------------------+----------+-----------+-------------+------------+-------+------------------------------------------
cve   | CVE-2019-15232 | openSUSE-2021-1004          | security | moderate  | ---         | needed     | -     | Security update for live555
cve   | CVE-2021-28899 | openSUSE-2021-1004          | security | moderate  | ---         | needed     | -     | Security update for live555
cve   | CVE-2021-3185  | openSUSE-2021-1012          | security | important | ---         | needed     | -     | Security update for gstreamer-plugins-bad
cve   | CVE-2020-27208 | openSUSE-2021-1019          | security | moderate  | ---         | not needed | -     | Security update for solo
...

--cve:和cve相关的补丁
--cve=NUMBER:给出具体的补丁号码

4.3 安装软件包的新版本

如果仓库中只有新版本的软件而没有补丁包,zypper patch就不会有任何显示。使用下面的命令直接更新软件包到最新的版本:

SUSE15:~ # zypper update

指定具体的包:

SUSE15:~ # zypper update mariadb
SUSE15:~ # zypper install mariadb

列出可以升级的软件包:

SUSE15:~ # zypper list-updates
Loading repository data...
Reading installed packages...
S | Repository                                                   | Name                                       | Current Version           | Available Version           | Arch
--+--------------------------------------------------------------+--------------------------------------------+---------------------------+-----------------------------+-------
v | Update repository with updates from SUSE Linux Enterprise 15 | MozillaFirefox                             | 78.10.0-8.38.1            | 78.12.0-8.46.1              | x86_64
v | Update repository with updates from SUSE Linux Enterprise 15 | MozillaFirefox-translations-common         | 78.10.0-8.38.1            | 78.12.0-8.46.1              | x86_64
v | Update repository with updates from SUSE Linux Enterprise 15 | autoyast2-installation                     | 4.3.77-1.1                | 4.3.86-3.17.1               | noarch
v | Update repository with updates from SUSE Linux Enterprise 15 | bash                                       | 4.4-17.83                 | 4.4-19.3.1                  | x86_64
v | Update repository with updates from SUSE Linux Enterprise 15 | bash-doc                                   | 4.4-17.83                 | 4.4-19.3.1                  | noarch
...

注意该命令有条件:

  • 和已安装的软件包有相同的提供者
  • 由至少和已安装的软件包具有相同优先级的仓库提供
  • 可安装的

--all选项列出所有有效的更新包。如果想知道某个软件包为什么不能安装,直接使用zypper install安装就会有错误信息输出。

4.4 识别被孤立的包

被孤立的包来自于非激活的仓库,下面的命令可以列出所有的被孤立的包:

SUSE15:~ # zypper packages --orphaned

5 使用已删除的文件识别进程和服务

在修补、更新或删除软件包时,系统上可能有正在运行的进程继续使用已被更新或删除删除的文件。使用zypper ps列出使用已删除文件的进程。如果进程属于已知服务,则会列出服务名称,以便轻松重启服务。默认情况下zypper ps显示一个表:

SUSE15:~ # zypper ps
PID   | PPID | UID | User  | Command      | Service      | Files
------+------+-----+-------+--------------+--------------+-------------------
814   | 1    | 481 | avahi | avahi-daemon | avahi-daemon | /lib64/ld-2.19.s->
      |      |     |       |              |              | /lib64/libdl-2.1->
      |      |     |       |              |              | /lib64/libpthrea->
      |      |     |       |              |              | /lib64/libc-2.19->
[...]
  • PID: 进程ID
  • PPID: 进程的父ID
  • UID: 运行进程的用户ID
  • Login:运行进程用户的登陆名
  • Command: 进程执行的命令
  • Service: 服务名称
  • Files: 删除的文件

zypper ps -s

不显示删除的文件

SUSE15:~ # zypper ps -s
PID   | PPID | UID  | User    | Command      | Service
------+------+------+---------+--------------+--------------
814   | 1    | 481  | avahi   | avahi-daemon | avahi-daemon
817   | 1    | 0    | root    | irqbalance   | irqbalance
1567  | 1    | 0    | root    | sshd         | sshd
1761  | 1    | 0    | root    | master       | postfix
1764  | 1761 | 51   | postfix | pickup       | postfix
1765  | 1761 | 51   | postfix | qmgr         | postfix
2031  | 2027 | 1000 | tux     | bash         |

zypper ps -ss

仅仅显示系统服务相关联的进程

SUSE15:~ # zypper ps -ss
PID   | PPID | UID  | User    | Command      | Service
------+------+------+---------+--------------+--------------
814   | 1    | 481  | avahi   | avahi-daemon | avahi-daemon
817   | 1    | 0    | root    | irqbalance   | irqbalance
1567  | 1    | 0    | root    | sshd         | sshd
1761  | 1    | 0    | root    | master       | postfix
1764  | 1761 | 51   | postfix | pickup       | postfix
1765  | 1761 | 51   | postfix | qmgr         | postfix

zypper ps-sss

仅显示删除的文件

SUSE15:~ # zypper ps -sss
avahi-daemon
irqbalance
postfix
sshd

zypper ps–print “systemctl status %s”

显示用于检索可能需要重新启动的服务的状态信息的命令。

SUSE15:~ # zypper ps--print "systemctl status %s"
systemctl status avahi-daemon
systemctl status irqbalance
systemctl status postfix
systemctl status sshd

6 使用zypper管理仓库

列出所有的仓库

SUSE15:~ # zypper repos
Repository priorities are without effect. All enabled repositories share the same priority.

#  | Alias                       | Name                                                                                        | Enabled | GPG Check | Refresh
---+-----------------------------+---------------------------------------------------------------------------------------------+---------+-----------+--------
 1 | openSUSE-Leap-15.3-1        | openSUSE-Leap-15.3-1                                                                        | No      | ----      | ----
 2 | repo-backports-debug-update | Update repository with updates for openSUSE Leap debuginfo packages from openSUSE Backports | No      | ----      | ----
 3 | repo-backports-update       | Update repository of openSUSE Backports                                                     | Yes     | (r ) Yes  | Yes
 4 | repo-debug                  | Debug Repository                                                                            | No      | ----      | ----
 5 | repo-debug-non-oss          | Debug Repository (Non-OSS)                                                                  | No      | ----      | ----
 6 | repo-debug-update           | Update Repository (Debug)                                                                   | No      | ----      | ----
 7 | repo-debug-update-non-oss   | Update Repository (Debug, Non-OSS)                                                          | No      | ----      | ----
 8 | repo-non-oss                | Non-OSS Repository                                                                          | Yes     | (r ) Yes  | Yes
 9 | repo-oss                    | Main Repository                                                                             | Yes     | (r ) Yes  | Yes
10 | repo-sle-debug-update       | Update repository with debuginfo for updates from SUSE Linux Enterprise 15                  | No      | ----      | ----
11 | repo-sle-update             | Update repository with updates from SUSE Linux Enterprise 15                                | Yes     | (r ) Yes  | Yes
12 | repo-source                 | Source Repository                                                                           | No      | ----      | ----
13 | repo-update                 | Main Update Repository                                                                      | Yes     | (r ) Yes  | Yes
14 | repo-update-non-oss         | Update Repository (Non-Oss)                                                                 | Yes     | (r ) Yes  | Yes

在各种命令中指定存储库时,可以使用来自zypper repos命令输出的别名、URI或存储库编号。存储库别名是存储库名称的简短版本,用于存储库处理命令。修改存储库列表后,存储库编号可能会更改。别名本身永远不会改变。
查看更详细的信息:

SUSE15:~ # zypper repos -d
#  | Alias                       | Name                                                                                        | Enabled | GPG Check | Refresh | Priority | Type   | URI                                                                                  | Service
---+-----------------------------+---------------------------------------------------------------------------------------------+---------+-----------+---------+----------+--------+--------------------------------------------------------------------------------------+--------
 1 | openSUSE-Leap-15.3-1        | openSUSE-Leap-15.3-1                                                                        | No      | ----      | ----    |   99     | NONE   | cd:/?devices=/dev/disk/by-id/ata-VMware_Virtual_SATA_CDRW_Drive_01000000000000000001 | 
 2 | repo-backports-debug-update | Update repository with updates for openSUSE Leap debuginfo packages from openSUSE Backports | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/update/leap/15.3/backports_debug/                       | 
 3 | repo-backports-update       | Update repository of openSUSE Backports                                                     | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/backports/                             | 
 4 | repo-debug                  | Debug Repository                                                                            | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/debug/distribution/leap/15.3/repo/oss/                  | 
 5 | repo-debug-non-oss          | Debug Repository (Non-OSS)                                                                  | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/debug/distribution/leap/15.3/repo/non-oss/              | 
 6 | repo-debug-update           | Update Repository (Debug)                                                                   | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/debug/update/leap/15.3/oss/                             | 
 7 | repo-debug-update-non-oss   | Update Repository (Debug, Non-OSS)                                                          | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/debug/update/leap/15.3/non-oss/                         | 
 8 | repo-non-oss                | Non-OSS Repository                                                                          | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.3/repo/non-oss/                    | 
 9 | repo-oss                    | Main Repository                                                                             | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/distribution/leap/15.3/repo/oss/                        | 
10 | repo-sle-debug-update       | Update repository with debuginfo for updates from SUSE Linux Enterprise 15                  | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/debug/update/leap/15.3/sle/                             | 
11 | repo-sle-update             | Update repository with updates from SUSE Linux Enterprise 15                                | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/sle/                                   | 
12 | repo-source                 | Source Repository                                                                           | No      | ----      | ----    |   99     | NONE   | http://download.opensuse.org/source/distribution/leap/15.3/repo/oss/                 | 
13 | repo-update                 | Main Update Repository                                                                      | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/oss/                                   | 
14 | repo-update-non-oss         | Update Repository (Non-Oss)                                                                 | Yes     | (r ) Yes  | Yes     |   99     | rpm-md | http://download.opensuse.org/update/leap/15.3/non-oss/                               | 

6.1 添加仓库

SUSE15:~ # zypper addrepo http://mirrors.163.com/openSUSE/update/leap/15.3/backports/ 163-update
Adding repository '163-update' ....................................................[done]
Repository '163-update' successfully added

URI         : http://mirrors.163.com/openSUSE/update/leap/15.3/backports/
Enabled     : Yes
GPG Check   : Yes
Autorefresh : No
Priority    : 99 (default priority)

Repository priorities are without effect. All enabled repositories share the same priority.

6.2 刷新

添加后需要刷新才能使用新的仓库,类似centos的yum makecache

SUSE15:~ # zypper refresh
Retrieving repository '163-update' metadata ...................................................................[done]
Building repository '163-update' cache ........................................................................[done]
Repository 'Update repository of openSUSE Backports' is up to date.                                                  
Repository 'Non-OSS Repository' is up to date.                                                                       
Repository 'Main Repository' is up to date.                                                                          
Repository 'Update repository with updates from SUSE Linux Enterprise 15' is up to date.                             
Repository 'Main Update Repository' is up to date.                                                                   
Repository 'Update Repository (Non-Oss)' is up to date.                                                              
All repositories have been refreshed.

添加--plus-content选项查看已禁用存储库中的更改

6.3. 删除仓库

通过指定id或别名来删除

SUSE15:~ # zypper removerepo 4
SUSE15:~ # zypper removerepo "Non-OSS Repository"

6.4 修改仓库

modifyrepo选项用于修改仓库的参数。例如,下面的命令用于开启名叫updates的仓库,开启自动刷新并设置优先级为20:

SUSE15:~ # zypper modifyrepo -er -p 20 'updates'

参数说明:

  • -e:打开仓库
  • -r:开启自动重刷新
  • -p:设置优先级,后面跟优先级
  • -a:所有的仓库
  • -l:本地仓库
  • -t:远程仓库
  • -m TYPE:指定仓库的类型。类型包括http , https ,ftp , cd , dvd , dir , file , cifs , smb , nfs , hd , iso

使用下面的命令重命名仓库名字(引号内的名字是修改前的):

SUSE15:~ # zypper renamerepo 'Mozilla Firefox' firefox

7 搜索

zypper提供了多种仓库和软件包的查询方式,可以通过下面的命令列出所有可用产品、模式、包或补丁的列表:

SUSE15:~ # zypper products
SUSE15:~ # zypper patterns
SUSE15:~ # zypper packages
SUSE15:~ # zypper patches

使用serach选项查询具体的软件包,使用info获取特定信息。

7.1 搜索软件包

查看含有fire关键字的软件包:

SUSE15:~ # zypper search "fire"
Loading repository data...
Reading installed packages...

S  | Name                                   | Summary                        | Type
---+----------------------------------------+--------------------------------+-----------
i  | MozillaFirefox                         | Mozilla Firefox Web Browser    | package
   | MozillaFirefox                         | Mozilla Firefox Web Browser    | srcpackage
   | MozillaFirefox-branding-SLE            | SLED branding of MozillaFire-> | package
i  | MozillaFirefox-branding-openSUSE       | openSUSE branding of Mozilla-> | package
   | MozillaFirefox-branding-upstream       | Upstream branding for Firefox  | package
...

精确匹配:

SUSE15:~ # zypper search --match-exact "MozillaFirefox"
Loading repository data...
Reading installed packages...

S | Name           | Summary                     | Type
--+----------------+-----------------------------+-----------
i | MozillaFirefox | Mozilla Firefox Web Browser | package
  | MozillaFirefox | Mozilla Firefox Web Browser | srcpackage

查看软件包中的描述和汇总信息中包含某个字段的软件包:

SUSE15:~ # zypper search -d curl
Loading repository data...
Reading installed packages...

S | Name                         | Summary                                   | Type
--+------------------------------+-------------------------------------------+-----------
  | R-curl                       | A Web Client for R                        | package
  | awesome-vicious              | Vicious plugins for awesome               | package
  | bumblebee-status-module-cmus | Widget to show information about the cu-> | package
  | bumblebee-status-module-mocp | Widget to display information about the-> | package
  | bumblebee-status-module-mpd  | Widget to display information about the-> | package
i | curl                         | A Tool for Transferring Data from URLs    | package
  | curl                         | A Tool for Transferring Data from URLs    | srcpackage
  | curl-mini                    | A Tool for Transferring Data from URLs    | srcpackage
...

仅显示没有安装的软件包:

SUSE15:~ # zypper search -u firefox
Loading repository data...
Reading installed packages...

S | Name                              | Summary                             | Type
--+-----------------------------------+-------------------------------------+-----------
  | MozillaFirefox                    | Mozilla Firefox Web Browser         | srcpackage
  | MozillaFirefox-branding-SLE       | SLED branding of MozillaFirefox     | package
  | MozillaFirefox-branding-upstream  | Upstream branding for Firefox       | package
  | MozillaFirefox-buildsymbols       | Breakpad buildsymbols for Firefox   | package
  | MozillaFirefox-devel              | Devel package for Firefox           | package
  | MozillaFirefox-translations-other | Extra translations for Firefox      | package
  | firefox-esr-branding-openSUSE     | openSUSE branding of MozillaFirefox | package
  | firefox-uget-integrator           | Integration of uGet with Firefox    | package

包含字符fir但接下来不是e字符的包(正则表达式):

SUSE15:~ # zypper search "/fir[^e]/"
Loading repository data...
Reading installed packages...

S | Name                           | Summary                                 | Type
--+--------------------------------+-----------------------------------------+-----------
  | adaptec-firmware               | Firmware files for Adaptec SAS Cards -> | package
  | alsa-firmware                  | Firmware Data Files for ALSA            | package
  | atmel-firmware                 | Firmware for Atmel at76c50x Wireless -> | package
  | bananapir2-firmware            | Binary bootloader and firmware files -> | package
  | bcm20702a1-firmware            | Firmware for BCM20702A1 based devices   | package
  | bcm43xx-firmware               | Firmware for the Broadcom/Cypress BCM-> | package
  | bladeRF-fpga-firmware          | FPGA firmware for SDR radio receiver    | package
  | bladeRF-fx3-firmware           | Microcontroller firmware for SDR radi-> | package
...

7.2 搜索特定功能的包

SUSE15:~ # zypper what-provides 'perl(SVN::Core)'
Command 'what-provides' is replaced by 'search --provides --match-exact'.
See 'help search' for all available options.
Loading repository data...
Reading installed packages...

S | Name            | Summary                                                   | Type
--+-----------------+-----------------------------------------------------------+--------
  | subversion-perl | Allows Perl scripts to directly use Subversion reposito-> | package

下面的命令提供了相同的功能,而且下面的方式更好用:

SUSE15:~ # zypper search --provides 'perl(SVN::Core)'
Loading repository data...
Reading installed packages...

S | Name            | Summary                                                   | Type
--+-----------------+-----------------------------------------------------------+--------
  | subversion-perl | Allows Perl scripts to directly use Subversion reposito-> | package
SUSE15:~ # zypper search --provides 'nmcli'
Loading repository data...
Reading installed packages...

S  | Name             | Summary                          | Type
---+------------------+----------------------------------+--------
   | nmcli-dmenu      | Control NetworkManager via dmenu | package
i+ | openSUSE-release | openSUSE Leap 15.3               | package

rpm -q --whatprovides也提供该功能,但是它只能查询RPM数据。zypper提供的查询功能不会局限于已经安装的程序,还可以查询所有的仓库中的未安装的程序。

7.4 查看包信息

使用info选项可以查询软件包的详细信息,但是必须跟具体的软件包:

SUSE15:~ # zypper info MozillaFirefox
Loading repository data...
Reading installed packages...


Information for package MozillaFirefox:
---------------------------------------
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : MozillaFirefox
Version        : 78.12.0-8.46.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 200.5 MiB
Installed      : Yes (automatically)
Status         : out-of-date (version 78.10.0-8.38.1 installed)
Source package : MozillaFirefox-78.12.0-8.46.1.src
Summary        : Mozilla Firefox Web Browser
Description    : 
    Mozilla Firefox is a standalone web browser, designed for standards
    compliance and performance.  Its functionality can be enhanced via a
    plethora of extensions.

--requires--recommends选项会查出该软件包需要/推荐安装的依赖包:

SUSE15:~ # zypper info --requires vim
Loading repository data...
Reading installed packages...


Information for package vim:
----------------------------
Repository     : Main Repository
Name           : vim
Version        : 8.0.1568-5.14.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 3.0 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : vim-8.0.1568-5.14.1.src
Summary        : Vi IMproved
Description    : 
    Vim (Vi IMproved) is an almost compatible version of the UNIX editor
    vi. Almost every possible command can be performed using only ASCII
    characters. Only the 'Q' command is missing (you do not need it). Many
    new features have been added: multilevel undo, command line history,
    file name completion, block operations, and editing of binary data.
Requires       : [16]
    libpthread.so.0()(64bit)
    libm.so.6()(64bit)
    libdl.so.2()(64bit)
    libpthread.so.0(GLIBC_2.2.5)(64bit)
    libm.so.6(GLIBC_2.2.5)(64bit)
    libc.so.6(GLIBC_2.15)(64bit)
    libdl.so.2(GLIBC_2.2.5)(64bit)
    libtinfo.so.6()(64bit)
    libtinfo.so.6(NCURSES6_TINFO_5.0.19991023)(64bit)
    libacl.so.1()(64bit)
    libacl.so.1(ACL_1.0)(64bit)
    libperl.so()(64bit)
    perl = 5.26.1
    vim-data-common = 8.0.1568-5.14.1
    /bin/sh
    update-alternatives

SUSE15:~ # zypper info --recommends vim
Loading repository data...
Reading installed packages...


Information for package vim:
----------------------------
Repository     : Main Repository
Name           : vim
Version        : 8.0.1568-5.14.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 3.0 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : vim-8.0.1568-5.14.1.src
Summary        : Vi IMproved
Description    : 
    Vim (Vi IMproved) is an almost compatible version of the UNIX editor
    vi. Almost every possible command can be performed using only ASCII
    characters. Only the 'Q' command is missing (you do not need it). Many
    new features have been added: multilevel undo, command line history,
    file name completion, block operations, and editing of binary data.
Recommends     : vim-data = 8.0.1568-5.14.1

8 配置zypper

zypper提供了可修改的配置文件,系统范围的配置文件是/etc/zypp/zypper.conf,用户级别的配置文件是~/.zypper.conf

9 排错

如果无法找到软件包,可以尝试刷新仓库列表:

SUSE15:~ # zypper refresh

如果还是有问题,可以尝试强制刷新并重建数据库:

SUSE15:~ # zypper refresh -fdb

10 zypper在btrfs文件系统上的回滚特性

如果在根分区上使用Btrfs文件系统并且安装了snapper,则Zypper在提交对文件系统的更改时会自动调用snapper以创建适当的文件系统快照。这些快照可用于恢复Zypper所做的任何更改。

Btrfs(通常念成Butter FS),是由Oracle于2007年宣布并进行中的copy-on-write文件系统。目标是取代Linux目前的ext3文件系统,改善ext3的限制,特别是单个文件的大小,总文件系统大小或文件检查和加入ext3未支持的功能,像是可写快照(writable snapshots)、快照的快照(snapshots of snapshots)、内建磁盘阵列(RAID),以及子卷(subvolumes)。Btrfs也宣称专注在“容错、修复及易于管理”。