Linux中國

用於 『Suse『 Linux 包管理的 Zypper 命令大全

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 &apos;openSUSE-13.2-Debug&apos; metadata ............................................................[done]
Building repository &apos;openSUSE-13.2-Debug&apos; cache .................................................................[done]
Retrieving repository &apos;openSUSE-13.2-Non-Oss&apos; metadata ......................................................... [done]
Building repository &apos;openSUSE-13.2-Non-Oss&apos; cache ...............................................................[done]
Retrieving repository &apos;openSUSE-13.2-Oss&apos; metadata ..............................................................[done]
Building repository &apos;openSUSE-13.2-Oss&apos; cache ...................................................................[done]
Retrieving repository &apos;openSUSE-13.2-Update&apos; metadata ...........................................................[done]
Building repository &apos;openSUSE-13.2-Update&apos; cache ................................................................[done]
Retrieving repository &apos;openSUSE-13.2-Update-Non-Oss&apos; metadata ...................................................[done]
Building repository &apos;openSUSE-13.2-Update-Non-Oss&apos; 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 &apos;openSUSE-13.2-0&apos; is up to date.
Repository &apos;openSUSE-13.2-Debug&apos; is up to date.
Repository &apos;openSUSE-13.2-Non-Oss&apos; is up to date.
Repository &apos;openSUSE-13.2-Oss&apos; is up to date.
Repository &apos;openSUSE-13.2-Update&apos; is up to date.
Repository &apos;openSUSE-13.2-Update-Non-Oss&apos; is up to date.
All repositories have been refreshed. 
  1. 刷新一個指定的軟體庫(以 'repo-non-oss' 為例 )。
# zypper refresh repo-non-oss
Repository &apos;openSUSE-13.2-Non-Oss&apos; 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 &apos;openSUSE-13.2-Non-Oss&apos; metadata ............................................................[done]
Forcing building of repository cache
Building repository &apos;openSUSE-13.2-Non-Oss&apos; 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 &apos;repo-oss&apos; has been successfully disabled.
  1. 如果需要再次開啟軟體庫 『repo-oss『, 接上例,與之相關聯的標示數字為 6。
# zypper mr -e 6
Repository &apos;repo-oss&apos; has been successfully enabled.
  1. 針對某一個軟體庫(以 'repo-non-oss' 為例 )開啟自動刷新( auto-refresh )和 rpm 緩存,並設置該軟體庫的優先順序,比如85。
# zypper mr -rk -p 85 repo-non-oss
Repository &apos;repo-non-oss&apos; priority has been left unchanged (85)
Nothing to change for repository &apos;repo-non-oss&apos;.
  1. 對所有的軟體庫關閉 rpm 文件緩存。
# zypper mr -Ka
RPM files caching has been disabled for repository &apos;openSUSE-13.2-0&apos;.
RPM files caching has been disabled for repository &apos;repo-debug&apos;.
RPM files caching has been disabled for repository &apos;repo-debug-update&apos;.
RPM files caching has been disabled for repository &apos;repo-debug-update-non-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-non-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-source&apos;.
RPM files caching has been disabled for repository &apos;repo-update&apos;.
RPM files caching has been disabled for repository &apos;repo-update-non-oss&apos;.
  1. 對所有的軟體庫開啟 rpm 文件緩存。
# zypper mr -ka
RPM files caching has been enabled for repository &apos;openSUSE-13.2-0&apos;.
RPM files caching has been enabled for repository &apos;repo-debug&apos;.
RPM files caching has been enabled for repository &apos;repo-debug-update&apos;.
RPM files caching has been enabled for repository &apos;repo-debug-update-non-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-non-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-source&apos;.
RPM files caching has been enabled for repository &apos;repo-update&apos;.
RPM files caching has been enabled for repository &apos;repo-update-non-oss&apos;.
  1. 關閉遠程庫的 rpm 文件緩存
# zypper mr -Kt
RPM files caching has been disabled for repository &apos;repo-debug&apos;.
RPM files caching has been disabled for repository &apos;repo-debug-update&apos;.
RPM files caching has been disabled for repository &apos;repo-debug-update-non-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-non-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-oss&apos;.
RPM files caching has been disabled for repository &apos;repo-source&apos;.
RPM files caching has been disabled for repository &apos;repo-update&apos;.
RPM files caching has been disabled for repository &apos;repo-update-non-oss&apos;.
  1. 開啟遠程軟體庫的 rpm 文件緩存。
# zypper mr -kt
RPM files caching has been enabled for repository &apos;repo-debug&apos;.
RPM files caching has been enabled for repository &apos;repo-debug-update&apos;.
RPM files caching has been enabled for repository &apos;repo-debug-update-non-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-non-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-oss&apos;.
RPM files caching has been enabled for repository &apos;repo-source&apos;.
RPM files caching has been enabled for repository &apos;repo-update&apos;.
RPM files caching has been enabled for repository &apos;repo-update-non-oss&apos;.

增加新的軟體庫

可以通過這兩個 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 &apos;update&apos; .............................................................................................................................................................[done]
Repository &apos;update&apos; 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 &apos;update&apos; renamed to &apos;upd8&apos;.

刪除軟體庫

  1. 刪除一個軟體庫。要從系統刪除一個軟體庫可以使 'zypper removerepo' 或者 'zypper rr'。例如以下的命令可以刪除軟體庫 'upd8'
# zypper rr upd8
# Removing repository &apos;upd8&apos; .........................................................................................[done]
Repository &apos;upd8&apos; 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 &apos;gcc<5.1&apos;
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 &apos;gcc.i586<5.1&apos;
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...
&apos;-vi&apos; 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 &apos;apache2-2.4.10-19.1.x86_64&apos;. The highest available version is already installed.
No update candidate for &apos;openssh-6.6p1-5.1.3.x86_64&apos;. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
  1. 安裝一個軟體庫,例如 mariadb,如果該庫存在則更新之。
# zypper in mariadb
Loading repository data...
Reading installed packages...
&apos;mariadb&apos; is already installed.
No update candidate for &apos;mariadb-10.0.13-2.6.1.x86_64&apos;. 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...
&apos;mariadb&apos; is already installed.
No update candidate for &apos;mariadb-10.0.13-2.6.1.x86_64&apos;. 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...
&apos;mariadb&apos; is already installed.
No update candidate for &apos;mariadb-10.0.13-2.6.1.x86_64&apos;. 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 &apos;man zypper&apos; for more information about this command.
Building repository &apos;openSUSE-13.2-0&apos; cache .....................................................................[done]
Retrieving repository &apos;openSUSE-13.2-Debug&apos; metadata ............................................................[done]
Building repository &apos;openSUSE-13.2-Debug&apos; cache .................................................................[done]
Retrieving repository &apos;openSUSE-13.2-Non-Oss&apos; metadata ..........................................................[done]
Building repository &apos;openSUSE-13.2-Non-Oss&apos; cache ...............................................................[done]

正文至此結束。希望本文可以幫助讀者尤其是新手們管理SUSE Linux系統和伺服器。如果您覺得某些比較重要的命令被作者漏掉了,請在評論部分寫下您的返回,作者將根據評論對文章進行更新。保持聯絡,保持評論,多謝支持。

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

作者:Avishek Kumar 譯者:張博約 校對:wxy

本文由 LCTT 原創翻譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國