感谢支持
我们一直在努力

用于 SUSE Linux 包管理的 Zypper 命令大全

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 服务器的详细信息。

  • 如何安装企业版 SUSE Linux 12

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’)。

    1. # zypper
    2. Usage:
    3. zypper [--global-options]
  2. 获取一个具体的子命令的帮助信息,比如 ‘in’ (install),可以执行下面的命令

    1. # zypper help in

    或者

    1. # zypper help install
    2. install (in)[options]{capability | rpm_file_uri}
    3. Install packages with specified capabilities or RPM files with specified
    4. location. A capability is NAME[.ARCH][OP],where OP is one
    5. of <,<=,=,>=,>.
    6. Command options:
    7. --from<alias|#|URI>Select packages from the specified repository.
    8. -r,--repo <alias|#|URI>Load only the specified repository.
    9. -t,--type Type of package(package, patch, pattern, product, srcpackage).
    10. Default:package.
    11. -n,--name Select packages by plain name,notby capability.
    12. -C,--capability Select packages by capability.
    13. -f,--force Install even if the item is already installed (reinstall),
    14. downgraded or changes vendor or architecture.
    15. --oldpackage Allow to replace a newer item with an older one.
    16. Handyif you are doing a rollback.Unlike--force
    17. it will not enforce a reinstall.
    18. --replacefiles Install the packages even if they replace files from other,
    19. already installed, packages.Defaultis to treat file conflicts
    20. as an error.--download-as-needed disables the fileconflict check.
    21. ......
  3. 安装之前搜索一个安转包(以 gnome-desktop 为例 )

    1. # zypper se gnome-desktop
    2. Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
    3. Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
    4. Retrieving repository 'openSUSE-13.2-Non-Oss' metadata .........................................................[done]
    5. Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]
    6. Retrieving repository 'openSUSE-13.2-Oss' metadata ..............................................................[done]
    7. Building repository 'openSUSE-13.2-Oss' cache ...................................................................[done]
    8. Retrieving repository 'openSUSE-13.2-Update' metadata ...........................................................[done]
    9. Building repository 'openSUSE-13.2-Update' cache ................................................................[done]
    10. Retrieving repository 'openSUSE-13.2-Update-Non-Oss' metadata ...................................................[done]
    11. Building repository 'openSUSE-13.2-Update-Non-Oss' cache ........................................................[done]
    12. Loading repository data...
    13. Reading installed packages...
    14. S |Name|Summary|Type
    15. --+---------------------------------------+-----------------------------------------------------------+-----------
    16. | gnome-desktop2-lang |Languagesforpackage gnome-desktop2 |package
    17. | gnome-desktop2 |The GNOME Desktop API Library|package
    18. | libgnome-desktop-2-17|The GNOME Desktop API Library|package
    19. | libgnome-desktop-3-10|The GNOME Desktop API Library|package
    20. | libgnome-desktop-3-devel |The GNOME Desktop API Library--DevelopmentFiles|package
    21. | libgnome-desktop-3_0-common |The GNOME Desktop API Library--Common data files |package
    22. | gnome-desktop-debugsource |Debug sources forpackage gnome-desktop |package
    23. | gnome-desktop-sharp2-debugsource |Debug sources forpackage gnome-desktop-sharp2 |package
    24. | gnome-desktop2-debugsource |Debug sources forpackage gnome-desktop2 |package
    25. | libgnome-desktop-2-17-debuginfo |Debug information forpackage libgnome-desktop-2-17|package
    26. | libgnome-desktop-3-10-debuginfo |Debug information forpackage libgnome-desktop-3-10|package
    27. | libgnome-desktop-3_0-common-debuginfo |Debug information forpackage libgnome-desktop-3_0-common |package
    28. | libgnome-desktop-2-17-debuginfo-32bit|Debug information forpackage libgnome-desktop-2-17|package
    29. | libgnome-desktop-3-10-debuginfo-32bit|Debug information forpackage libgnome-desktop-3-10|package
    30. | gnome-desktop-sharp2 |Mono bindings for libgnome-desktop |package
    31. | libgnome-desktop-2-devel |The GNOME Desktop API Library--DevelopmentFiles| packag
    32. | gnome-desktop-lang |Languagesforpackage gnome-desktop |package
    33. | libgnome-desktop-2-17-32bit|The GNOME Desktop API Library|package
    34. | libgnome-desktop-3-10-32bit|The GNOME Desktop API Library|package
    35. | gnome-desktop |The GNOME Desktop API Library| srcpackage
  4. 获取一个模式包的信息(以 lamp_server 为例)。

    1. # zypper info -t pattern lamp_server
    2. Loading repository data...
    3. Reading installed packages...
    4. Informationfor pattern lamp_server:
    5. ------------------------------------
    6. Repository: openSUSE-13.2-Update
    7. Name: lamp_server
    8. Version:20141007-5.1
    9. Arch: x86_64
    10. Vendor: openSUSE
    11. Installed:No
    12. Visible to User:Yes
    13. Summary:Weband LAMP Server
    14. Description:
    15. 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,
    16. and scripting languages such as PHP,Python,Ruby on Rails,orPerl.
    17. Contents:
    18. S |Name|Type|Dependency
    19. --+-------------------------------+---------+-----------
    20. | apache2-mod_php5 |package|
    21. | php5-iconv |package|
    22. i | patterns-openSUSE-base|package|
    23. i | apache2-prefork |package|
    24. | php5-dom |package|
    25. | php5-mysql |package|
    26. i | apache2 |package|
    27. | apache2-example-pages |package|
    28. | mariadb |package|
    29. | apache2-mod_perl |package|
    30. | php5-ctype |package|
    31. | apache2-doc |package|
    32. | yast2-http-server |package|
    33. | patterns-openSUSE-lamp_server |package|
  5. 开启一个Zypper Shell 的会话。

    1. # zypper shell

    或者

    1. # zypper sh
    1. zypper> help
    2. Usage:
    3. zypper [--global-options]

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

