标签 Zypper 下的文章

zypper 是 Suse Linux 系统的包和补丁管理器,你可以根据下面的 12 条附带输出示例的实用范例来学习 zypper 命令的使用。

Suse Linux 使用 zypper 进行包管理,其是一个由 ZYpp 包管理引擎提供的包管理系统。在此篇文章中我们将分享 12 条附带输出示例的实用 zypper 命令,能帮助你处理日常的系统管理任务。

不带参数的 zypper 命令将列出所有可用的选项,这比参考详细的 man 手册要容易上手得多。

root@kerneltalks # zypper
  用法:
        zypper [--global-options] <command> [--command-options] [arguments]
        zypper <subcommand> [--command-options] [arguments]
 
  全局选项:
        --help, -h              帮助
        --version, -V           输出版本号
        --promptids             输出 zypper 用户提示符列表
        --config, -c <file>     使用指定的配置文件来替代默认的
        --userdata <string>     在历史和插件中使用的用户自定义事务 id
        --quiet, -q             忽略正常输出,只打印错误信息
        --verbose, -v           增加冗长程度
        --color
        --no-color              是否启用彩色模式,如果 tty 支持的话
        --no-abbrev, -A         表格中的文字不使用缩写
        --table-style, -s       表格样式(整型)
        --non-interactive, -n   不询问任何选项,自动使用默认答案
        --non-interactive-include-reboot-patches
                                针对带有重启标志的补丁,不使用交互模式
        --xmlout, -x            切换至 XML 输出
        --ignore-unknown, -i    忽略未知的包
 
        --reposd-dir, -D <dir>  使用自定义仓库文件目录
        --cache-dir, -C <dir>   为所有缓存启用可选路径
        --raw-cache-dir <dir>   启用可选 raw 元数据缓存路径
        --solv-cache-dir <dir>  启用可选 solv 文件缓存路径
        --pkg-cache-dir <dir>   启用可选包缓存路径
 
     仓库选项:
        --no-gpg-checks         忽略 GPG 检查失败并跳过
        --gpg-auto-import-keys  自动信任并导入新仓库的签名密钥
        --plus-repo, -p <URI>   使用附加仓库
        --plus-content <tag>    另外使用禁用的仓库来提供特定的关键词
                                尝试使用 '--plus-content debug' 选项来启用仓库
        --disable-repositories  不从仓库中读取元数据
        --no-refresh            不刷新仓库
        --no-cd                 忽略 CD/DVD 中的仓库
        --no-remote             忽略远程仓库
        --releasever            设置所有 .repo 文件中的 $releasever 变量(默认值:发行版版本)
 
     Target Options:
        --root, -R <dir>        在另一个根路径下进行操作
        --disable-system-resolvables
                                不读取已安装包
 
  命令:
        help, ?                 打印帮助
        shell, sh               允许多命令
 
     仓库管理:
        repos, lr               列出所有自定义仓库
        addrepo, ar             添加一个新仓库
        removerepo, rr          移除指定仓库
        renamerepo, nr          重命名指定仓库
        modifyrepo, mr          修改指定仓库
        refresh, ref            刷新所有仓库
        clean                   清除本地缓存
 
     服务管理:
        services, ls            列出所有自定义服务
        addservice, as          添加一个新服务
        modifyservice, ms       修改指定服务
        removeservice, rs       移除指定服务
        refresh-services, refs  刷新所有服务
 
     软件管理:
        install, in             安装包
        remove, rm              移除包
        verify, ve              确认包依赖的完整性
        source-install, si      安装源码包及其构建依赖
        install-new-recommends, inr
                                安装由已安装包建议一并安装的新包
 
     更新管理:
        update, up              更新已安装包至更新版本
        list-updates, lu        列出可用更新
        patch                   安装必要的补丁
        list-patches, lp        列出必要的补丁
        dist-upgrade, dup       进行发行版更新
        patch-check, pchk       检查补丁
 
     查询:
        search, se              查找符合匹配模式的包
        info, if                展示特定包的完全信息
        patch-info              展示特定补丁的完全信息
        pattern-info            展示特定模式的完全信息
        product-info            展示特定产品的完全信息
        patches, pch            列出所有可用的补丁
        packages, pa            列出所有可用的包
        patterns, pt            列出所有可用的模式
        products, pd            列出所有可用的产品
        what-provides, wp       列出提供特定功能的包
 
     包锁定:
        addlock, al             添加一个包锁定
        removelock, rl          移除一个包锁定
        locks, ll               列出当前的包锁定
        cleanlocks, cl          移除无用的锁定
 
     其他命令:
        versioncmp, vcmp        比较两个版本字符串
        targetos, tos           打印目标操作系统 ID 字符串
        licenses                打印已安装包的证书和 EULAs 报告
        download                使用命令行下载指定 rpm 包到本地目录
        source-download         下载所有已安装包的源码 rpm 包到本地目录
 
     子命令:
        subcommand              列出可用子命令
 
输入 'zypper help <command>' 来获得特定命令的帮助。

如何使用 zypper 安装包

zypper 通过 ininstall 子命令来在你的系统上安装包。它的用法与 yum 软件包安装 相同。你只需要提供包名作为参数,包管理器(此处是 zypper)就会处理所有的依赖并与你指定的包一并安装。

# zypper install telnet
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Resolving package dependencies...
 
The following NEW package is going to be installed:
  telnet
 
1 new package to install.
Overall download size: 51.8 KiB. Already cached: 0 B. After the operation, additional 113.3 KiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package telnet-1.2-165.63.x86_64                                                                                        (1/1),  51.8 KiB (113.3 KiB unpacked)
Retrieving: telnet-1.2-165.63.x86_64.rpm .........................................................................................................................[done]
Checking for file conflicts: .....................................................................................................................................[done]
(1/1) Installing: telnet-1.2-165.63.x86_64 .......................................................................................................................[done]

以上是我们安装 telnet 包时的输出,供你参考。

推荐阅读:在 YUM 和 APT 系统中安装包

如何使用 zypper 移除包

要在 Suse Linux 中擦除或移除包,使用 zypper 附带 removerm 子命令。

root@kerneltalks # zypper rm telnet
Loading repository data...
Reading installed packages...
Resolving package dependencies...
 
The following package is going to be REMOVED:
  telnet
 
1 package to remove.
After the operation, 113.3 KiB will be freed.
Continue? [y/n/...? shows all options] (y): y
(1/1) Removing telnet-1.2-165.63.x86_64 ..........................................................................................................................[done]

我们在此处移除了先前安装的 telnet 包。

使用 zypper 检查依赖或者认证已安装包的完整性

有时可以通过强制忽略依赖关系来安装软件包。zypper 使你能够扫描所有已安装的软件包并检查其依赖性。如果缺少任何依赖项,它将提供你安装或重新安装它的机会,从而保持已安装软件包的完整性。

使用附带 verifyve 子命令的 zypper 命令来检查已安装包的完整性。

root@kerneltalks # zypper ve
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
 
Dependencies of all installed packages are satisfied.

在上面的输出中,你能够看到最后一行说明已安装包的所有依赖都已安装完全,并且无需更多操作。

如何在 Suse Linux 中使用 zypper 下载包

zypper 提供了一种方法使得你能够将包下载到本地目录而不去安装它。你可以在其他具有同样配置的系统上使用这个已下载的软件包。包会被下载至 /var/cache/zypp/packages/<repo>/<arch>/ 目录。

root@kerneltalks # zypper download telnet
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Retrieving package telnet-1.2-165.63.x86_64                                                                                        (1/1),  51.8 KiB (113.3 KiB unpacked)
(1/1) /var/cache/zypp/packages/SMT-http_smt-ec2_susecloud_net:SLES12-SP3-Pool/x86_64/telnet-1.2-165.63.x86_64.rpm ................................................[done]
 
download: Done.
 
# ls -lrt /var/cache/zypp/packages/SMT-http_smt-ec2_susecloud_net:SLES12-SP3-Pool/x86_64/
total 52
-rw-r--r-- 1 root root 53025 Feb 21 03:17 telnet-1.2-165.63.x86_64.rpm
 

