2021-05-12 14:32:11
用於 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 伺服器的詳細資訊。
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 幫助資訊
-
不帶任何選項的執行 zypper, 將輸出該命令的全域性選項以及子命令列表(LCTT 譯者注:全域性選項,global option,控制台命令的輸入分為可選引數和位置引數兩大類。按照習慣,一般可選引數稱為選項'option',而位置引數稱為引數 'argument')。
# zypper
Usage:
zypper [--global-options]
-
獲取一個具體的子命令的幫助資訊,比如 '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,notby 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.
Handyif 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.Defaultis to treat file conflicts
as an error.--download-as-needed disables the fileconflict check.
......
-
安裝之前搜尋一個安轉包(以 gnome-desktop 為例 )
# zypper se gnome-desktop
Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata .........................................................[done]
Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]
Retrieving repository 'openSUSE-13.2-Oss' metadata ..............................................................[done]
Building repository 'openSUSE-13.2-Oss' cache ...................................................................[done]
Retrieving repository 'openSUSE-13.2-Update' metadata ...........................................................[done]
Building repository 'openSUSE-13.2-Update' cache ................................................................[done]
Retrieving repository 'openSUSE-13.2-Update-Non-Oss' metadata ...................................................[done]
Building repository 'openSUSE-13.2-Update-Non-Oss' cache ........................................................[done]
Loading repository data...
Reading installed packages...
S |Name|Summary|Type
--+---------------------------------------+-----------------------------------------------------------+-----------
| gnome-desktop2-lang |Languagesforpackage 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--DevelopmentFiles|package
| libgnome-desktop-3_0-common |The GNOME Desktop API Library--Common data files |package
| gnome-desktop-debugsource |Debug sources forpackage gnome-desktop |package
| gnome-desktop-sharp2-debugsource |Debug sources forpackage gnome-desktop-sharp2 |package
| gnome-desktop2-debugsource |Debug sources forpackage gnome-desktop2 |package
| libgnome-desktop-2-17-debuginfo |Debug information forpackage libgnome-desktop-2-17|package
| libgnome-desktop-3-10-debuginfo |Debug information forpackage libgnome-desktop-3-10|package
| libgnome-desktop-3_0-common-debuginfo |Debug information forpackage libgnome-desktop-3_0-common |package
| libgnome-desktop-2-17-debuginfo-32bit|Debug information forpackage libgnome-desktop-2-17|package
| libgnome-desktop-3-10-debuginfo-32bit|Debug information forpackage libgnome-desktop-3-10|package
| gnome-desktop-sharp2 |Mono bindings for libgnome-desktop |package
| libgnome-desktop-2-devel |The GNOME Desktop API Library--DevelopmentFiles| packag
| gnome-desktop-lang |Languagesforpackage 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
-
獲取一個模式包的資訊(以 lamp_server 為例)。
# zypper info -t pattern lamp_server
Loading repository data...
Reading installed packages...
Informationfor 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:Weband 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,orPerl.
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|
-
開啟一個Zypper Shell 的對談。
# zypper shell
或者
# zypper sh
zypper> help
Usage:
zypper [--global-options]
注意:在 Zypper shell裡面可以通過鍵入 ‘help‘ 獲得全域性選項以及子命令的列表。
Zypper 軟體庫管理
列舉已定義的軟體庫
-
使用 '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
-
在表格裡面顯示 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/
-
根據優先順序列舉軟體庫。
# 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
重新整理軟體庫
-
使用 'zypper refresh' or 'zypper ref' 來重新整理 zypper 軟體庫。
# zypper refresh
或者
# zypper ref
Repository'openSUSE-13.2-0'is up to date.
Repository'openSUSE-13.2-Debug'is up to date.
Repository'openSUSE-13.2-Non-Oss'is up to date.
Repository'openSUSE-13.2-Oss'is up to date.
Repository'openSUSE-13.2-Update'is up to date.
Repository'openSUSE-13.2-Update-Non-Oss'is up to date.
All repositories have been refreshed.
-
重新整理一個指定的軟體庫(以 'repo-non-oss' 為例 )。
# zypper refresh repo-non-oss
Repository'openSUSE-13.2-Non-Oss'is up to date.
Specified repositories have been refreshed.
-
強制更新一個軟體庫(以 'repo-non-oss' 為例 )。
# zypper ref -f repo-non-oss
Forcing raw metadata refresh
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ............................................................[done]
Forcing building of repository cache
Building repository 'openSUSE-13.2-Non-Oss' cache ............................................................[done]
Specified repositories have been refreshed.
修改軟體庫
本文中我們使用‘zypper modifyrepo‘ 或者 ‘zypper mr‘ 來關閉或者開啟 zypper 軟體庫。
-
在關閉一個軟體庫之前,我們需要知道在 zypper 中,每一個軟體庫有一個唯一的標示數位與之關聯,該數位用於開啟或者關閉與之相聯絡的軟體庫。假設我們需要關閉 'repo-oss' 軟體庫,那麼我們可以通過以下的法來獲得該軟體庫的標誌數位。
# zypper lr
|Alias|Name|Enabled|Refresh
--+---------------------------+------------------------------------+---------+--------
1| openSUSE-13.2-0| openSUSE-13.2-0|Yes|No
2| repo-debug | openSUSE-13.2-Debug|Yes|Yes
3| repo-debug-update | openSUSE-13.2-Update-Debug|No|Yes
4| repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss|No|Yes
5| repo-non-oss | openSUSE-13.2-Non-Oss|Yes|Yes
6| repo-oss | openSUSE-13.2-Oss|No|Yes
7| repo-source | openSUSE-13.2-Source|No|Yes
8| repo-update | openSUSE-13.2-Update|Yes|Yes
9| repo-update-non-oss | openSUSE-13.2-Update-Non-Oss|Yes|Yes
從以上輸出的列表中我們可以看到 'repo-oss' 庫的標示數位是 6,因此通過以下的命令來關閉該庫。
# zypper mr -d 6
Repository'repo-oss' has been successfully disabled.
-
如果需要再次開啟軟體庫 ‘repo-oss‘, 接上例,與之相關聯的標示數位為 6。
# zypper mr -e 6
Repository'repo-oss' has been successfully enabled.
-
針對某一個軟體庫(以 'repo-non-oss' 為例 )開啟自動重新整理( auto-refresh )和 rpm 快取,並設定該軟體庫的優先順序,比如85。
# zypper mr -rk -p 85 repo-non-oss
Repository'repo-non-oss' priority has been left unchanged (85)
Nothing to change for repository 'repo-non-oss'.
-
對所有的軟體庫關閉 rpm 檔案快取。
# zypper mr -Ka
RPM files caching has been disabled for repository 'openSUSE-13.2-0'.
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
-
對所有的軟體庫開啟 rpm 檔案快取。
# zypper mr -ka
RPM files caching has been enabled for repository 'openSUSE-13.2-0'.
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.
-
關閉遠端庫的 rpm 檔案快取
# zypper mr -Kt
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
-
開啟遠端軟體庫的 rpm 檔案快取。
# zypper mr -kt
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.
增加新的軟體庫
可以通過這兩個 zypper 指令 – 'zypper addrepo' 和 'zypper ar' 來增加新的軟體庫。在此過程中可以使用 URL 或者軟體庫的別名。
-
增加一個新的軟體庫( 以 “http://download.opensuse.org/update/12.3/” 為例 )。
# zypper ar http://download.opensuse.org/update/11.1/ update
Adding repository 'update'.............................................................................................................................................................[done]
Repository'update' successfully added
Enabled:Yes
Autorefresh:No
GPG check :Yes
URI : http://download.opensuse.org/update/11.1/
-
更改一個軟體庫的名字,這將僅僅改變軟體庫的別名。 命令 'zypper namerepo' 或者 'zypperr nr' 可以勝任此工作。例如更改標示數位為10的軟體庫的名字為 'upd8',或者說將標示數位為10的軟體庫的別名改為 'upd8',可以使用下面的命令。
# zypper nr 10 upd8
Repository'update' renamed to 'upd8'.
刪除軟體庫
-
刪除一個軟體庫。要從系統刪除一個軟體庫可以使 'zypper removerepo' 或者 'zypper rr'。例如以下的命令可以刪除軟體庫 'upd8'
# zypper rr upd8
# Removing repository 'upd8' .........................................................................................[done]
Repository'upd8' has been removed.
相關文章