Zypper 软件库管理

列举已定义的软件库

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

    1. # zypper repos

    或者

    1. # zypper lr
    2. |Alias|Name|Enabled|Refresh
    3. --+---------------------------+------------------------------------+---------+--------
    4. 1| openSUSE-13.2-0| openSUSE-13.2-0|Yes|No
    5. 2| repo-debug | openSUSE-13.2-Debug|Yes|Yes
    6. 3| repo-debug-update | openSUSE-13.2-Update-Debug|No|Yes
    7. 4| repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss|No|Yes
    8. 5| repo-non-oss | openSUSE-13.2-Non-Oss|Yes|Yes
    9. 6| repo-oss | openSUSE-13.2-Oss|Yes|Yes
    10. 7| repo-source | openSUSE-13.2-Source|No|Yes
    11. 8| repo-update | openSUSE-13.2-Update|Yes|Yes
    12. 9| repo-update-non-oss | openSUSE-13.2-Update-Non-Oss|Yes|Yes
  2. 在表格里面显示 zypper URI

    1. # zypper lr -u
    2. |Alias|Name|Enabled|Refresh| URI
    3. --+---------------------------+------------------------------------+---------+---------+----------------------------------------------------------------
    4. 1| openSUSE-13.2-0| openSUSE-13.2-0|Yes|No| cd:///?devices=/dev/disk/by-id/ata-VBOX_CD-ROM_VB2-01700376
    5. 2| repo-debug | openSUSE-13.2-Debug|Yes|Yes| http://download.opensuse.org/debug/distribution/13.2/repo/oss/
    6. 3| repo-debug-update | openSUSE-13.2-Update-Debug|No|Yes| http://download.opensuse.org/debug/update/13.2/
    7. 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/
    8. 5| repo-non-oss | openSUSE-13.2-Non-Oss|Yes|Yes| http://download.opensuse.org/distribution/13.2/repo/non-oss/
    9. 6| repo-oss | openSUSE-13.2-Oss|Yes|Yes| http://download.opensuse.org/distribution/13.2/repo/oss/
    10. 7| repo-source | openSUSE-13.2-Source|No|Yes| http://download.opensuse.org/source/distribution/13.2/repo/oss/
    11. 8| repo-update | openSUSE-13.2-Update|Yes|Yes| http://download.opensuse.org/update/13.2/
    12. 9| repo-update-non-oss | openSUSE-13.2-Update-Non-Oss|Yes|Yes| http://download.opensuse.org/update/13.2-non-oss/
  3. 根据优先级列举软件库。

    1. # zypper lr -P
    2. |Alias|Name|Enabled|Refresh|Priority
    3. --+---------------------------+------------------------------------+---------+---------+---------
    4. 1| openSUSE-13.2-0| openSUSE-13.2-0|Yes|No|99
    5. 2| repo-debug | openSUSE-13.2-Debug|Yes|Yes|99
    6. 3| repo-debug-update | openSUSE-13.2-Update-Debug|No|Yes|99
    7. 4| repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss|No|Yes|99
    8. 5| repo-non-oss | openSUSE-13.2-Non-Oss|Yes|Yes|85
    9. 6| repo-oss | openSUSE-13.2-Oss|Yes|Yes|99
    10. 7| repo-source | openSUSE-13.2-Source|No|Yes|99
    11. 8| repo-update | openSUSE-13.2-Update|Yes|Yes|99
    12. 9| repo-update-non-oss | openSUSE-13.2-Update-Non-Oss|Yes|Yes|99

