14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zypperコマンドの使い方

Last updated at Posted at 2017-08-18

#1 はじめに
zypperコマンドの使い方だけを確認したかったので、コンテナを使って確認しました。

#2 環境
VMware Workstation 12 Player上のゲストマシンを使っています。

[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

[root@server ~]# uname -r
3.10.0-514.el7.x86_64

#3 openSUSEコンテナの起動方法

Dockerをインストールする。
[root@server ~]# yum -y install docker

Dockerを起動する。
[root@server ~]# systemctl start docker

openSUSEのイメージをダウンロードする。
[root@server ~]# docker pull opensuse:latest
[root@server ~]# docker images opensuse
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
docker.io/opensuse   latest              04129f4661e6        12 days ago         108.2 MB

コンテナ(openSUSE)を起動する。
[root@server ~]# docker run -it --rm opensuse bash
bash-4.3#

zypperコマンドの版数を確認する。
bash-4.3# zypper --version
zypper 1.13.28

#4 リポジトリに関する操作

##4.1 リポジトリの表示に関する捜査
###4.1.1 リポジトリを簡潔に表示する方法(lr)

bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | non-oss        | NON-OSS        | Yes     | ( p) Yes  | Yes
2 | oss            | OSS            | Yes     | ( p) Yes  | Yes
3 | oss-update     | OSS Update     | Yes     | ( p) Yes  | Yes
4 | update-non-oss | Update Non-Oss | Yes     | ( p) Yes  | Yess

###4.1.2 リポジトリのURIを表示する方法(lr -u)

admin:~ # zypper lr -u
Repository priorities are without effect. All enabled repositories share the same priority.

#  | Alias                     | Name                                    | Enabled | GPG Check | Refresh | URI                                                  
---+---------------------------+-----------------------------------------+---------+-----------+---------+---------------------------------------------------------------------------------------
 1 | openSUSE-Leap-42.3-0      | openSUSE-Leap-42.3-0                    | No      | ----      | ----    | cd:///?devices=/dev/disk/by-id/ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001
 2 | repo-debug                | openSUSE-Leap-42.3-Debug                | No      | ----      | ----    | http://download.opensuse.org/debug/distribution/leap/42.3/repo/oss/
 3 | repo-debug-non-oss        | openSUSE-Leap-42.3-Debug-Non-Oss        | No      | ----      | ----    | http://download.opensuse.org/debug/distribution/leap/42.3/repo/non-oss/
 4 | repo-debug-update         | openSUSE-Leap-42.3-Update-Debug         | No      | ----      | ----    | http://download.opensuse.org/debug/update/leap/42.3/oss/
 5 | repo-debug-update-non-oss | openSUSE-Leap-42.3-Update-Debug-Non-Oss | No      | ----      | ----    | http://download.opensuse.org/debug/update/leap/42.3/non-oss/
 6 | repo-non-oss              | openSUSE-Leap-42.3-Non-Oss              | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/distribution/leap/42.3/repo/non-oss/
 7 | repo-oss                  | openSUSE-Leap-42.3-Oss                  | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/distribution/leap/42.3/repo/oss/
 8 | repo-source               | openSUSE-Leap-42.3-Source               | No      | ----      | ----    | http://download.opensuse.org/source/distribution/leap/42.3/repo/oss/
 9 | repo-source-non-oss       | openSUSE-Leap-42.3-Source-Non-Oss       | No      | ----      | ----    | http://download.opensuse.org/source/distribution/leap/42.3/repo/non-oss/
10 | repo-update               | openSUSE-Leap-42.3-Update               | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/42.3/oss/   
11 | repo-update-non-oss       | openSUSE-Leap-42.3-Update-Non-Oss       | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/42.3/non-oss/

##4.2 リポジトリを更新する方法(refresh)

bash-4.3# zypper refresh
Retrieving repository 'NON-OSS' metadata ...........................................................................[done]
Building repository 'NON-OSS' cache ................................................................................[done]
Retrieving repository 'OSS' metadata ...............................................................................[done]
Building repository 'OSS' cache ....................................................................................[done]
Retrieving repository 'OSS Update' metadata ........................................................................[done]
Building repository 'OSS Update' cache .............................................................................[done]
Retrieving repository 'Update Non-Oss' metadata ....................................................................[done]
Building repository 'Update Non-Oss' cache .........................................................................[done]
All repositories have been refreshed.

##4.3 リポジトリを追加する方法(ar)

リポジトリの追加は下記のように実行します。
# zypper ar [URL] [リポジトリ名]
ここでは、ossリポジトリを追加してみます。
リポジトリのURLについては、4.8を参照してください。

現在のリポジトリを確認する。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
2 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
3 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

ossリポジトリを追加する。
bash-4.3# zypper ar http://download.opensuse.org/distribution/leap/42.3/repo/oss oss
Adding repository 'oss' ............................................................................................................................[done]
Repository 'oss' successfully added

URI         : http://download.opensuse.org/distribution/leap/42.3/repo/oss
Enabled     : Yes
GPG Check   : Yes
Autorefresh : No
Priority    : 99 (default priority)

Repository priorities are without effect. All enabled repositories share the same priority.

リポジトリを確認する。ossリポジトリ(★)が追加されたことがわかる。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
2 | oss ★         | oss            | Yes     | ( p) Yes  | No
3 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
4 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

リポジトリの状態を更新する。ossリポジトリの状態が更新されたことがわかる。
bash-4.3# zypper ref
Repository 'NON-OSS' is up to date.
Retrieving repository 'oss' metadata ...............................................................................................................[done]
Building repository 'oss' cache ....................................................................................................................[done]
Retrieving repository 'OSS Update' metadata ........................................................................................................[done]
Building repository 'OSS Update' cache .............................................................................................................[done]
Retrieving repository 'Update Non-Oss' metadata ....................................................................................................[done]
Building repository 'Update Non-Oss' cache .........................................................................................................[done]
All repositories have been refreshed.

##4.4 リポジトリを削除する方法(rr)

"fonts"リポジトリを削除する。
bash-4.3# zypper rr fonts
Removing repository 'fonts' .........................................................................................................[done]
Repository 'fonts' has been removed.

リポジトリを確認する。"fonts"リポジトリが削除されたことがわかる。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
2 | oss            | OSS            | Yes     | (r ) Yes  | Yes
3 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
4 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

##4.5 リポジトリを自動更新する方法(modifyrepo -r)

"fonts"リポジトリの自動更新を有効にする。
bash-4.3# zypper modifyrepo -r fonts
Autorefresh has been enabled for repository 'fonts'.

リポジトリを確認する。"fonts"リポジトリの自動更新が有効になったことがわかる(★)。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | fonts          | fonts          | Yes     | ( p) Yes  | Yes★
2 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
3 | oss            | OSS            | Yes     | (r ) Yes  | Yes
4 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
5 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

##4.6 リポジトリを無効にする方法(modifyrepo -d)

"fonts"リポジトリを無効にする。
bash-4.3# zypper modifyrepo -d fonts
Repository 'fonts' has been successfully disabled.

リポジトリを確認する。"fonts"リポジトリが無効(★)になったことがわかる。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | fonts          | fonts          | No★    | ----      | ----
2 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
3 | oss            | OSS            | Yes     | (r ) Yes  | Yes
4 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
5 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

##4.7 リポジトリを有効にする方法(modifyrepo -e)

"fonts"リポジトリを有効にする。
bash-4.3# zypper modifyrepo -e fonts
Repository 'fonts' has been successfully enabled.

リポジトリを確認する。"fonts"リポジトリが有効(★)になったことがわかる。
bash-4.3# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

# | Alias          | Name           | Enabled | GPG Check | Refresh
--+----------------+----------------+---------+-----------+--------
1 | fonts          | fonts          | Yes★   | ( p) Yes  | Yes
2 | non-oss        | NON-OSS        | Yes     | (r ) Yes  | Yes
3 | oss            | OSS            | Yes     | (r ) Yes  | Yes
4 | oss-update     | OSS Update     | Yes     | (r ) Yes  | Yes
5 | update-non-oss | Update Non-Oss | Yes     | (r ) Yes  | Yes

##4.8 現在のリポジトリ情報を取得する方法

リポジトリ情報をファイル(foo.repo)に保存する。
bash-4.3# zypper lr --export foo.repo
Repositories have been successfully exported to ./foo.repo.

ファイルに保存したリポジトリ情報を確認する。
non-oss,oss,oss-update,update-non-ossといったリポジトリのURL等の情報が確認できる。
bash-4.3# more foo.repo
[non-oss]
name=NON-OSS
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/distribution/leap/42.3/repo/non-oss/
path=/
type=yast2
keeppackages=0

[oss]
enabled=1
autorefresh=0
baseurl=http://download.opensuse.org/distribution/leap/42.3/repo/oss
type=yast2

[oss-update]
name=OSS Update
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/update/leap/42.3/oss/
path=/
type=rpm-md
keeppackages=0

[update-non-oss]
name=Update Non-Oss
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/update/leap/42.3/non-oss/
path=/
type=rpm-md
keeppackages=0

#5 パッケージに関する操作
##5.1 パッケージをインストールする方法(in)
"non-interactive"オプションを使うと、Yes/Noの問い合わせなしでパッケージをインストールできます。
yumコマンドの-yオプションに相当します。

keepalivedパッケージを確認する。
bash-4.3# zypper --non-interactive in keepalived
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  keepalived

1 new package to install.
Overall download size: 190.8 KiB. Already cached: 0 B. After the operation, additional 569.3 KiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package keepalived-1.2.15-6.17.x86_64                                                                     (1/1), 190.8 KiB (569.3 KiB unpacked)
Retrieving: keepalived-1.2.15-6.17.x86_64.rpm .........................................................................................[done (92.8 KiB/s)]
Checking for file conflicts: .......................................................................................................................[done]
(1/1) Installing: keepalived-1.2.15-6.17.x86_64 ....................................................................................................[done]
Additional rpm output:
Updating /etc/sysconfig/keepalived...
Failed to connect to bus: No such file or directory
Operation failed: No such file or directory

インストールしたkeepalivedの版数を確認する。
bash-4.3# keepalived --version
Keepalived v1.2.15 (07/08,2017)

##5.2 パッケージを削除する方法(rm)
non-interactiveモードでkeepalivedパッケージを削除します。

bash-4.3# zypper --non-interactive rm keepalived
-以下、略-

##5.3 パッケージを検索する方法(se)

bcパッケージを検索する。
"match-exact"オプションを使うことで、パッケージ名(bc)に正確に一致するものだけを検索します。
bash-4.3# zypper se -s --match-exact bc
Loading repository data...
Reading installed packages...

S | Name | Type    | Version       | Arch   | Repository
--+------+---------+---------------+--------+-----------
  | bc   | package | 1.06.95-11.13 | x86_64 | OSS

#6 ソースパッケージのインストール方法(si)

##6.1 ソースパッケージが存在するリポジトリの有効

リポジトリを確認する。bcのソースパッケージはrepo-sourceにあるが、現時点では無効(★)になっている。
server:~ # zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

#  | Alias                     | Name                                    | Enabled | GPG Check | Refresh
---+---------------------------+-----------------------------------------+---------+-----------+--------
 1 | openSUSE-Leap-42.3-0      | openSUSE-Leap-42.3-0                    | No      | ----      | ----
 2 | repo-debug                | openSUSE-Leap-42.3-Debug                | No      | ----      | ----
 3 | repo-debug-non-oss        | openSUSE-Leap-42.3-Debug-Non-Oss        | No      | ----      | ----
 4 | repo-debug-update         | openSUSE-Leap-42.3-Update-Debug         | No      | ----      | ----
 5 | repo-debug-update-non-oss | openSUSE-Leap-42.3-Update-Debug-Non-Oss | No      | ----      | ----
 6 | repo-non-oss              | openSUSE-Leap-42.3-Non-Oss              | Yes     | (r ) Yes  | Yes
 7 | repo-oss                  | openSUSE-Leap-42.3-Oss                  | Yes     | (r ) Yes  | Yes
 8 | repo-source               | openSUSE-Leap-42.3-Source               |★No     | ----      | ----
 9 | repo-source-non-oss       | openSUSE-Leap-42.3-Source-Non-Oss       | No      | ----      | ----
10 | repo-update               | openSUSE-Leap-42.3-Update               | Yes     | (r ) Yes  | Yes
11 | repo-update-non-oss       | openSUSE-Leap-42.3-Update-Non-Oss       | Yes     | (r ) Yes  | Yes

repo-sourceリポジトリを有効にする。
server:~ # zypper modifyrepo -e repo-source
Repository 'repo-source' has been successfully enabled.

リポジトリの状態を確認する。repo-sourceリポジトリが有効(★)になったことがわかる。
[server:~ # zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.

#  | Alias                     | Name                                    | Enabled | GPG Check | Refresh
---+---------------------------+-----------------------------------------+---------+-----------+--------
 1 | openSUSE-Leap-42.3-0      | openSUSE-Leap-42.3-0                    | No      | ----      | ----
 2 | repo-debug                | openSUSE-Leap-42.3-Debug                | No      | ----      | ----
 3 | repo-debug-non-oss        | openSUSE-Leap-42.3-Debug-Non-Oss        | No      | ----      | ----
 4 | repo-debug-update         | openSUSE-Leap-42.3-Update-Debug         | No      | ----      | ----
 5 | repo-debug-update-non-oss | openSUSE-Leap-42.3-Update-Debug-Non-Oss | No      | ----      | ----
 6 | repo-non-oss              | openSUSE-Leap-42.3-Non-Oss              | Yes     | (r ) Yes  | Yes
 7 | repo-oss                  | openSUSE-Leap-42.3-Oss                  | Yes     | (r ) Yes  | Yes
 8 | repo-source               | openSUSE-Leap-42.3-Source               |★Yes    | (r ) Yes  | Yes
 9 | repo-source-non-oss       | openSUSE-Leap-42.3-Source-Non-Oss       | No      | ----      | ----
10 | repo-update               | openSUSE-Leap-42.3-Update               | Yes     | (r ) Yes  | Yes
11 | repo-update-non-oss       | openSUSE-Leap-42.3-Update-Non-Oss       | Yes     | (r ) Yes  | Yes

##6.2 ソースパッケージのインストール(si)

bcのソースパッケージをインストールする。
server:~ # zypper si bc
Reading installed packages...
Loading repository data...
Resolving package dependencies...

The following source package is going to be installed:
  bc

1 source package to install.
Overall download size: 294.8 KiB. Already cached: 0 B. After the operation, additional 293.0 KiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving srcpackage bc-1.06.95-11.13.noarch                                                                       (1/1)
Retrieving: bc-1.06.95-11.13.src.rpm ..............................................................................[done]
Checking for file conflicts: ......................................................................................[done]
(1/1) Installing: bc-1.06.95-11.13.src ............................................................................[done]
server:~ #

インストールしたパッケージは、/usr/src/packages配下にインストールされます。
server:~ # ls -F /usr/src/packages/
BUILD/  BUILDROOT/  RPMS/  SOURCES/  SPECS/  SRPMS/

##6.3 ソースの展開

server:/usr/src/packages/SPECS # pwd
/usr/src/packages/SPECS

server:/usr/src/packages/SPECS # ls
bc.spec

パッケージをビルドする。
server:/usr/src/packages/SPECS # rpmbuild -bp bc.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.NyC81L
+ umask 022
+ cd /usr/src/packages/BUILD
+ cd /usr/src/packages/BUILD
+ rm -rf bc-1.06.95
+ /usr/bin/bzip2 -dc /usr/src/packages/SOURCES/bc-1.06.95.tar.bz2
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd bc-1.06.95
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ echo 'Patch #1 (bc-1.06-dc_ibase.patch):'
Patch #1 (bc-1.06-dc_ibase.patch):
+ /usr/bin/cat /usr/src/packages/SOURCES/bc-1.06-dc_ibase.patch
+ /usr/bin/patch -p1 -b --suffix .dc_ibase --fuzz=0
patching file dc/numeric.c
Hunk #1 succeeded at 308 (offset 23 lines).
Hunk #2 succeeded at 327 (offset 23 lines).
Hunk #3 succeeded at 337 (offset 23 lines).
Hunk #4 succeeded at 354 (offset 23 lines).
+ echo 'Patch #2 (bc-1.06.95-memleak.patch):'
Patch #2 (bc-1.06.95-memleak.patch):
+ /usr/bin/cat /usr/src/packages/SOURCES/bc-1.06.95-memleak.patch
+ /usr/bin/patch -p1 -b --suffix .memleak --fuzz=0
patching file bc/bc.y
patching file bc/util.c
+ echo 'Patch #3 (bc-1.06.95-matlib.patch):'
Patch #3 (bc-1.06.95-matlib.patch):
+ /usr/bin/cat /usr/src/packages/SOURCES/bc-1.06.95-matlib.patch
+ /usr/bin/patch -p1 -b --suffix .matlib --fuzz=0
patching file bc/storage.c
+ echo 'Patch #4 (bc-1.06.95-sigintmasking.patch):'
Patch #4 (bc-1.06.95-sigintmasking.patch):
+ /usr/bin/patch -p1 -b --suffix .sigintmask --fuzz=0
+ /usr/bin/cat /usr/src/packages/SOURCES/bc-1.06.95-sigintmasking.patch
patching file dc/eval.c
patching file doc/dc.texi
+ exit 0
server:/usr/src/packages/SPECS #

ビルドしたソースはBUILD配下に作成されます。
server:/usr/src/packages/BUILD/bc-1.06.95 # pwd
/usr/src/packages/BUILD/bc-1.06.95

BUILD配下のファイルを確認する。BUILD配下にソースが展開されたことがわかる。
server:/usr/src/packages/BUILD/bc-1.06.95 # ls
AUTHORS      ChangeLog  INSTALL      NEWS    aclocal.m4   configure     depcomp  install-sh
COPYING      Examples   Makefile.am  README  bc           configure.in  doc      lib
COPYING.LIB  FAQ        Makefile.in  Test    config.h.in  dc            h        missing

#7 ソースパッケージのダウンロード方法
ここでは、ipsetパッケージのソースパッケージをダウンロードしてみます。
まず、rpmファイルの版数を確認します。

版数確認
master:~ # rpm -qa|grep ipset
ipset-6.29-4.4.1.x86_64

src.rpmファイルをダウンロードします。

src.rpmのダウンロード
master:~ # zypper in -t srcpackage -d ipset=6.29-4.4.1
(中略)

The following source package is going to be installed:
  ipset

1 source package to install.
Overall download size: 544.0 KiB. Already cached: 0 B. Download only.
Continue? [y/n/...? shows all options] (y): y
Retrieving srcpackage ipset-6.29-4.4.1.noarch                                                                                                  (1/1)
Retrieving: ipset-6.29-4.4.1.src.rpm ...........................................................................................[done (363.8 KiB/s)]

ダウンロードしたsrc.rpmファイルは、/var/cache/zypp配下に保存されるようです。

ダウンロードしたsrc.rpmの確認
master:~ # find /var/cache -name "ipset*" -printf "%p %TY-%Tm-%Td %TH:%TM\n"
/var/cache/zypp/packages/repo-update/src/ipset-6.29-4.4.1.src.rpm 2018-11-27 16:41

#X 参考情報
Zypper の使い方
openSUSE 13.2にパッケージリポジトリを追加する
追加のパッケージ・リポジトリ

SuSE パッケージ検索
Package repositories
opensuse/distribution/openSUSE-current/repo/oss/suse/x86_64/
第5章 SystemTap—システムデータのフィルタと分析
パッケージリポジトリ

14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?