zypper 通过 in 或 install 子命令来在你的系统上安装包。它的用法与 yum 软件包安装 相同。你只需要提供包名作为参数,包管理器(此处是 zypper)就会处理所有的依赖并与你指定的包一并安装。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 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]
要在 Suse Linux 中擦除或移除包,使用 zypper 附带 remove 或 rm 子命令。
1 2 3 4 5 6 7 8 9 10 11 12
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]
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.
要使用 zypper 更新包,使用 update 或 up 子命令后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 rsync 包更新可用。让我们现在来更新它吧!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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 附带的 se 或 search 子命令并提供查找字符串来查找包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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 检查已安装包的详细信息。info 或 if 子命令将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,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 命令附带 lr 或 repos 子命令列出仓库。
1 2 3 4 5 6 7 8 9 10 11 12
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,否则你会遇到如下错误。
1 2
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,你可以像如下方式添加仓库:
1 2 3 4 5 6 7 8 9 10 11
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 中使用附带 addrepo 或 ar 子命令的 zypper 命令添加仓库,后接 URI 以及你需要提供一个别名。