刷新软件库

  1. 使用 ‘zypper refresh’ or ‘zypper ref’ 来刷新 zypper 软件库。

    1. # zypper refresh

    或者

    1. # zypper ref
    2. Repository'openSUSE-13.2-0'is up to date.
    3. Repository'openSUSE-13.2-Debug'is up to date.
    4. Repository'openSUSE-13.2-Non-Oss'is up to date.
    5. Repository'openSUSE-13.2-Oss'is up to date.
    6. Repository'openSUSE-13.2-Update'is up to date.
    7. Repository'openSUSE-13.2-Update-Non-Oss'is up to date.
    8. All repositories have been refreshed.
  2. 刷新一个指定的软件库(以 ‘repo-non-oss’ 为例 )。

    1. # zypper refresh repo-non-oss
    2. Repository'openSUSE-13.2-Non-Oss'is up to date.
    3. Specified repositories have been refreshed.
  3. 强制更新一个软件库(以 ‘repo-non-oss’ 为例 )。

    1. # zypper ref -f repo-non-oss
    2. Forcing raw metadata refresh
    3. Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ............................................................[done]
    4. Forcing building of repository cache
    5. Building repository 'openSUSE-13.2-Non-Oss' cache ............................................................[done]
    6. Specified repositories have been refreshed.

修改软件库

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

  1. 在关闭一个软件库之前,我们需要知道在 zypper 中,每一个软件库有一个唯一的标示数字与之关联,该数字用于打开或者关闭与之相联系的软件库。假设我们需要关闭 ‘repo-oss’ 软件库,那么我们可以通过以下的法来获得该软件库的标志数字。

    1. # zypper lr
    2. |Alias|Name|Enabled|Refresh
    3. --+---------------------------+------------------------------------+---------+--------
    4. 1| openSUSE-13.2-0| openSUSE-13.2-0|Yes|No
    5. 2| repo-debug | openSUSE-13.2-Debug|Yes|Yes
    6. 3| repo-debug-update | openSUSE-13.2-Update-Debug|No|Yes
    7. 4| repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss|No|Yes
    8. 5| repo-non-oss | openSUSE-13.2-Non-Oss|Yes|Yes
    9. 6| repo-oss | openSUSE-13.2-Oss|No|Yes
    10. 7| repo-source | openSUSE-13.2-Source|No|Yes
    11. 8| repo-update | openSUSE-13.2-Update|Yes|Yes
    12. 9| repo-update-non-oss | openSUSE-13.2-Update-Non-Oss|Yes|Yes

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

    1. # zypper mr -d 6
    2. Repository'repo-oss' has been successfully disabled.
  2. 如果需要再次开启软件库 ‘repo-oss‘, 接上例,与之相关联的标示数字为 6。

    1. # zypper mr -e 6
    2. Repository'repo-oss' has been successfully enabled.
  3. 针对某一个软件库(以 ‘repo-non-oss’ 为例 )开启自动刷新( auto-refresh )和 rpm 缓存,并设置该软件库的优先级,比如85。

    1. # zypper mr -rk -p 85 repo-non-oss
    2. Repository'repo-non-oss' priority has been left unchanged (85)
    3. Nothing to change for repository 'repo-non-oss'.
  4. 对所有的软件库关闭 rpm 文件缓存。

    1. # zypper mr -Ka
    2. RPM files caching has been disabled for repository 'openSUSE-13.2-0'.
    3. RPM files caching has been disabled for repository 'repo-debug'.
    4. RPM files caching has been disabled for repository 'repo-debug-update'.
    5. RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
    6. RPM files caching has been disabled for repository 'repo-non-oss'.
    7. RPM files caching has been disabled for repository 'repo-oss'.
    8. RPM files caching has been disabled for repository 'repo-source'.
    9. RPM files caching has been disabled for repository 'repo-update'.
    10. RPM files caching has been disabled for repository 'repo-update-non-oss'.
  5. 对所有的软件库开启 rpm 文件缓存。

    1. # zypper mr -ka
    2. RPM files caching has been enabled for repository 'openSUSE-13.2-0'.
    3. RPM files caching has been enabled for repository 'repo-debug'.
    4. RPM files caching has been enabled for repository 'repo-debug-update'.
    5. RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
    6. RPM files caching has been enabled for repository 'repo-non-oss'.
    7. RPM files caching has been enabled for repository 'repo-oss'.
    8. RPM files caching has been enabled for repository 'repo-source'.
    9. RPM files caching has been enabled for repository 'repo-update'.
    10. RPM files caching has been enabled for repository 'repo-update-non-oss'.
  6. 关闭远程库的 rpm 文件缓存

    1. # zypper mr -Kt
    2. RPM files caching has been disabled for repository 'repo-debug'.
    3. RPM files caching has been disabled for repository 'repo-debug-update'.
    4. RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
    5. RPM files caching has been disabled for repository 'repo-non-oss'.
    6. RPM files caching has been disabled for repository 'repo-oss'.
    7. RPM files caching has been disabled for repository 'repo-source'.
    8. RPM files caching has been disabled for repository 'repo-update'.
    9. RPM files caching has been disabled for repository 'repo-update-non-oss'.
  7. 开启远程软件库的 rpm 文件缓存。

    1. # zypper mr -kt
    2. RPM files caching has been enabled for repository 'repo-debug'.
    3. RPM files caching has been enabled for repository 'repo-debug-update'.
    4. RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
    5. RPM files caching has been enabled for repository 'repo-non-oss'.
    6. RPM files caching has been enabled for repository 'repo-oss'.
    7. RPM files caching has been enabled for repository 'repo-source'.
    8. RPM files caching has been enabled for repository 'repo-update'.
    9. 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/” 为例 )。

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

    1. # zypper nr 10 upd8
    2. Repository'update' renamed to 'upd8'.