你能看到我们使用 zypper 将 telnet 包下载到了本地。

推荐阅读:在 YUM 和 APT 系统中只下载包而不安装

如何使用 zypper 列出可用包更新

zypper 允许你浏览已安装包的所有可用更新,以便你可以提前计划更新活动。使用 list-updateslu 子命令来显示已安装包的所有可用更新。

root@kerneltalks # zypper lu
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
S | Repository                        | Name                       | Current Version               | Available Version                  | Arch
--|-----------------------------------|----------------------------|-------------------------------|------------------------------------|-------
v | SLES12-SP3-Updates                | at-spi2-core               | 2.20.2-12.3                   | 2.20.2-14.3.1                      | x86_64
v | SLES12-SP3-Updates                | bash                       | 4.3-82.1                      | 4.3-83.5.2                         | x86_64
v | SLES12-SP3-Updates                | ca-certificates-mozilla    | 2.7-11.1                      | 2.22-12.3.1                        | noarch
v | SLE-Module-Containers12-Updates   | containerd                 | 0.2.5+gitr639_422e31c-20.2    | 0.2.9+gitr706_06b9cb351610-16.8.1  | x86_64
v | SLES12-SP3-Updates                | crash                      | 7.1.8-4.3.1                   | 7.1.8-4.6.2                        | x86_64
v | SLES12-SP3-Updates                | rsync                      | 3.1.0-12.1                    | 3.1.0-13.10.1                      | x86_64

输出特意被格式化以便于阅读。每一列分别代表包所属仓库名称、包名、已安装版本、可用的更新版本和架构。

在 Suse Linux 中列出和安装补丁

使用 list-patcheslp 子命令来显示你的 Suse Linux 系统需要被应用的所有可用补丁。

root@kerneltalks # zypper lp
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
 
Repository                        | Name                                     | Category    | Severity  | Interactive | Status | Summary                                 
----------------------------------|------------------------------------------|-------------|-----------|-------------|--------|------------------------------------------------------------------------------------
SLE-Module-Containers12-Updates   | SUSE-SLE-Module-Containers-12-2018-273   | security    | important | ---         | needed | Version update for docker, docker-runc, containerd, golang-github-docker-libnetwork
SLE-Module-Containers12-Updates   | SUSE-SLE-Module-Containers-12-2018-62    | recommended | low       | ---         | needed | Recommended update for sle2docker       
SLE-Module-Public-Cloud12-Updates | SUSE-SLE-Module-Public-Cloud-12-2018-268 | recommended | low       | ---         | needed | Recommended update for python-ecdsa     
SLES12-SP3-Updates                | SUSE-SLE-SERVER-12-SP3-2018-116          | security    | moderate  | ---         | needed | Security update for rsync               
---- output clipped ----
SLES12-SP3-Updates                | SUSE-SLE-SERVER-12-SP3-2018-89           | security    | moderate  | ---         | needed | Security update for perl-XML-LibXML     
SLES12-SP3-Updates                | SUSE-SLE-SERVER-12-SP3-2018-90           | recommended | low       | ---         | needed | Recommended update for lvm2             
 
Found 37 applicable patches:
37 patches needed (18 security patches)

使用相应的表头可以很好地组织输出。你可以轻松地找出并根据情况计划你的补丁更新。我们能看到在我们的系统中,37 个可用补丁中有 18 个是安全补丁,需要被高优先级应用!

你可以通过发出 zypper patch 命令安装所有需要的补丁。

如何使用 zypper 更新包

要使用 zypper 更新包,使用 updateup 子命令后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 rsync 包更新可用。让我们现在来更新它吧!

root@kerneltalks # zypper update rsync
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Resolving package dependencies...
 
The following package is going to be upgraded:
  rsync
 
1 package to upgrade.
Overall download size: 325.2 KiB. Already cached: 0 B. After the operation, additional 64.0 B will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package rsync-3.1.0-13.10.1.x86_64                                                                                      (1/1), 325.2 KiB (625.5 KiB unpacked)
Retrieving: rsync-3.1.0-13.10.1.x86_64.rpm .......................................................................................................................[done]
Checking for file conflicts: .....................................................................................................................................[done]
(1/1) Installing: rsync-3.1.0-13.10.1.x86_64 .....................................................................................................................[done]

在 Suse Linux 上使用 zypper 查找包

如果你不确定包的全名也不要担心。你可以使用 zypper 附带的 sesearch 子命令并提供查找字符串来查找包。

root@kerneltalks # zypper se lvm
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
 
S  | Name          | Summary                      | Type
---|---------------|------------------------------|-----------
   | libLLVM       | Libraries for LLVM           | package
   | libLLVM-32bit | Libraries for LLVM           | package
   | llvm          | Low Level Virtual Machine    | package
   | llvm-devel    | Header Files for LLVM        | package
   | lvm2          | Logical Volume Manager Tools | srcpackage
i+ | lvm2          | Logical Volume Manager Tools | package
   | lvm2-devel    | Development files for LVM2   | package 

在上述示例中我们查找了 lvm 字符串并得到了如上输出列表。你能在 zypper install/remove/update 命令中使用 Name 字段的名字。

使用 zypper 检查已安装包信息

你能够使用 zypper 检查已安装包的详细信息。infoif 子命令将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,Installed 参数将返回 No 值。

root@kerneltalks # zypper info rsync
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
 
 
Information for package rsync:
------------------------------
Repository     : SLES12-SP3-Updates
Name           : rsync
Version        : 3.1.0-13.10.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Support Level  : Level 3
Installed Size : 625.5 KiB
Installed      : Yes
Status         : up-to-date
Source package : rsync-3.1.0-13.10.1.src
Summary        : Versatile tool for fast incremental file transfer
Description    :
    Rsync is a fast and extraordinarily versatile file  copying  tool. It can copy
    locally, to/from another host over any remote shell, or to/from a remote rsync
    daemon. It offers a large number of options that control every aspect of its
    behavior and permit very flexible specification of the set of files to be
    copied. It is famous for its delta-transfer algorithm, which reduces the amount
    of data sent over the network by sending only the differences between the
    source files and the existing files in the destination. Rsync is widely used
    for backups and mirroring and as an improved copy command for everyday use.

使用 zypper 列出仓库

使用 zypper 命令附带 lrrepos 子命令列出仓库。

root@kerneltalks # zypper lr
Refreshing service 'cloud_update'.
Repository priorities are without effect. All enabled repositories share the same priority.
 
#  | Alias                                                                                | Name                                                  | Enabled | GPG Check | Refresh
---|--------------------------------------------------------------------------------------|-------------------------------------------------------|---------|-----------|--------
 1 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Debuginfo-Pool    | SLE-Module-Adv-Systems-Management12-Debuginfo-Pool    | No      | ----      | ----
 2 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Debuginfo-Updates | SLE-Module-Adv-Systems-Management12-Debuginfo-Updates | No      | ----      | ----
 3 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Pool              | SLE-Module-Adv-Systems-Management12-Pool              | Yes     | (r ) Yes  | No
 4 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Adv-Systems-Management12-Updates           | SLE-Module-Adv-Systems-Management12-Updates           | Yes     | (r ) Yes  | Yes
 5 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Containers12-Debuginfo-Pool                | SLE-Module-Containers12-Debuginfo-Pool                | No      | ----      | ----
 6 | SMT-http_smt-ec2_susecloud_net:SLE-Module-Containers12-Debuginfo-Updates             | SLE-Module-Containers12-Debuginfo-Updates             | No      | ----      | ----

此处你需要检查 enabled 列来确定哪些仓库是已被启用的而哪些没有。

在 Suse Linux 中使用 zypper 添加或移除仓库

要添加仓库你需要仓库或 .repo 文件的 URI,否则你会遇到如下错误。

root@kerneltalks # zypper addrepo -c SLES12-SP3-Updates
If only one argument is used, it must be a URI pointing to a .repo file.

使用 URI,你可以像如下方式添加仓库:

root@kerneltalks # zypper  addrepo -c http://smt-ec2.susecloud.net/repo/SUSE/Products/SLE-SDK/12-SP3/x86_64/product?credentials=SMT-http_smt-ec2_susecloud_net SLE-SDK12-SP3-Pool
Adding repository 'SLE-SDK12-SP3-Pool' ...........................................................................................................................[done]
Repository 'SLE-SDK12-SP3-Pool' successfully added
 
