zoukankan      html  css  js  c++  java
  • 12 条实用的 zypper 命令范例 (转载)

    12 条实用的 zypper 命令范例

    作者: Kerneltalks 译者: LCTT cycoe

    | 2018-12-12 13:29      

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

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

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

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

    如何使用 zypper 安装包

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

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

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

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

    如何使用 zypper 移除包

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

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

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

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

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

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

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

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

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

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

    1. root@kerneltalks # zypper download telnet
    2. Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
    3. Refreshing service 'cloud_update'.
    4. Loading repository data...
    5. Reading installed packages...
    6. Retrieving package telnet-1.2-165.63.x86_64 (1/1), 51.8 KiB (113.3 KiB unpacked)
    7. (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]
    8. download: Done.
    9. # ls -lrt /var/cache/zypp/packages/SMT-http_smt-ec2_susecloud_net:SLES12-SP3-Pool/x86_64/
    10. total 52
    11. -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 子命令来显示已安装包的所有可用更新。

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

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

    在 Suse Linux 中列出和安装补丁

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

    1. root@kerneltalks # zypper lp
    2. Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
    3. Refreshing service 'cloud_update'.
    4. Loading repository data...
    5. Reading installed packages...
    6. Repository | Name | Category | Severity | Interactive | Status | Summary
    7. ----------------------------------|------------------------------------------|-------------|-----------|-------------|--------|------------------------------------------------------------------------------------
    8. 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
    9. SLE-Module-Containers12-Updates | SUSE-SLE-Module-Containers-12-2018-62 | recommended | low | --- | needed | Recommended update for sle2docker
    10. SLE-Module-Public-Cloud12-Updates | SUSE-SLE-Module-Public-Cloud-12-2018-268 | recommended | low | --- | needed | Recommended update for python-ecdsa
    11. SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-116 | security | moderate | --- | needed | Security update for rsync
    12. ---- output clipped ----
    13. SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-89 | security | moderate | --- | needed | Security update for perl-XML-LibXML
    14. SLES12-SP3-Updates | SUSE-SLE-SERVER-12-SP3-2018-90 | recommended | low | --- | needed | Recommended update for lvm2
    15. Found 37 applicable patches:
    16. 37 patches needed (18 security patches)

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

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

    如何使用 zypper 更新包

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

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

    在 Suse Linux 上使用 zypper 查找包

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

    1. root@kerneltalks # zypper se lvm
    2. Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
    3. Refreshing service 'cloud_update'.
    4. Loading repository data...
    5. Reading installed packages...
    6. S | Name | Summary | Type
    7. ---|---------------|------------------------------|-----------
    8. | libLLVM | Libraries for LLVM | package
    9. | libLLVM-32bit | Libraries for LLVM | package
    10. | llvm | Low Level Virtual Machine | package
    11. | llvm-devel | Header Files for LLVM | package
    12. | lvm2 | Logical Volume Manager Tools | srcpackage
    13. i+ | lvm2 | Logical Volume Manager Tools | package
    14. | lvm2-devel | Development files for LVM2 | package

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

    使用 zypper 检查已安装包信息

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

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

    使用 zypper 列出仓库

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

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

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

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

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

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

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

    1. 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
    2. Adding repository 'SLE-SDK12-SP3-Pool' ...........................................................................................................................[done]
    3. Repository 'SLE-SDK12-SP3-Pool' successfully added
    4. URI : http://smt-ec2.susecloud.net/repo/SUSE/Products/SLE-SDK/12-SP3/x86_64/product?credentials=SMT-http_smt-ec2_susecloud_net
    5. Enabled : Yes
    6. GPG Check : Yes
    7. Autorefresh : No
    8. Priority : 99 (default priority)
    9. Repository priorities are without effect. All enabled repositories share the same priority.

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

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

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

    清除 zypper 本地缓存

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

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

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

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

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

  • 相关阅读:
    “2O9”学习小组第五周学习总结(10、11章)
    2020—2021—1学期 20202408《网络空间安全导论》第五周学习总结
    2020—2021—1学期 20202408《网络空间安全导论》第四周学习总结
    “2O9”学习小组第二周学习总结(8、9章)
    “2O9”学习小组第二周学习总结(6、7章)
    2020—2021—1学期 20202408《网络空间安全导论》第三周学习总结
    “2O9”学习小组第二周学习总结(4、5章)
    2020—2021—1学期 20202408《网络空间安全导论》第二周学习总结
    Python字符串格式化的三种形式
    关于python函数几点注意
  • 原文地址:https://www.cnblogs.com/pipci/p/10109650.html
Copyright © 2011-2022 走看看