删除软件库

  1. 删除一个软件库。要从系统删除一个软件库可以使 ‘zypper removerepo’ 或者 ‘zypper rr’。例如以下的命令可以删除软件库 ‘upd8’

    1. # zypper rr upd8
    2. # Removing repository 'upd8' .........................................................................................[done]
    3. Repository'upd8' has been removed.

 

 

使用 zypper 进行软件包管理

 

用 zypper 安装一个软件包

  1. 在 zypper 中,我们可以通过软件包的功能名称来安装一个软件包。以 Firefox 为例,以下的命令可以用来安装该软件包。

    1. # zypper in MozillaFirefox
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 128 NEW packages are going to be installed:
    6. 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
    7. gstreamer-plugins-base gtk2-branding-openSUSE gtk2-data gtk2-immodule-amharic gtk2-immodule-inuktitut gtk2-immodule-thai gtk2-immodule-vietnamese gtk2-metatheme-adwaita
    8. 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
    9. libatspi0 libcairo2 libcairo-gobject2 libcanberra0 libcanberra-gtk0 libcanberra-gtk2-module libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra-gtk-module-common libcdda_interface0
    10. 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
    11. 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
    12. 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
    13. libsqlite3-0 libstartup-notification-1-0 libtheoradec1 libtheoraenc1 libtiff5 libvisual libvorbis0 libvorbisenc2 libvorbisfile3 libwayland-client0 libwayland-cursor0 libwayland-server0
    14. 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
    15. libXfixes3 libXft2 libXi6 libXinerama1 libxkbcommon-0_4_3 libXrandr2 libXrender1 libxshmfence1 libXtst6 libXv1 libXxf86vm1 MesaMesa-libEGL1 Mesa-libGL1 Mesa-libglapi0
    16. metatheme-adwaita-common MozillaFirefoxMozillaFirefox-branding-openSUSE mozilla-nss mozilla-nss-certs PackageKit-gstreamer-plugin pango-tools sound-theme-freedesktop
    17. The following 10 recommended packages were automatically selected:
    18. gstreamer-fluendo-mp3 gtk2-branding-openSUSE gtk2-data gtk2-immodule-amharic gtk2-immodule-inuktitut gtk2-immodule-thai gtk2-immodule-vietnamese libcanberra0 libpulse0
    19. PackageKit-gstreamer-plugin
    20. 128new packages to install.
    21. Overall download size:77.2MiB.Already cached:0 B After the operation, additional 200.0MiB will be used.
    22. Continue?[y/n/? shows all options](y): y
    23. Retrievingpackage cantarell-fonts-0.0.16-1.1.noarch (1/128),74.1KiB(115.6KiB unpacked)
    24. Retrieving: cantarell-fonts-0.0.16-1.1.noarch.rpm .........................................................................................................................[done(63.4KiB/s)]
    25. Retrievingpackage hicolor-icon-theme-0.13-2.1.2.noarch(2/128),40.1KiB(50.5KiB unpacked)
    26. Retrieving: hicolor-icon-theme-0.13-2.1.2.noarch.rpm ...................................................................................................................................[done]
    27. Retrievingpackage sound-theme-freedesktop-0.8-7.1.2.noarch(3/128),372.6KiB(460.3KiB unpacked)
  2. 安装指定版本号的软件包,(以 gcc 5.1 为例)。

    1. # zypper in 'gcc<5.1'
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 13 NEW packages are going to be installed:
    6. cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49
    7. 13new packages to install.
    8. Overall download size:14.5MiB.Already cached:0 B After the operation, additional 49.4MiB will be used.
    9. Continue?[y/n/? shows all options](y): y
  3. 为特定的CPU架构安装软件包(以兼容 i586 的 gcc 为例)。

    1. # zypper in gcc.i586
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 13 NEW packages are going to be installed:
    6. cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49
    7. 13new packages to install.
    8. Overall download size:14.5MiB.Already cached:0 B After the operation, additional 49.4MiB will be used.
    9. Continue?[y/n/? shows all options](y): y
    10. Retrievingpackage libasan0-4.8.3+r212056-2.2.4.x86_64 (1/13),74.2KiB(166.9KiB unpacked)
    11. Retrieving: libasan0-4.8.3+r212056-2.2.4.x86_64.rpm .......................................................................................................................[done(79.2KiB/s)]
    12. Retrievingpackage libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64 (2/13),14.3KiB(26.1KiB unpacked)
    13. Retrieving: libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm ...............................................................................................................[done(55.3KiB/s)]
  4. 为特定的CPU架构安装指定版本号的软件包(以兼容 i586 且版本低于5.1的 gcc 为例)

    1. # zypper in 'gcc.i586<5.1'
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 13 NEW packages are going to be installed:
    6. cpp cpp48 gcc gcc48 libasan0 libatomic1-gcc49 libcloog-isl4 libgomp1-gcc49 libisl10 libitm1-gcc49 libmpc3 libmpfr4 libtsan0-gcc49
    7. 13new packages to install.
    8. Overall download size:14.4MiB.Already cached:129.5KiBAfter the operation, additional 49.4MiB will be used.
    9. Continue?[y/n/? shows all options](y): y
    10. In cache libasan0-4.8.3+r212056-2.2.4.x86_64.rpm (1/13),74.2KiB(166.9KiB unpacked)
    11. In cache libatomic1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm (2/13),14.3KiB(26.1KiB unpacked)
    12. In cache libgomp1-gcc49-4.9.0+r211729-2.1.7.x86_64.rpm (3/13),41.1KiB(90.7KiB unpacked)
  5. 从指定的软件库里面安装一个软件包,例如从 amarok 中安装 libxine。

    1. # zypper in amarok upd:libxine1
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 202 NEW packages are going to be installed:
    6. 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
    7. hicolor-icon-theme-branding-openSUSE htdig hunspell hunspell-tools icoutils ispell ispell-american kde4-filesystem kdebase4-runtime kdebase4-runtime-branding-openSUSE kdelibs4
    8. kdelibs4-branding-openSUSE kdelibs4-core kdialog libakonadi4 l
    9. .....
  6. 通过指定软件包的名字安装软件包。

    1. # zypper in -n git
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 35 NEW packages are going to be installed:
    6. 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
    7. 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
    8. tk xhost
    9. The following 13 recommended packages were automatically selected:
    10. 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
    11. The following packageis suggested, but will not be installed:
    12. git-daemon
    13. 35new packages to install.
    14. Overall download size:15.6MiB.Already cached:0 B After the operation, additional 56.7MiB will be used.
    15. Continue?[y/n/? shows all options](y): y
  7. 通过通配符来安装软件包,例如,安装所有 php5 的软件包。

    1. # zypper in php5*
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. Problem: php5-5.6.1-18.1.x86_64 requires smtp_daemon, but this requirement cannot be provided
    6. uninstallable providers: exim-4.83-3.1.8.x86_64[openSUSE-13.2-0]
    7. postfix-2.11.0-5.2.2.x86_64[openSUSE-13.2-0]
    8. sendmail-8.14.9-2.2.2.x86_64[openSUSE-13.2-0]
    9. exim-4.83-3.1.8.i586[repo-oss]
    10. msmtp-mta-1.4.32-2.1.3.i586[repo-oss]
    11. postfix-2.11.0-5.2.2.i586[repo-oss]
    12. sendmail-8.14.9-2.2.2.i586[repo-oss]
    13. exim-4.83-3.1.8.x86_64[repo-oss]
    14. msmtp-mta-1.4.32-2.1.3.x86_64[repo-oss]
    15. postfix-2.11.0-5.2.2.x86_64[repo-oss]
    16. sendmail-8.14.9-2.2.2.x86_64[repo-oss]
    17. postfix-2.11.3-5.5.1.i586[repo-update]
    18. postfix-2.11.3-5.5.1.x86_64[repo-update]
    19. Solution1:Following actions will be done:
    20. donot install php5-5.6.1-18.1.x86_64
    21. donot install php5-pear-Auth_SASL-1.0.6-7.1.3.noarch
    22. donot install php5-pear-Horde_Http-2.0.1-6.1.3.noarch
    23. donot install php5-pear-Horde_Image-2.0.1-6.1.3.noarch
    24. donot install php5-pear-Horde_Kolab_Format-2.0.1-6.1.3.noarch
    25. donot install php5-pear-Horde_Ldap-2.0.1-6.1.3.noarch
    26. donot install php5-pear-Horde_Memcache-2.0.1-7.1.3.noarch
    27. donot install php5-pear-Horde_Mime-2.0.2-6.1.3.noarch
    28. donot install php5-pear-Horde_Oauth-2.0.0-6.1.3.noarch
    29. donot install php5-pear-Horde_Pdf-2.0.1-6.1.3.noarch
    30. ....
  8. 使用模式名称(模式名称是一类软件包的名字)来批量安装软件包。

    1. # zypper in -t pattern lamp_server
    2. ading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 29 NEW packages are going to be installed:
    6. 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
    7. 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
    8. 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
    9. The following NEW pattern is going to be installed:
    10. lamp_server
    11. The following 10 recommended packages were automatically selected:
    12. 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
    13. 29new packages to install.
    14. Overall download size:7.2MiB.Already cached:1.2MiBAfter the operation, additional 34.7MiB will be used.
    15. Continue?[y/n/? shows all options](y):
  9. 使用一行命令安装一个软件包同时卸载另一个软件包,例如在安装 nano 的同时卸载 vi

    1. # zypper in nano -vi
    2. Loading repository data...
    3. Reading installed packages...
    4. '-vi'not found inpackage names.Trying capabilities.
    5. Resolvingpackage dependencies...
    6. The following 2 NEW packages are going to be installed:
    7. nano nano-lang
    8. The following packageis going to be REMOVED:
    9. vim
    10. The following recommended package was automatically selected:
    11. nano-lang
    12. 2new packages to install,1 to remove.
    13. Overall download size:550.0KiB.Already cached:0 B After the operation,463.3KiB will be freed.
    14. Continue?[y/n/? shows all options](y):
    15. ...
  10. 使用 zypper 安装 rpm 软件包。

    1. # zypper in teamviewer*.rpm
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 24 NEW packages are going to be installed:
    6. 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
    7. libuuid1-32bit libX11-6-32bit libXau6-32bit libxcb1-32bit libXdamage1-32bit libXext6-32bit libXfixes3-32bit libXinerama1-32bit libXrandr2-32bit libXrender1-32bit libXtst6-32bit
    8. libz1-32bit teamviewer
    9. The following recommended package was automatically selected:
    10. alsa-oss-32bit
    11. 24new packages to install.
    12. Overall download size:41.2MiB.Already cached:0 B After the operation, additional 119.7MiB will be used.
    13. Continue?[y/n/? shows all options](y):
    14. ..

 