URI         : http://smt-ec2.susecloud.net/repo/SUSE/Products/SLE-SDK/12-SP3/x86_64/product?credentials=SMT-http_smt-ec2_susecloud_net
Enabled     : Yes
GPG Check   : Yes
Autorefresh : No
Priority    : 99 (default priority)
 
Repository priorities are without effect. All enabled repositories share the same priority.

在 Suse 中使用附带 addrepoar 子命令的 zypper 命令添加仓库,后接 URI 以及你需要提供一个别名。

要在 Suse 中移除一个仓库,使用附带 removereporr 子命令的 zypper 命令。

root@kerneltalks # zypper removerepo nVidia-Driver-SLE12-SP3
Removing repository 'nVidia-Driver-SLE12-SP3' ....................................................................................................................[done]
Repository 'nVidia-Driver-SLE12-SP3' has been removed.

清除 zypper 本地缓存

使用 zypper clean 命令清除 zypper 本地缓存。

root@kerneltalks # zypper clean
All repositories have been cleaned up.

via: https://kerneltalks.com/commands/12-useful-zypper-command-examples/

作者:KernelTalks 译者:cycoe 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

一个 Linux 新用户应该知道他或她的进步源自于对 Linux 发行版的使用,而 Linux 发行版有好几种,并以不同的方式管理软件包。

在 Linux 中,包管理器非常重要,知道如何使用多种包管理器可以让你像一个高手一样活得很舒适,从在仓库下载软件、安装软件,到更新软件、处理依赖和删除软件是非常重要的,这也是Linux 系统管理的一个重要部分。

最好的Linux包管理器

成为一个 Linux 高手的一个标志是了解主要的 Linux 发行版如何处理包,在这篇文章中,我们应该看一些你在 Linux 上能找到的最佳的包管理器,

在这里,我们的主要重点是关于一些最佳包管理器的相关信息,但不是如何使用它们,这些留给你亲自发现。但我会提供一些有意义的链接,使用指南或更多。

1. DPKG - Debian 包管理系统 Debian Package Management System

Dpkg 是 Debian Linux 家族的基础包管理系统,它用于安装、删除、存储和提供.deb包的信息。

这是一个低层面的工具,并且有多个前端工具可以帮助用户从远程的仓库获取包,或处理复杂的包关系的工具,包括如下:

APT ( 高级打包工具 Advanced Packaging Tool )

这个是一个 dpkg 包管理系统的前端工具,它是一个非常受欢迎的、自由而强大的,有用的命令行包管理器系统。

Debian 及其衍生版,例如 Ubuntu 和 Linux Mint 的用户应该非常熟悉这个包管理工具。

想要了解它是如何工作的,你可以去看看下面这些 HOW TO 指南:

Aptitude 包管理器

这个也是 Debian Linux 家族一个非常出名的命令行前端包管理工具,它工作方式类似 APT ,它们之间有很多可以比较的地方,不过,你应该两个都试试才知道哪个工作的更好。

它最初为 Debian 及其衍生版设计的,但是现在它的功能延伸到 RHEL 家族。你可以参考这个指南了解更多关于 APT 和 Aptitude。

Synaptic 包管理器

Synaptic是一个基于GTK+的APT的可视化包管理器,对于一些不想使用命令行的用户,它非常好用。

2. RPM - 红帽包管理器 Red Hat Package Manager

这个是红帽创建的 Linux 基本标准(LSB)打包格式和基础包管理系统。基于这个底层系统,有多个前端包管理工具可供你使用,但我们应该只看那些最好的,那就是:

YUM ( 黄狗更新器,修改版 Yellowdog Updater, Modified

这个是一个开源、流行的命令行包管理器,它是用户使用 RPM 的界面(之一)。你可以把它和 Debian Linux 系统中的 APT 进行对比,它和 APT 拥有相同的功能。你可以从这个 HOW TO 指南中的例子更加清晰的理解YUM:

DNF( 优美的 Yum Dandified Yum

这个也是一个用于基于 RPM 的发行版的包管理器,Fedora 18 引入了它,它是下一代 YUM。

如果你用 Fedora 22 及更新版本,你肯定知道它是默认的包管理器。这里有一些链接,将为你提供更多关于 DNF 的信息和如何使用它。

3. Pacman 包管理器 – Arch Linux

这个是一个流行的、强大而易用的包管理器,它用于 Arch Linux 和其他的一些小众发行版。它提供了一些其他包管理器提供的基本功能,包括安装、自动解决依赖关系、升级、卸载和降级软件。

但是最大的用处是,它为 Arch 用户创建了一个简单易用的包管理方式。你可以阅读 Pacman 概览,它会解释上面提到的一些功能。

4. Zypper 包管理器 – openSUSE

这个是一个使用 libzypp 库制作的用于 OpenSUSE 系统上的命令行包管理器,它的常用功能包括访问仓库、安装包、解决依赖问题和其他功能。

更重要的是,它也可以支持存储库扩展功能,如模式、补丁和产品。新的 OpenSUSE 用户可以参考下面的链接来掌控它。

5. Portage 包管理器 – Gentoo

这个是 Gentoo 的包管理器,当下不怎么流行的一个发行版,但是这并不阻止它成为 Linux 下最好的软件包管理器之一。

Portage 项目的主要目标是创建一个简单、无故障的包管理系统,包含向后兼容、自动化等功能。

如果希望理解的更清晰,可以看下: Portage 项目页

结束语

正如我在开始时提到的,这个指南的主要意图是给 Linux 用户提供一个最佳软件包管理器的列表,但知道如何使用它们可以通过其后提供的重要的链接,并实际去试试它们。

各个发行版的用户需要学习超出他们的发行版之外的一些东西,才能更好理解上述提到的这些不同的包管理器。


via: http://www.tecmint.com/linux-package-managers/

作者:Ravi Saive 译者:Bestony 校对:wxy

本文由 LCTT 原创翻译,Linux中国 荣誉推出

SUSE( Software and System Entwicklung,即软件和系统开发。其中‘entwicklung‘是德语,意为开发)Linux 是由 Novell 公司在 Linux 内核基础上建立的操作系统。SUSE Linux 有两个发行分支。其中之一名为 openSUSE,这是一款自由而且免费的操作系统 (free as in speech as well as free as in wine)。该系统由开源社区开发维护,支持一些最新版本的应用软件,其最新的稳定版本为 13.2。

另外一个分支是 SUSE Linux 企业版。该分支是一个为企业及商业化产品设计的 Linux 发行版,包含了大量的企业应用以及适用于商业产品生产环境的特性。其最新的稳定版本为 12。

以下的链接包含了安装企业版 SUSE Linux 服务器的详细信息。

Zypper 和 Yast 是 SUSE Linux 平台上的软件包管理工具,他们的底层使用了 RPM(LCTT 译者注:RPM 最初指 Redhat Pacakge Manager ,现普遍解释为递归短语 RPM Package Manager 的缩写)。

Yast(Yet another Setup Tool )是 OpenSUSE 以及企业版 SUSE 上用于系统管理、设置和配置的工具。

Zypper 是软件包管理器ZYpp的命令行接口,可用于安装、删除SUSE Linux上的软件以及进行系统更新。ZYpp为Zypper和Yast提供底层支持。

本文将介绍实际应用中常见的一些Zypper命令。这些命令用来进行安装、更新、删除等任何软件包管理器所能够胜任的工作。

重要 : 切记所有的这些命令都将在系统全局范围内产生影响,所以必须以 root 身份执行,否则命令将失败。

获取基本的 Zypper 帮助信息

  1. 不带任何选项的执行 zypper, 将输出该命令的全局选项以及子命令列表(LCTT 译者注:全局选项,global option,控制台命令的输入分为可选参数和位置参数两大类。按照习惯,一般可选参数称为选项'option',而位置参数称为参数 'argument')。
#  zypper
    Usage:
    zypper [--global-options]
  1. 获取一个具体的子命令的帮助信息,比如 'in' (install),可以执行下面的命令
# zypper help in

或者

# zypper help install
install (in) [options] {capability | rpm_file_uri}

Install packages with specified capabilities or RPM files with specified
location. A capability is NAME[.ARCH][OP], where OP is one
of <, <=, =, >=, >.

  Command options:
--from <alias|#|URI>    Select packages from the specified repository.
-r, --repo <alias|#|URI>    Load only the specified repository.
-t, --type            Type of package (package, patch, pattern, product, srcpackage).
                            Default: package.
-n, --name                  Select packages by plain name, not by capability.
-C, --capability            Select packages by capability.
-f, --force                 Install even if the item is already installed (reinstall),
                            downgraded or changes vendor or architecture.
    --oldpackage            Allow to replace a newer item with an older one.
                            Handy if you are doing a rollback. Unlike --force
                            it will not enforce a reinstall.
    --replacefiles          Install the packages even if they replace files from other,
                            already installed, packages. Default is to treat file conflicts
                            as an error. --download-as-needed disables the fileconflict check.
...... 
  1. 安装之前搜索一个安转包(以 gnome-desktop 为例 )
# zypper se gnome-desktop

Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ......................................................... [done]
Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]
Retrieving repository 'openSUSE-13.2-Oss' metadata ..............................................................[done]
Building repository 'openSUSE-13.2-Oss' cache ...................................................................[done]
Retrieving repository 'openSUSE-13.2-Update' metadata ...........................................................[done]
Building repository 'openSUSE-13.2-Update' cache ................................................................[done]
Retrieving repository 'openSUSE-13.2-Update-Non-Oss' metadata ...................................................[done]
Building repository 'openSUSE-13.2-Update-Non-Oss' cache ........................................................[done]
Loading repository data...
Reading installed packages...

S | Name                                  | Summary                                                   | Type
--+---------------------------------------+-----------------------------------------------------------+-----------
  | gnome-desktop2-lang                   | Languages for package gnome-desktop2                      | package
  | gnome-desktop2                        | The GNOME Desktop API Library                             | package
  | libgnome-desktop-2-17                 | The GNOME Desktop API Library                             | package
  | libgnome-desktop-3-10                 | The GNOME Desktop API Library                             | package
  | libgnome-desktop-3-devel              | The GNOME Desktop API Library -- Development Files        | package
  | libgnome-desktop-3_0-common           | The GNOME Desktop API Library -- Common data files        | package
  | gnome-desktop-debugsource             | Debug sources for package gnome-desktop                   | package
  | gnome-desktop-sharp2-debugsource      | Debug sources for package gnome-desktop-sharp2            | package
  | gnome-desktop2-debugsource            | Debug sources for package gnome-desktop2                  | package
  | libgnome-desktop-2-17-debuginfo       | Debug information for package libgnome-desktop-2-17       | package
  | libgnome-desktop-3-10-debuginfo       | Debug information for package libgnome-desktop-3-10       | package
  | libgnome-desktop-3_0-common-debuginfo | Debug information for package libgnome-desktop-3_0-common | package
  | libgnome-desktop-2-17-debuginfo-32bit | Debug information for package libgnome-desktop-2-17       | package
  | libgnome-desktop-3-10-debuginfo-32bit | Debug information for package libgnome-desktop-3-10       | package
  | gnome-desktop-sharp2                  | Mono bindings for libgnome-desktop                        | package
  | libgnome-desktop-2-devel              | The GNOME Desktop API Library -- Development Files        | packag
  | gnome-desktop-lang                    | Languages for package gnome-desktop                       | package
  | libgnome-desktop-2-17-32bit           | The GNOME Desktop API Library                             | package
  | libgnome-desktop-3-10-32bit           | The GNOME Desktop API Library                             | package
  | gnome-desktop                         | The GNOME Desktop API Library                             | srcpackage
  1. 获取一个模式包的信息(以 lamp\_server 为例)。
# zypper info -t pattern lamp_server

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

Information for pattern lamp_server:
------------------------------------
Repository: openSUSE-13.2-Update
Name: lamp_server
Version: 20141007-5.1
Arch: x86_64
Vendor: openSUSE
Installed: No
Visible to User: Yes
Summary: Web and LAMP Server
Description: 
  Software to set up a Web server that is able to serve static, dynamic, and interactive content (like a Web shop). This includes Apache HTTP Server, the database management system MySQL,
  and scripting languages such as PHP, Python, Ruby on Rails, or Perl.
Contents:

S | Name                          | Type    | Dependency
--+-------------------------------+---------+-----------
  | apache2-mod_php5              | package |
  | php5-iconv                    | package |
i | patterns-openSUSE-base        | package |
i | apache2-prefork               | package |
  | php5-dom                      | package |
  | php5-mysql                    | package |
i | apache2                       | package |
  | apache2-example-pages         | package |
  | mariadb                       | package |
  | apache2-mod_perl              | package |
  | php5-ctype                    | package |
  | apache2-doc                   | package |
  | yast2-http-server             | package |
  | patterns-openSUSE-lamp_server | package |
  1. 开启一个Zypper Shell 的会话。
# zypper shell 

或者

# zypper sh 
zypper> help
  Usage:
    zypper [--global-options]

注意:在 Zypper shell里面可以通过键入 ‘help‘ 获得全局选项以及子命令的列表。

Zypper 软件库管理

列举已定义的软件库

  1. 使用 'zypper repos' 或者 'zypper lr' 来列举所有已定以的软件库。
# zypper repos

或者

# zypper lr
  | Alias                     | Name                               | Enabled | Refresh
--+---------------------------+------------------------------------+---------+--------
1 | openSUSE-13.2-0           | openSUSE-13.2-0                    | Yes     | No
2 | repo-debug                | openSUSE-13.2-Debug                | Yes     | Yes
3 | repo-debug-update         | openSUSE-13.2-Update-Debug         | No      | Yes
4 | repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss | No      | Yes
5 | repo-non-oss              | openSUSE-13.2-Non-Oss              | Yes     | Yes
6 | repo-oss                  | openSUSE-13.2-Oss                  | Yes     | Yes
7 | repo-source               | openSUSE-13.2-Source               | No      | Yes
8 | repo-update               | openSUSE-13.2-Update               | Yes     | Yes
9 | repo-update-non-oss       | openSUSE-13.2-Update-Non-Oss       | Yes     | Yes
  1. 在表格里面显示 zypper URI
# zypper lr -u
  | Alias                     | Name                               | Enabled | Refresh | URI
--+---------------------------+------------------------------------+---------+---------+----------------------------------------------------------------
1 | openSUSE-13.2-0           | openSUSE-13.2-0                    | Yes     | No      | cd:///?devices=/dev/disk/by-id/ata-VBOX_CD-ROM_VB2-01700376
2 | repo-debug                | openSUSE-13.2-Debug                | Yes     | Yes     | http://download.opensuse.org/debug/distribution/13.2/repo/oss/
3 | repo-debug-update         | openSUSE-13.2-Update-Debug         | No      | Yes     | http://download.opensuse.org/debug/update/13.2/
4 | repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss | No      | Yes     | http://download.opensuse.org/debug/update/13.2-non-oss/
5 | repo-non-oss              | openSUSE-13.2-Non-Oss              | Yes     | Yes     | http://download.opensuse.org/distribution/13.2/repo/non-oss/
6 | repo-oss                  | openSUSE-13.2-Oss                  | Yes     | Yes     | http://download.opensuse.org/distribution/13.2/repo/oss/
7 | repo-source               | openSUSE-13.2-Source               | No      | Yes     | http://download.opensuse.org/source/distribution/13.2/repo/oss/
8 | repo-update               | openSUSE-13.2-Update               | Yes     | Yes     | http://download.opensuse.org/update/13.2/
9 | repo-update-non-oss       | openSUSE-13.2-Update-Non-Oss       | Yes     | Yes     | http://download.opensuse.org/update/13.2-non-oss/
  1. 根据优先级列举软件库。
# zypper lr -P
  | Alias                     | Name                               | Enabled | Refresh | Priority
--+---------------------------+------------------------------------+---------+---------+---------
1 | openSUSE-13.2-0           | openSUSE-13.2-0                    | Yes     | No      |   99
2 | repo-debug                | openSUSE-13.2-Debug                | Yes     | Yes     |   99
3 | repo-debug-update         | openSUSE-13.2-Update-Debug         | No      | Yes     |   99
4 | repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss | No      | Yes     |   99
5 | repo-non-oss              | openSUSE-13.2-Non-Oss              | Yes     | Yes     |   85
6 | repo-oss                  | openSUSE-13.2-Oss                  | Yes     | Yes     |   99
7 | repo-source               | openSUSE-13.2-Source               | No      | Yes     |   99
8 | repo-update               | openSUSE-13.2-Update               | Yes     | Yes     |   99
9 | repo-update-non-oss       | openSUSE-13.2-Update-Non-Oss       | Yes     | Yes     |   99

刷新软件库

  1. 使用 'zypper refresh' or 'zypper ref' 来刷新 zypper 软件库。
# zypper refresh 

或者

# zypper ref
Repository 'openSUSE-13.2-0' is up to date.
Repository 'openSUSE-13.2-Debug' is up to date.
Repository 'openSUSE-13.2-Non-Oss' is up to date.
Repository 'openSUSE-13.2-Oss' is up to date.
Repository 'openSUSE-13.2-Update' is up to date.
Repository 'openSUSE-13.2-Update-Non-Oss' is up to date.
All repositories have been refreshed. 
  1. 刷新一个指定的软件库(以 'repo-non-oss' 为例 )。
# zypper refresh repo-non-oss
Repository 'openSUSE-13.2-Non-Oss' is up to date.
Specified repositories have been refreshed. 
  1. 强制更新一个软件库(以 'repo-non-oss' 为例 )。
# zypper ref -f repo-non-oss 
Forcing raw metadata refresh
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ............................................................[done]
Forcing building of repository cache
Building repository 'openSUSE-13.2-Non-Oss' cache ............................................................[done]
Specified repositories have been refreshed.

修改软件库

本文中我们使用‘zypper modifyrepo‘ 或者 ‘zypper mr‘ 来关闭或者开启 zypper 软件库。

  1. 在关闭一个软件库之前,我们需要知道在 zypper 中,每一个软件库有一个唯一的标示数字与之关联,该数字用于打开或者关闭与之相联系的软件库。假设我们需要关闭 'repo-oss' 软件库,那么我们可以通过以下的法来获得该软件库的标志数字。
# zypper lr
  | Alias                     | Name                               | Enabled | Refresh
--+---------------------------+------------------------------------+---------+--------
1 | openSUSE-13.2-0           | openSUSE-13.2-0                    | Yes     | No
2 | repo-debug                | openSUSE-13.2-Debug                | Yes     | Yes
3 | repo-debug-update         | openSUSE-13.2-Update-Debug         | No      | Yes
4 | repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss | No      | Yes
5 | repo-non-oss              | openSUSE-13.2-Non-Oss              | Yes     | Yes
6 | repo-oss                  | openSUSE-13.2-Oss                  | No      | Yes
7 | repo-source               | openSUSE-13.2-Source               | No      | Yes
8 | repo-update               | openSUSE-13.2-Update               | Yes     | Yes
9 | repo-update-non-oss       | openSUSE-13.2-Update-Non-Oss       | Yes     | Yes

从以上输出的列表中我们可以看到 'repo-oss' 库的标示数字是 6,因此通过以下的命令来关闭该库。

# zypper mr -d 6
Repository 'repo-oss' has been successfully disabled.
  1. 如果需要再次开启软件库 ‘repo-oss‘, 接上例,与之相关联的标示数字为 6。
# zypper mr -e 6
Repository 'repo-oss' has been successfully enabled.
  1. 针对某一个软件库(以 'repo-non-oss' 为例 )开启自动刷新( auto-refresh )和 rpm 缓存,并设置该软件库的优先级,比如85。
# zypper mr -rk -p 85 repo-non-oss
Repository 'repo-non-oss' priority has been left unchanged (85)
Nothing to change for repository 'repo-non-oss'.
  1. 对所有的软件库关闭 rpm 文件缓存。
# zypper mr -Ka
RPM files caching has been disabled for repository 'openSUSE-13.2-0'.
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
  1. 对所有的软件库开启 rpm 文件缓存。
# zypper mr -ka
RPM files caching has been enabled for repository 'openSUSE-13.2-0'.
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.
  1. 关闭远程库的 rpm 文件缓存
# zypper mr -Kt
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
  1. 开启远程软件库的 rpm 文件缓存。
# zypper mr -kt
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.

增加新的软件库

可以通过这两个 zypper 指令 – 'zypper addrepo' 和 'zypper ar' 来增加新的软件库。在此过程中可以使用 URL 或者软件库的别名。

  1. 增加一个新的软件库( 以 “http://download.opensuse.org/update/12.3/” 为例 )。
# zypper ar http://download.opensuse.org/update/11.1/ update
Adding repository 'update' .............................................................................................................................................................[done]
Repository 'update' successfully added
Enabled     : Yes
Autorefresh : No
GPG check   : Yes
URI         : http://download.opensuse.org/update/11.1/
  1. 更改一个软件库的名字,这将仅仅改变软件库的别名。 命令 'zypper namerepo' 或者 'zypperr nr' 可以胜任此工作。例如更改标示数字为10的软件库的名字为 'upd8',或者说将标示数字为10的软件库的别名改为 'upd8',可以使用下面的命令。
# zypper nr 10 upd8
Repository 'update' renamed to 'upd8'.

删除软件库

  1. 删除一个软件库。要从系统删除一个软件库可以使 'zypper removerepo' 或者 'zypper rr'。例如以下的命令可以删除软件库 'upd8'
# zypper rr upd8
# Removing repository 'upd8' .........................................................................................[done]
Repository 'upd8' has been removed.

使用 zypper 进行软件包管理

用 zypper 安装一个软件包

  1. 在 zypper 中,我们可以通过软件包的功能名称来安装一个软件包。以 Firefox 为例,以下的命令可以用来安装该软件包。
# zypper in MozillaFirefox
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 128 NEW packages are going to be installed:
  adwaita-icon-theme at-spi2-atk-common at-spi2-atk-gtk2 at-spi2-core cantarell-fonts cups-libs desktop-file-utils fontconfig gdk-pixbuf-query-loaders gstreamer gstreamer-fluendo-mp3
  gstreamer-plugins-base gtk2-branding-openSUSE gtk2-data gtk2-immodule-amharic gtk2-immodule-inuktitut gtk2-immodule-thai gtk2-immodule-vietnamese gtk2-metatheme-adwaita
  gtk2-theming-engine-adwaita gtk2-tools gtk3-data gtk3-metatheme-adwaita gtk3-tools hicolor-icon-theme hicolor-icon-theme-branding-openSUSE libasound2 libatk-1_0-0 libatk-bridge-2_0-0
  libatspi0 libcairo2 libcairo-gobject2 libcanberra0 libcanberra-gtk0 libcanberra-gtk2-module libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra-gtk-module-common libcdda_interface0
  libcdda_paranoia0 libcolord2 libdrm2 libdrm_intel1 libdrm_nouveau2 libdrm_radeon1 libFLAC8 libfreebl3 libgbm1 libgdk_pixbuf-2_0-0 libgraphite2-3 libgstapp-1_0-0 libgstaudio-1_0-0
  libgstpbutils-1_0-0 libgstreamer-1_0-0 libgstriff-1_0-0 libgsttag-1_0-0 libgstvideo-1_0-0 libgthread-2_0-0 libgtk-2_0-0 libgtk-3-0 libharfbuzz0 libjasper1 libjbig2 libjpeg8 libjson-c2
  liblcms2-2 libLLVM libltdl7 libnsssharedhelper0 libogg0 liborc-0_4-0 libpackagekit-glib2-18 libpango-1_0-0 libpciaccess0 libpixman-1-0 libpulse0 libsndfile1 libsoftokn3 libspeex1
  libsqlite3-0 libstartup-notification-1-0 libtheoradec1 libtheoraenc1 libtiff5 libvisual libvorbis0 libvorbisenc2 libvorbisfile3 libwayland-client0 libwayland-cursor0 libwayland-server0
  libX11-xcb1 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb-util1 libxcb-xfixes0 libXcomposite1 libXcursor1 libXdamage1 libXevie1
  libXfixes3 libXft2 libXi6 libXinerama1 libxkbcommon-0_4_3 libXrandr2 libXrender1 libxshmfence1 libXtst6 libXv1 libXxf86vm1 Mesa Mesa-libEGL1 Mesa-libGL1 Mesa-libglapi0
  metatheme-adwaita-common MozillaFirefox MozillaFirefox-branding-openSUSE mozilla-nss mozilla-nss-certs PackageKit-gstreamer-plugin pango-tools sound-theme-freedesktop

The following 10 recommended packages were automatically selected:
  gstreamer-fluendo-mp3 gtk2-branding-openSUSE gtk2-data gtk2-immodule-amharic gtk2-immodule-inuktitut gtk2-immodule-thai gtk2-immodule-vietnamese libcanberra0 libpulse0
  PackageKit-gstreamer-plugin

128 new packages to install.
Overall download size: 77.2 MiB. Already cached: 0 B  After the operation, additional 200.0 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package cantarell-fonts-0.0.16-1.1.noarch                                                                                                   (1/128),  74.1 KiB (115.6 KiB unpacked)
Retrieving: cantarell-fonts-0.0.16-1.1.noarch.rpm .........................................................................................................................[done (63.4 KiB/s)]
Retrieving package hicolor-icon-theme-0.13-2.1.2.noarch                                                                                                (2/128),  40.1 KiB ( 50.5 KiB unpacked)
Retrieving: hicolor-icon-theme-0.13-2.1.2.noarch.rpm ...................................................................................................................................[done]
Retrieving package sound-theme-freedesktop-0.8-7.1.2.noarch                                                                                            (3/128), 372.6 KiB (460.3 KiB unpacked) 
  1. 安装指定版本号的软件包,(以 gcc 5.1 为例)。
# zypper in 'gcc<5.1'
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 13 NEW packages are going to be installed:
  cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49

13 new packages to install.
Overall download size: 14.5 MiB. Already cached: 0 B  After the operation, additional 49.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y 
  1. 为特定的CPU架构安装软件包(以兼容 i586 的 gcc 为例)。
# zypper in gcc.i586
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 13 NEW packages are going to be installed:
  cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49

13 new packages to install.
Overall download size: 14.5 MiB. Already cached: 0 B  After the operation, additional 49.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package libasan0-4.8.3+r212056-2.2.4.x86_64                                                                                                  (1/13),  74.2 KiB (166.9 KiB unpacked)
Retrieving: libasan0-4.8.3+r212056-2.2.4.x86_64.rpm .......................................................................................................................[done (79.2 KiB/s)]
Retrieving package libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64                                                                                          (2/13),  14.3 KiB ( 26.1 KiB unpacked)
Retrieving: libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm ...............................................................................................................[done (55.3 KiB/s)] 
  1. 为特定的CPU架构安装指定版本号的软件包(以兼容 i586 且版本低于5.1的 gcc 为例)
# zypper in 'gcc.i586<5.1'
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 13 NEW packages are going to be installed:
  cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49

13 new packages to install.
Overall download size: 14.4 MiB. Already cached: 129.5 KiB  After the operation, additional 49.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y
In cache libasan0-4.8.3+r212056-2.2.4.x86_64.rpm                                                                                                        (1/13),  74.2 KiB (166.9 KiB unpacked)
In cache libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm                                           (2/13),  14.3 KiB ( 26.1 KiB unpacked)
In cache libgomp1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm                                             (3/13),  41.1 KiB ( 90.7 KiB unpacked) 
  1. 从指定的软件库里面安装一个软件包,例如从 amarok 中安装 libxine。
# zypper in amarok upd:libxine1
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 202 NEW packages are going to be installed:
  amarok bundle-lang-kde-en clamz cups-libs enscript fontconfig gdk-pixbuf-query-loaders ghostscript-fonts-std gptfdisk gstreamer gstreamer-plugins-base hicolor-icon-theme
  hicolor-icon-theme-branding-openSUSE htdig hunspell hunspell-tools icoutils ispell ispell-american kde4-filesystem kdebase4-runtime kdebase4-runtime-branding-openSUSE kdelibs4
  kdelibs4-branding-openSUSE kdelibs4-core kdialog libakonadi4 l
.....
  1. 通过指定软件包的名字安装软件包。
# zypper in -n git
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 35 NEW packages are going to be installed:
  cvs cvsps fontconfig git git-core git-cvs git-email git-gui gitk git-svn git-web libserf-1-1 libsqlite3-0 libXft2 libXrender1 libXss1 perl-Authen-SASL perl-Clone perl-DBD-SQLite perl-DBI
  perl-Error perl-IO-Socket-SSL perl-MLDBM perl-Net-Daemon perl-Net-SMTP-SSL perl-Net-SSLeay perl-Params-Util perl-PlRPC perl-SQL-Statement perl-Term-ReadKey subversion subversion-perl tcl
  tk xhost

The following 13 recommended packages were automatically selected:
  git-cvs git-email git-gui gitk git-svn git-web perl-Authen-SASL perl-Clone perl-MLDBM perl-Net-Daemon perl-Net-SMTP-SSL perl-PlRPC perl-SQL-Statement

The following package is suggested, but will not be installed:
  git-daemon

35 new packages to install.
Overall download size: 15.6 MiB. Already cached: 0 B  After the operation, additional 56.7 MiB will be used.
Continue? [y/n/? shows all options] (y): y 
  1. 通过通配符来安装软件包,例如,安装所有 php5 的软件包。
# zypper in php5*
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: php5-5.6.1-18.1.x86_64 requires smtp_daemon, but this requirement cannot be provided
  uninstallable providers: exim-4.83-3.1.8.x86_64[openSUSE-13.2-0]
                   postfix-2.11.0-5.2.2.x86_64[openSUSE-13.2-0]
                   sendmail-8.14.9-2.2.2.x86_64[openSUSE-13.2-0]
                   exim-4.83-3.1.8.i586[repo-oss]
                   msmtp-mta-1.4.32-2.1.3.i586[repo-oss]
                   postfix-2.11.0-5.2.2.i586[repo-oss]
                   sendmail-8.14.9-2.2.2.i586[repo-oss]
                   exim-4.83-3.1.8.x86_64[repo-oss]
                   msmtp-mta-1.4.32-2.1.3.x86_64[repo-oss]
                   postfix-2.11.0-5.2.2.x86_64[repo-oss]
                   sendmail-8.14.9-2.2.2.x86_64[repo-oss]
                   postfix-2.11.3-5.5.1.i586[repo-update]
                   postfix-2.11.3-5.5.1.x86_64[repo-update]
 Solution 1: Following actions will be done:
  do not install php5-5.6.1-18.1.x86_64
  do not install php5-pear-Auth_SASL-1.0.6-7.1.3.noarch
  do not install php5-pear-Horde_Http-2.0.1-6.1.3.noarch
  do not install php5-pear-Horde_Image-2.0.1-6.1.3.noarch
  do not install php5-pear-Horde_Kolab_Format-2.0.1-6.1.3.noarch
  do not install php5-pear-Horde_Ldap-2.0.1-6.1.3.noarch
  do not install php5-pear-Horde_Memcache-2.0.1-7.1.3.noarch
  do not install php5-pear-Horde_Mime-2.0.2-6.1.3.noarch
  do not install php5-pear-Horde_Oauth-2.0.0-6.1.3.noarch
  do not install php5-pear-Horde_Pdf-2.0.1-6.1.3.noarch
....
  1. 使用模式名称(模式名称是一类软件包的名字)来批量安装软件包。
# zypper in -t pattern lamp_server
ading repository data...
Reading installed packages...
Resolving package dependencies...

The following 29 NEW packages are going to be installed:
  apache2 apache2-doc apache2-example-pages apache2-mod_perl apache2-prefork patterns-openSUSE-lamp_server perl-Data-Dump perl-Encode-Locale perl-File-Listing perl-HTML-Parser
  perl-HTML-Tagset perl-HTTP-Cookies perl-HTTP-Daemon perl-HTTP-Date perl-HTTP-Message perl-HTTP-Negotiate perl-IO-HTML perl-IO-Socket-SSL perl-libwww-perl perl-Linux-Pid
  perl-LWP-MediaTypes perl-LWP-Protocol-https perl-Net-HTTP perl-Net-SSLeay perl-Tie-IxHash perl-TimeDate perl-URI perl-WWW-RobotRules yast2-http-server

The following NEW pattern is going to be installed:
  lamp_server

The following 10 recommended packages were automatically selected:
  apache2 apache2-doc apache2-example-pages apache2-mod_perl apache2-prefork perl-Data-Dump perl-IO-Socket-SSL perl-LWP-Protocol-https perl-TimeDate yast2-http-server

29 new packages to install.
Overall download size: 7.2 MiB. Already cached: 1.2 MiB  After the operation, additional 34.7 MiB will be used.
Continue? [y/n/? shows all options] (y): 
  1. 使用一行命令安装一个软件包同时卸载另一个软件包,例如在安装 nano 的同时卸载 vi
# zypper in nano -vi
Loading repository data...
Reading installed packages...
'-vi' not found in package names. Trying capabilities.
Resolving package dependencies...

The following 2 NEW packages are going to be installed:
  nano nano-lang

The following package is going to be REMOVED:
  vim

The following recommended package was automatically selected:
  nano-lang

2 new packages to install, 1 to remove.
Overall download size: 550.0 KiB. Already cached: 0 B  After the operation, 463.3 KiB will be freed.
Continue? [y/n/? shows all options] (y):
...
  1. 使用 zypper 安装 rpm 软件包。
# zypper in teamviewer*.rpm
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 24 NEW packages are going to be installed:
  alsa-oss-32bit fontconfig-32bit libasound2-32bit libexpat1-32bit libfreetype6-32bit libgcc_s1-gcc49-32bit libICE6-32bit libjpeg62-32bit libpng12-0-32bit libpng16-16-32bit libSM6-32bit
  libuuid1-32bit libX11-6-32bit libXau6-32bit libxcb1-32bit libXdamage1-32bit libXext6-32bit libXfixes3-32bit libXinerama1-32bit libXrandr2-32bit libXrender1-32bit libXtst6-32bit
  libz1-32bit teamviewer

The following recommended package was automatically selected:
  alsa-oss-32bit

24 new packages to install.
Overall download size: 41.2 MiB. Already cached: 0 B  After the operation, additional 119.7 MiB will be used.
Continue? [y/n/? shows all options] (y):
..

使用 zypper 卸载软件包

  1. 命令 ‘zypper remove‘ 和 ‘zypper rm‘ 用于卸载软件包。例如卸载 apache2:
# zypper remove apache2 

或者

# zypper rm apache2
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 packages are going to be REMOVED:
  apache2 apache2-prefork

2 packages to remove.
After the operation, 4.2 MiB will be freed.
Continue? [y/n/? shows all options] (y): y
(1/2) Removing apache2-2.4.10-19.1 ........................................................................[done]
(2/2) Removing apache2-prefork-2.4.10-19.1 ................................................................[done] 

使用Zypper 进行软件包更新

  1. 更新所有的软件包,可以使用 ‘zypper update‘ 或者 ‘zypper up‘。
# zypper up 

或者

# zypper update

Loading repository data...
Reading installed packages...
Nothing to do. 
  1. 更新指定的软件包,例如更新 apache2 以及 openssh。
 zypper up apache2 openssh
Loading repository data...
Reading installed packages...
No update candidate for 'apache2-2.4.10-19.1.x86_64'. The highest available version is already installed.
No update candidate for 'openssh-6.6p1-5.1.3.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
  1. 安装一个软件库,例如 mariadb,如果该库存在则更新之。
# zypper in mariadb
Loading repository data...
Reading installed packages...
'mariadb' is already installed.
No update candidate for 'mariadb-10.0.13-2.6.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.

安装源文件并且构建依赖关系

命令 ‘zypper source-install‘ 或者 ‘zypper si‘ 可以用于从源文件编译软件包

  1. 安装某一个软件包的源文件及其依赖关系,例如 mariadb。
# zypper si mariadb
Reading installed packages...
Loading repository data...
Resolving package dependencies...

The following 36 NEW packages are going to be installed:
  autoconf automake bison cmake cpp cpp48 gcc gcc48 gcc48-c++ gcc-c++ libaio-devel libarchive13 libasan0 libatomic1-gcc49 libcloog-isl4 libedit-devel libevent-devel libgomp1-gcc49 libisl10
  libitm1-gcc49 libltdl7 libmpc3 libmpfr4 libopenssl-devel libstdc++48-devel libtool libtsan0-gcc49 m4 make ncurses-devel pam-devel readline-devel site-config tack tcpd-devel zlib-devel

The following source package is going to be installed:
  mariadb

36 new packages to install, 1 source package.
Overall download size: 71.5 MiB. Already cached: 129.5 KiB  After the operation, additional 183.9 MiB will be used.
Continue? [y/n/? shows all options] (y): y 
  1. 仅为某一个软件包安装源文件,例如 mariadb
# zypper in -D mariadb
Loading repository data...
Reading installed packages...
'mariadb' is already installed.
No update candidate for 'mariadb-10.0.13-2.6.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do. 
  1. 仅为某一个软件包安装依赖关系,例如 mariadb
# zypper si -d mariadb
Reading installed packages...
Loading repository data...
Resolving package dependencies...

The following 36 NEW packages are going to be installed:
  autoconf automake bison cmake cpp cpp48 gcc gcc48 gcc48-c++ gcc-c++ libaio-devel libarchive13 libasan0 libatomic1-gcc49 libcloog-isl4 libedit-devel libevent-devel libgomp1-gcc49 libisl10
  libitm1-gcc49 libltdl7 libmpc3 libmpfr4 libopenssl-devel libstdc++48-devel libtool libtsan0-gcc49 m4 make ncurses-devel pam-devel readline-devel site-config tack tcpd-devel zlib-devel

The following package is recommended, but will not be installed due to conflicts or dependency issues:
  readline-doc

36 new packages to install.
Overall download size: 33.7 MiB. Already cached: 129.5 KiB  After the operation, additional 144.3 MiB will be used.
Continue? [y/n/? shows all options] (y): y

在脚本和应用中调用 Zypper (非交互式)

  1. 安装一个软件包,并且在安装过程中跳过与用户的交互, 例如 mariadb。
# zypper --non-interactive in mariadb
Loading repository data...
Reading installed packages...
'mariadb' is already installed.
No update candidate for 'mariadb-10.0.13-2.6.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
  1. 卸载一个软件包,并且在卸载过程中跳过与用户的交互,例如 mariadb
# zypper --non-interactive rm mariadb
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following package is going to be REMOVED:
  mariadb

1 package to remove.
After the operation, 71.8 MiB will be freed.
Continue? [y/n/? shows all options] (y): y
(1/1) Removing mariadb-10.0.13-2.6.1 .............................................................................[done] 
  1. 以 XML 格式显示 zypper 的输出。
# zypper --xmlout
  Usage:
    zypper [--global-options]  [--command-options] [arguments]

  Global Options
....
  1. 在安装过程中禁止详细信息输出到屏幕。
# zypper --quiet in mariadb
The following NEW package is going to be installed:
  mariadb

1 new package to install.
Overall download size: 0 B. Already cached: 7.8 MiB  After the operation, additional 71.8 MiB will be used.
Continue? [y/n/? shows all options] (y):
...
  1. 在卸载过程中禁止详细信息输出到屏幕
# zypper --quiet rm mariadb 
  1. 自动地同意版权或者协议。
# zypper patch --auto-agree-with-licenses
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Nothing to do.

清除 Zypper 缓存以及查看历史信息

  1. 以下指令可以用来清理Zypper缓存。
# zypper clean
All repositories have been cleaned up.

如果需要一次性地清理元数据以及软件包缓存,可以通过 -all 或 -a 选项来达到目的

<pre><code># zypper clean -a
All repositories have been cleaned up.</code></pre>
  1. 查看 Zypper 的历史信息。任何通过 Zypper 进行的软件包管理动作,包括安装、更新以及卸载都会在 /var/log/zypp/history中保留历史信息。可以通过 cat 来查看此文件,或者通过过滤器来筛选希望看到的信息。
 cat /var/log/zypp/history
2015-05-07 15:43:03|install|boost-license1_54_0|1.54.0-10.1.3|noarch||openSUSE-13.2-0|0523b909d2aae5239f9841316dafaf3a37b4f096|
2015-05-07 15:43:03|install|branding-openSUSE|13.2-3.6.1|noarch||openSUSE-13.2-0|6609def94b1987bf3f90a9467f4f7ab8f8d98a5c|
2015-05-07 15:43:03|install|bundle-lang-common-en|13.2-3.3.1|noarch||openSUSE-13.2-0|ca55694e6fdebee6ce37ac7cf3725e2aa6edc342|
2015-05-07 15:43:03|install|insserv-compat|0.1-12.2.2|noarch||openSUSE-13.2-0|6160de7fbf961a279591a83a1550093a581214d9|
2015-05-07 15:43:03|install|libX11-data|1.6.2-5.1.2|noarch||openSUSE-13.2-0|f1cb58364ba9016c1f93b1a383ba12463c56885a|
2015-05-07 15:43:03|install|libnl-config|3.2.25-2.1.2|noarch||openSUSE-13.2-0|aab2ded312a781e93b739b418e3d32fe4e187020|
2015-05-07 15:43:04|install|wireless-regdb|2014.06.13-1.2|noarch||openSUSE-13.2-0|be8cb16f3e92af12b5ceb977e37e13f03c007bd1|
2015-05-07 15:43:04|install|yast2-trans-en_US|3.1.0-2.1|noarch||openSUSE-13.2-0|1865754e5e0ec3c149ac850b340bcca55a3c404d|
2015-05-07 15:43:04|install|yast2-trans-stats|2.19.0-16.1.3|noarch||openSUSE-13.2-0|b107d2b3e702835885b57b04d12d25539f262d1a|
2015-05-07 15:43:04|install|cracklib-dict-full|2.8.12-64.1.2|x86_64||openSUSE-13.2-0|08bd45dbba7ad44e3a4837f730be76f55ad5dcfa|
......

使用 Zypper 进行SUSE系统升级

  1. 可以使用 Zypper 命令的 'dist-upgrade' 选项来将当前的 SUSE Linux 升级至最新版本。
# zypper dist-upgrade
You are about to do a distribution upgrade with all enabled repositories. Make sure these repositories are compatible before you continue. See 'man zypper' for more information about this command.
Building repository 'openSUSE-13.2-0' cache .....................................................................[done]
Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ..........................................................[done]
Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]

正文至此结束。希望本文可以帮助读者尤其是新手们管理SUSE Linux系统和服务器。如果您觉得某些比较重要的命令被作者漏掉了,请在评论部分写下您的返回,作者将根据评论对文章进行更新。保持联络,保持评论,多谢支持。


via: http://www.tecmint.com/zypper-commands-to-manage-suse-linux-package-management/

作者:Avishek Kumar 译者:张博约 校对:wxy

本文由 LCTT 原创翻译,Linux中国 荣誉推出

Zypper是SUSE Linux中用于安装,升级,卸载,管理仓库、进行各种包查询的命令行接口。本篇将会讨论zypper的几个不同命令的例子。

语法:

# zypper [--global-opts] <command> [--command-opts] [command-arguments]

中括号中的部分可以不需要。执行zypper最简单的方法是输入 zypper 及 。

例子1:列出可用的全局选项和命令

打开终端,输入zypper并按回车,它会显示所有可用的全局选项和命令。

linux-xa3t:~ # zypper

例子2:获得zypper的某个命令的帮助

语法: zypper help [command]

linux-xa3t:~ # zypper help remove
remove (rm) [options] <capability> ...

Remove packages with specified capabilities.
A capability is NAME[.ARCH][OP<VERSION>], where OP is one of <, <=, =, >=, >.

Command options:
-r, --repo <alias|#|URI> Load only the specified repository.
-t, --type <type> Type of package (package, patch, pattern, product).

 Default: package.
-n, --name Select packages by plain name, not by capability.
-C, --capability Select packages by capability.
--debug-solver Create solver test case for debugging.
-R, --no-force-resolution Do not force the solver to find solution,let it ask.
--force-resolution Force the solver to find a solution (even an aggressive one).
-u, --clean-deps Automatically remove unneeded dependencies.
-U, --no-clean-deps No automatic removal of unneeded dependencies.
-D, --dry-run Test the removal, do not actually remove.

例子3:打开zypper shell/会话

linux-xa3t:~ # zypper sh
zypper>

linux-xa3t:~ # zypper shell
zypper>

例子4:列出已定义的仓库

linux-xa3t:~ # zypper repos

linux-xa3t:~ # zypper lr

4.1) 以表格的形式列出仓库的URI

4.2) 以优先级列出仓库

linux-xa3t:~ # zypper lr -p

例子5:刷新仓库

linux-xa3t:~ # zypper ref
Repository 'openSUSE-13.1-Non-Oss' is up to date.
Repository 'openSUSE-13.1-Oss' is up to date.
Repository 'openSUSE-13.1-Update' is up to date.
Repository 'openSUSE-13.1-Update-Non-Oss' is up to date.
All repositories have been refreshed.

例子6:修改zypper仓库

zypper仓库可以通过别名、数字或者URI或者通过‘–all、 –remote、 –local、 –medium-type’这些选项修改。

linux-xa3t:~ # zypper mr -d 6 #禁用6号仓库 linux-xa3t:~ # zypper mr -rk -p 70 upd #启用自动书信并为‘upd’仓库设置rpm文件‘缓存’,且设置它的优先级为70 linux-xa3t:~ # zypper mr -Ka #为所有的仓库禁用rpm文件缓存 linux-xa3t:~ # zypper mr -kt #为远程仓库设置rpm文件缓存

例子7:添加仓库

语法: zypper addrepo 或者 zypper ar <仓库的URL或者别名>

linux-xa3t:~ # zypper ar http://download.opensuse.org/update/13.1/ update
Adding repository 'update' .............................................[done]
Repository 'update' successfully added
Enabled: Yes
Autorefresh: No
GPG check: Yes
URI: http://download.opensuse.org/update/13.1/