使用 zypper 卸载软件包

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

    1. # zypper remove apache2

    或者

    1. # zypper rm apache2
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following 2 packages are going to be REMOVED:
    6. apache2 apache2-prefork
    7. 2 packages to remove.
    8. After the operation,4.2MiB will be freed.
    9. Continue?[y/n/? shows all options](y): y
    10. (1/2)Removing apache2-2.4.10-19.1........................................................................[done]
    11. (2/2)Removing apache2-prefork-2.4.10-19.1................................................................[done]

 

使用Zypper 进行软件包更新

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

    1. # zypper up

    或者

    1. # zypper update
    2. Loading repository data...
    3. Reading installed packages...
    4. Nothing to do.
  2. 更新指定的软件包,例如更新 apache2 以及 openssh。

    1. zypper up apache2 openssh
    2. Loading repository data...
    3. Reading installed packages...
    4. No update candidate for'apache2-2.4.10-19.1.x86_64'.The highest available version is already installed.
    5. No update candidate for'openssh-6.6p1-5.1.3.x86_64'.The highest available version is already installed.
    6. Resolvingpackage dependencies...
    7. Nothing to do.
  3. 安装一个软件库,例如 mariadb,如果该库存在则更新之。

    1. # zypper in mariadb
    2. Loading repository data...
    3. Reading installed packages...
    4. 'mariadb'is already installed.
    5. No update candidate for'mariadb-10.0.13-2.6.1.x86_64'.The highest available version is already installed.
    6. Resolvingpackage dependencies...
    7. Nothing to do.

 

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

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

  1. 安装某一个软件包的源文件及其依赖关系,例如 mariadb。

    1. # zypper si mariadb
    2. Reading installed packages...
    3. Loading repository data...
    4. Resolvingpackage dependencies...
    5. The following 36 NEW packages are going to be installed:
    6. 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
    7. 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
    8. The following source packageis going to be installed:
    9. mariadb
    10. 36new packages to install,1 source package.
    11. Overall download size:71.5MiB.Already cached:129.5KiBAfter the operation, additional 183.9MiB will be used.
    12. Continue?[y/n/? shows all options](y): y
  2. 仅为某一个软件包安装源文件,例如 mariadb

    1. # zypper in -D mariadb
    2. Loading repository data...
    3. Reading installed packages...
    4. 'mariadb'is already installed.
    5. No update candidate for'mariadb-10.0.13-2.6.1.x86_64'.The highest available version is already installed.
    6. Resolvingpackage dependencies...
    7. Nothing to do.
  3. 仅为某一个软件包安装依赖关系,例如 mariadb

    1. # zypper si -d mariadb
    2. Reading installed packages...
    3. Loading repository data...
    4. Resolvingpackage dependencies...
    5. The following 36 NEW packages are going to be installed:
    6. 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
    7. 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
    8. The following packageis recommended, but will not be installed due to conflicts or dependency issues:
    9. readline-doc
    10. 36new packages to install.
    11. Overall download size:33.7MiB.Already cached:129.5KiBAfter the operation, additional 144.3MiB will be used.
    12. Continue?[y/n/? shows all options](y): y

 

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

  1. 安装一个软件包,并且在安装过程中跳过与用户的交互, 例如 mariadb。

    1. # zypper --non-interactive in mariadb
    2. Loading repository data...
    3. Reading installed packages...
    4. 'mariadb'is already installed.
    5. No update candidate for'mariadb-10.0.13-2.6.1.x86_64'.The highest available version is already installed.
    6. Resolvingpackage dependencies...
    7. Nothing to do.
  2. 卸载一个软件包,并且在卸载过程中跳过与用户的交互,例如 mariadb

    1. # zypper --non-interactive rm mariadb
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. The following packageis going to be REMOVED:
    6. mariadb
    7. 1package to remove.
    8. After the operation,71.8MiB will be freed.
    9. Continue?[y/n/? shows all options](y): y
    10. (1/1)Removing mariadb-10.0.13-2.6.1.............................................................................[done]
  3. 以 XML 格式显示 zypper 的输出。

    1. # zypper --xmlout
    2. Usage:
    3. zypper [--global-options][--command-options][arguments]
    4. GlobalOptions
    5. ....
  4. 在安装过程中禁止详细信息输出到屏幕。

    1. # zypper --quiet in mariadb
    2. The following NEW packageis going to be installed:
    3. mariadb
    4. 1newpackage to install.
    5. Overall download size:0 B.Already cached:7.8MiBAfter the operation, additional 71.8MiB will be used.
    6. Continue?[y/n/? shows all options](y):
    7. ...
  5. 在卸载过程中禁止详细信息输出到屏幕

    1. # zypper --quiet rm mariadb
  6. 自动地同意版权或者协议。

    1. # zypper patch --auto-agree-with-licenses
    2. Loading repository data...
    3. Reading installed packages...
    4. Resolvingpackage dependencies...
    5. Nothing to do.

 

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

  1. 以下指令可以用来清理Zypper缓存。

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

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

  1. <pre><code># zypper clean -a
  2. All repositories have been cleaned up.</code></pre>
  1. 查看 Zypper 的历史信息。任何通过 Zypper 进行的软件包管理动作,包括安装、更新以及卸载都会在 /var/log/zypp/history中保留历史信息。可以通过 cat 来查看此文件,或者通过过滤器来筛选希望看到的信息。

    1. cat /var/log/zypp/history
    2. 2015-05-0715:43:03|install|boost-license1_54_0|1.54.0-10.1.3|noarch||openSUSE-13.2-0|0523b909d2aae5239f9841316dafaf3a37b4f096|
    3. 2015-05-0715:43:03|install|branding-openSUSE|13.2-3.6.1|noarch||openSUSE-13.2-0|6609def94b1987bf3f90a9467f4f7ab8f8d98a5c|
    4. 2015-05-0715:43:03|install|bundle-lang-common-en|13.2-3.3.1|noarch||openSUSE-13.2-0|ca55694e6fdebee6ce37ac7cf3725e2aa6edc342|
    5. 2015-05-0715:43:03|install|insserv-compat|0.1-12.2.2|noarch||openSUSE-13.2-0|6160de7fbf961a279591a83a1550093a581214d9|
    6. 2015-05-0715:43:03|install|libX11-data|1.6.2-5.1.2|noarch||openSUSE-13.2-0|f1cb58364ba9016c1f93b1a383ba12463c56885a|
    7. 2015-05-0715:43:03|install|libnl-config|3.2.25-2.1.2|noarch||openSUSE-13.2-0|aab2ded312a781e93b739b418e3d32fe4e187020|
    8. 2015-05-0715:43:04|install|wireless-regdb|2014.06.13-1.2|noarch||openSUSE-13.2-0|be8cb16f3e92af12b5ceb977e37e13f03c007bd1|
    9. 2015-05-0715:43:04|install|yast2-trans-en_US|3.1.0-2.1|noarch||openSUSE-13.2-0|1865754e5e0ec3c149ac850b340bcca55a3c404d|
    10. 2015-05-0715:43:04|install|yast2-trans-stats|2.19.0-16.1.3|noarch||openSUSE-13.2-0|b107d2b3e702835885b57b04d12d25539f262d1a|
    11. 2015-05-0715:43:04|install|cracklib-dict-full|2.8.12-64.1.2|x86_64||openSUSE-13.2-0|08bd45dbba7ad44e3a4837f730be76f55ad5dcfa|
    12. ......

 

使用 Zypper 进行SUSE系统升级

  1. 可以使用 Zypper 命令的 ‘dist-upgrade’ 选项来将当前的 SUSE Linux 升级至最新版本。

    1. # zypper dist-upgrade
    2. 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.
    3. Building repository 'openSUSE-13.2-0' cache .....................................................................[done]
    4. Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
    5. Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
    6. Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ..........................................................[done]
    7. Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]

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

更多SUSE相关信息见SUSE 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=3


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

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

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

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-06/118698.htm

赞(0) 打赏
转载请注明出处:服务器评测 » 用于 SUSE Linux 包管理的 Zypper 命令大全
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