例子8:移除仓库

语法: zypper removerepo <仓库名> <别名>

或者

zypper rr <仓库名> <别名>

linux-xa3t:~ # zypper rr openSUSE-13.1-1.10 openSUSE-13.1-1.10
Removing repository 'openSUSE-13.1-1.10' ............................[done]
Repository 'openSUSE-13.1-1.10' has been removed.

例子9:安装软件包

语法: zypper install <包名> 或者 zypper in <包名>

linux-xa3t:~ # zypper install vlc

例子10:卸载软件包

语法: zypper remove <包名> 或者 zypper rm <包名>

linux-xa3t:~ # zypper remove sqlite

例子11:导出和导入仓库

导出仓库的语法 : zypper repos –export 或者 zypper lr -e

linux-xa3t:~ # zypper lr --export repo-backup/back.repo
Repositories have been successfully exported to repo-backup/back.repo.

导入仓库的语法 :

linux-xa3t:~ # zypper ar repo-backup/back.repo

例子12:更新一个软件包

语法: zypper update <包名> 或者 zypper up <包名>

linux-xa3t:~ # zypper update bash

例子13:安装源码包

语法: zypper source-install <源码包> 或 zypper si <源码包>

linux-xa3t:~ # zypper source-install zypper

例子14:只安装依赖包

例子13中的命令会安装和构建特定包的依赖。如果你想要安装源码包就用-D选项

# zypper source-install -D package_name

只安装依赖就使用-d

# zypper source-install -d package_name

via: http://www.linuxtechi.com/suse-linux-zypper-command-examples/

作者:Pradeep Kumar 译者:geekpi 校对:wxy

本文由 LCTT 原创翻译,Linux中国 荣誉推出