0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntuのパッケージ利用について

Posted at

apt(apt-get)コマンド、dpkgコマンドによって、debパッケージを利用する方法について、Copilotに聞きながら調べたことをまとめます。

1. パッケージ情報の参照

ここでは、htopコマンドのパッケージ(topのUIがフレンドリーなもの)を例にします。

まず、OSにパッケージが入っているかどうかは、dpkg -lです。「ii」なら入っています。

root@u24043s-vm1:~# dpkg -l | grep -e Architecture -e htop
||/ Name                                         Version                                 Architecture Description
ii  htop                                         3.3.0-4build1                           amd64        interactive processes viewer
root@u24043s-vm1:~#

「ii」のところの表示の意味は、以下、とのこと。

1文字目: ユーザーが望む操作(Desired action)

  • i: Install(インストール)
  • r: Remove(削除)
  • p: Purge(完全削除)
  • u: Unpack(展開)

2文字目: 現在の状態(Actual status)

  • n: Not-installed(未インストール)
  • i: Installed(インストール済み)
  • c: Config-files(設定ファイルのみ残存)
  • U: Unpacked(展開済み)
  • F: Half-configured(設定途中)
  • H: Half-installed(インストール途中)

OSにインストール済みのパッケージの情報を確認するには、apt show htopです。

root@u24043s-vm1:~# apt show htop
Package: htop
Version: 3.3.0-4build1
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Daniel Lange <DLange@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 434 kB
Depends: libc6 (>= 2.38), libncursesw6 (>= 6), libnl-3-200 (>= 3.2.7), libnl-genl-3-200 (>= 3.2.7), libtinfo6 (>= 6)
Suggests: lm-sensors, lsof, strace
Homepage: https://htop.dev/
Task: cloud-image, cloud-image, server, ubuntu-server-raspi, lubuntu-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop-minimal, ubuntu-budgie-desktop, ubuntu-budgie-desktop-raspi
Download-Size: 171 kB
APT-Manual-Installed: no
APT-Sources: http://jp.archive.ubuntu.com/ubuntu noble/main amd64 Packages
Description: interactive processes viewer
 Htop is an ncursed-based process viewer similar to top, but it
 allows one to scroll the list vertically and horizontally to see
 all processes and their full command lines.
 .
 Tasks related to processes (killing, renicing) can be done without
 entering their PIDs.

root@u24043s-vm1:~#

OSにインストール済みのパッケージに含まれるファイルの一覧は、dpkg -Lで見られます。

root@u24043s-vm1:~# dpkg -L htop
/.
/usr
/usr/bin
/usr/bin/htop
/usr/share
/usr/share/applications
/usr/share/applications/htop.desktop
/usr/share/doc
/usr/share/doc/htop
/usr/share/doc/htop/AUTHORS
/usr/share/doc/htop/README.gz
/usr/share/doc/htop/changelog.Debian.gz
/usr/share/doc/htop/copyright
/usr/share/icons
/usr/share/icons/hicolor
/usr/share/icons/hicolor/scalable
/usr/share/icons/hicolor/scalable/apps
/usr/share/icons/hicolor/scalable/apps/htop.svg
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/htop.1.gz
/usr/share/pixmaps
/usr/share/pixmaps/htop.png
root@u24043s-vm1:~#

逆に、ファイルから、どのパッケージに属するかは、dpkg -Sで見られます。

root@u24043s-vm1:~# dpkg -S /usr/share/applications/htop.desktop
htop: /usr/share/applications/htop.desktop
root@u24043s-vm1:~#

2. パッケージの検索

apt-fileコマンドを使うと、キーワードで、パッケージを検索できます。

apt-fileコマンドは、Ubuntu 24.04.3には、デフォルトでは入っていませんでした。入れる場合、以下です。

root@u24043s-vm1:~# apt install apt-file
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libapt-pkg-perl libregexp-assemble-perl
The following NEW packages will be installed:
  apt-file libapt-pkg-perl libregexp-assemble-perl
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 164 kB of archives.
After this operation, 532 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libapt-pkg-perl amd64 0.1.40build7 [68.4 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble/universe amd64 libregexp-assemble-perl all 0.38-2 [69.5 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu noble/universe amd64 apt-file all 3.3 [25.9 kB]
Fetched 164 kB in 2s (74.6 kB/s)
Selecting previously unselected package libapt-pkg-perl.
(Reading database ... 95074 files and directories currently installed.)
Preparing to unpack .../libapt-pkg-perl_0.1.40build7_amd64.deb ...
Unpacking libapt-pkg-perl (0.1.40build7) ...
Selecting previously unselected package libregexp-assemble-perl.
Preparing to unpack .../libregexp-assemble-perl_0.38-2_all.deb ...
Unpacking libregexp-assemble-perl (0.38-2) ...
Selecting previously unselected package apt-file.
Preparing to unpack .../archives/apt-file_3.3_all.deb ...
Unpacking apt-file (3.3) ...
Setting up libapt-pkg-perl (0.1.40build7) ...
Setting up libregexp-assemble-perl (0.38-2) ...
Setting up apt-file (3.3) ...
The system-wide cache is empty. You may want to run 'apt-file update'
as root to update the cache.
Processing triggers for man-db (2.12.0-4build2) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@u24043s-vm1:~#

更新します。

root@u24043s-vm1:~# apt-file update
Hit:1 http://jp.archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:3 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:5 http://jp.archive.ubuntu.com/ubuntu noble amd64 Contents (deb) [51.3 MB]
Hit:6 http://ddebs.ubuntu.com noble InRelease
Get:7 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [21.6 kB]
Hit:8 http://ddebs.ubuntu.com noble-updates InRelease
Get:9 http://security.ubuntu.com/ubuntu noble-security amd64 Contents (deb) [81.8 MB]
Hit:10 http://ddebs.ubuntu.com noble-proposed InRelease
Get:11 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Components [212 B]
Get:12 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [52.2 kB]
Get:13 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [208 B]
Get:14 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [164 kB]
Get:15 http://jp.archive.ubuntu.com/ubuntu noble-updates amd64 Contents (deb) [85.8 MB]
Get:16 http://jp.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Get:17 http://jp.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [377 kB]
Get:18 http://jp.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Get:19 http://jp.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [7,088 B]
Get:20 http://jp.archive.ubuntu.com/ubuntu noble-backports amd64 Contents (deb) [775 kB]
Get:21 http://jp.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [216 B]
Get:22 http://jp.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [30.7 kB]
Get:23 http://jp.archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B]
Fetched 221 MB in 38s (5,843 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@u24043s-vm1:~#

例えば、htop.desktop、というファイルで検索すると、このように、4パッケージがヒットします。

root@u24043s-vm1:~# apt-file search htop.desktop
app-install-data: /usr/share/app-install/desktop/htop:htop.desktop
htop: /usr/share/applications/htop.desktop
libkf5newstuff-data: /usr/share/kf5/kmoretools/presets-kmoretools/htop.desktop
ubuntu-mate-default-settings: /usr/share/mate/applications/htop.desktop
root@u24043s-vm1:~#

フルパスを指定すると、1つに絞られます。

root@u24043s-vm1:~# apt-file search /usr/share/applications/htop.desktop
htop: /usr/share/applications/htop.desktop
root@u24043s-vm1:~#

なかなかに便利ですね。

root@u24043s-vm1:~# apt-file search libvirt-guests
libvirt-daemon: /usr/lib/libvirt/libvirt-guests.sh
libvirt-daemon: /usr/share/man/man8/libvirt-guests.8.gz
libvirt-daemon-system: /etc/default/libvirt-guests
libvirt-daemon-system: /lib/systemd/system/libvirt-guests.service
libvirt-daemon-system-sysv: /etc/init.d/libvirt-guests
libvirt-doc: /usr/share/doc/libvirt-doc/html/manpages/libvirt-guests.html
root@u24043s-vm1:~#

ただし、デバッグ情報パッケージは、ヒットしませんでした。

root@u24043s-vm1:~# apt-file search /usr/lib/debug/boot/vmlinux-6.8.0-71-generic
root@u24043s-vm1:~#
root@u24043s-vm1:~# apt-file search vmlinux-6.8.0-71-generic
root@u24043s-vm1:~#

正しいファイル名で検索していますが、上記の通り、なし、の結果でした。

root@u24043s-vm1:~# dpkg -L linux-image-unsigned-6.8.0-71-generic-dbgsym | grep /usr/lib/debug/boot/vmlinu
x-6.8.0-71-generic
/usr/lib/debug/boot/vmlinux-6.8.0-71-generic
root@u24043s-vm1:~#

apt-file searchは、以下のContentsファイルを参照して探していますが、ここに、ddeb.ubuntu.comの情報がないため、検索ができない、とのこと。

root@u24043s-vm1:~# find /var/lib/apt/lists/ -name "*Contents*"
/var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_noble-security_Contents-amd64.lz4
/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_noble_Contents-amd64.lz4
/var/lib/apt/lists/Contents-amd64.lz4
/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_noble-updates_Contents-amd64.lz4
/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_noble-backports_Contents-amd64.lz4
root@u24043s-vm1:~#

手動追加することもできない(そもそも、提供されていない)とのことです。

3. パッケージの追加

nginxを追加してみます。nginxはデフォルトでは入っていません。

root@u24043s-vm1:~# dpkg -l | grep nginx
root@u24043s-vm1:~#

入れます。入れる時迷ったのが、以下のどれを使えばいいかです。
・apt install
・apt-get install?
・dpkg -i

Copilotによると、以下、とのこと。
・apt、apt-getは、yumやdnfに相当する、高レベルのパッケージ管理で、依存解決やリポジトリ連携を行う。
・dpkgは、rpmに相当する、低レベルのパッケージ操作で、依存関係は、知らせはするが、解決まではしてくれない。
・aptは、Ubuntu 16.04以降追加されたもので、apt-get(1998年頃から存在)よりも、よりユーザフレンドリ。
・人間が対話的に使うならapt、スクリプトで使うならapt-getを使い分けると良い。
・aptは、内部的には、apt-get、apt-cache、dpkgなどを呼び出している。

ということで、dnf install nginxに相当することをしたければ、以下、となります。

root@u24043s-vm1:~# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  nginx-common
Suggested packages:
  fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
  nginx nginx-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 564 kB of archives.
After this operation, 1,596 kB of additional disk space will be used.
Do you want to continue? [Y/n]

このように、「The following NEW packages will be installed:」「nginx nginx-common」と、これこれを入れていいか、と聞かれますので、「y」を入れて進めます。

Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 nginx-common all 1.24.0-2ubuntu7.4 [43.4 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 nginx amd64 1.24.0-2ubuntu7.4 [521 kB]
Fetched 564 kB in 2s (236 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 95148 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.24.0-2ubuntu7.4_all.deb ...
Unpacking nginx-common (1.24.0-2ubuntu7.4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.24.0-2ubuntu7.4_amd64.deb ...
Unpacking nginx (1.24.0-2ubuntu7.4) ...
Setting up nginx-common (1.24.0-2ubuntu7.4) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Setting up nginx (1.24.0-2ubuntu7.4) ...
 * Upgrading binary nginx                                                                          [ OK ]
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for ufw (0.36.2-6) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@u24043s-vm1:~#

入りました。

root@u24043s-vm1:~# dpkg -l | grep nginx
ii  nginx                                        1.24.0-2ubuntu7.4                       amd64        small, powerful, scalable web/proxy server
ii  nginx-common                                 1.24.0-2ubuntu7.4                       all          small, powerful, scalable web/proxy server - common files
root@u24043s-vm1:~#

nginxパッケージはamd64アーキテクチャのファイル、nginx-commonはアーキテクチャ非依存のファイル、と分かれているようですね。

root@u24043s-vm1:~# dpkg -L nginx
/.
/usr
/usr/sbin
/usr/sbin/nginx
/usr/share
/usr/share/doc
/usr/share/doc/nginx
/usr/share/doc/nginx/changelog.Debian.gz
/usr/share/doc/nginx/copyright
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/nginx.8.gz
root@u24043s-vm1:~#
root@u24043s-vm1:~# dpkg -L nginx-common
/.
/etc
/etc/default
/etc/default/nginx
/etc/init.d
/etc/init.d/nginx
/etc/logrotate.d
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules-available
/etc/nginx/modules-enabled
/etc/nginx/nginx.conf
/etc/nginx/proxy_params
/etc/nginx/scgi_params
/etc/nginx/sites-available
/etc/nginx/sites-available/default
/etc/nginx/sites-enabled
/etc/nginx/snippets
/etc/nginx/snippets/fastcgi-php.conf
/etc/nginx/snippets/snakeoil.conf
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/ufw
/etc/ufw/applications.d
/etc/ufw/applications.d/nginx
/usr
/usr/lib
/usr/lib/systemd
/usr/lib/systemd/system
/usr/lib/systemd/system/nginx.service
/usr/share
/usr/share/apport
/usr/share/apport/package-hooks
/usr/share/apport/package-hooks/source_nginx.py
/usr/share/doc
/usr/share/doc/nginx-common
/usr/share/doc/nginx-common/changelog.Debian.gz
/usr/share/doc/nginx-common/copyright
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/index.html
/usr/share/vim
/usr/share/vim/addons
/usr/share/vim/addons/ftdetect
/usr/share/vim/addons/ftdetect/nginx.vim
/usr/share/vim/addons/ftplugin
/usr/share/vim/addons/ftplugin/nginx.vim
/usr/share/vim/addons/indent
/usr/share/vim/addons/indent/nginx.vim
/usr/share/vim/addons/syntax
/usr/share/vim/addons/syntax/nginx.vim
/usr/share/vim/registry
/usr/share/vim/registry/nginx.yaml
/var
/var/lib
/var/lib/nginx
/var/log
/var/log/nginx
/usr/share/nginx/modules
root@u24043s-vm1:~#

適当に、hello worldを出すように設定してみます。

root@u24043s-vm1:~# echo "Hello, world" | sudo tee /var/www/html/hello.html
Hello, world
root@u24043s-vm1:~#
root@u24043s-vm1:~# vim /etc/nginx/sites-available/hello
root@u24043s-vm1:~#
root@u24043s-vm1:~# cat /etc/nginx/sites-available/hello
server {
    listen 80;
    server_name localhost;

    location / {
        root /var/www/html;
        index hello.html;
    }
}
root@u24043s-vm1:~#
root@u24043s-vm1:~# ln -s /etc/nginx/sites-available/hello /etc/nginx/sites-enabled/
root@u24043s-vm1:~#
root@u24043s-vm1:~# rm /etc/nginx/sites-enabled/default
root@u24043s-vm1:~#
root@u24043s-vm1:~# ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx 1 root root 32 Aug 11 09:47 hello -> /etc/nginx/sites-available/hello
root@u24043s-vm1:~#
root@u24043s-vm1:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@u24043s-vm1:~#
root@u24043s-vm1:~# systemctl restart nginx
root@u24043s-vm1:~#

これで、hello world返します。

root@u24043s-vm1:~# curl http://localhost
Hello, world
root@u24043s-vm1:~#

返すと、access.logにログが出ます。

root@u24043s-vm1:~# ls -l /var/log/nginx/
total 8
-rw-r----- 1 www-data adm 84 Aug 11 09:48 access.log
-rw-r----- 1 www-data adm 76 Aug 11 09:39 error.log
root@u24043s-vm1:~#
root@u24043s-vm1:~# cat /var/log/nginx/access.log
127.0.0.1 - - [11/Aug/2025:09:48:46 +0900] "GET / HTTP/1.1" 200 13 "-" "curl/8.5.0"
root@u24043s-vm1:~#

nginxの設定ファイルを変え、ログの出し方を変えてみます。

root@u24043s-vm1:~# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
root@u24043s-vm1:~#
root@u24043s-vm1:~# vim /etc/nginx/nginx.conf
root@u24043s-vm1:~#
root@u24043s-vm1:~# diff -urN /etc/nginx/nginx.conf.org /etc/nginx/nginx.conf
--- /etc/nginx/nginx.conf.org   2025-08-11 09:52:15.218960034 +0900
+++ /etc/nginx/nginx.conf       2025-08-11 09:54:25.692685189 +0900
@@ -36,8 +36,18 @@
        ##
        # Logging Settings
        ##
+
+       log_format json_format escape=json '{'
+           '"time":"$time_local",'
+           '"remote_addr":"$remote_addr",'
+           '"request":"$request",'
+           '"status":$status,'
+           '"body_bytes_sent":$body_bytes_sent,'
+           '"referer":"$http_referer",'
+           '"user_agent":"$http_user_agent"'
+       '}';

-       access_log /var/log/nginx/access.log;
+       access_log /var/log/nginx/access.log json_format;

        ##
        # Gzip Settings
root@u24043s-vm1:~#
root@u24043s-vm1:~# dpkg -S /etc/nginx/nginx.conf
nginx-common: /etc/nginx/nginx.conf
root@u24043s-vm1:~#
root@u24043s-vm1:~# dpkg -S /etc/nginx/nginx.conf.org
dpkg-query: no path found matching pattern /etc/nginx/nginx.conf.org
root@u24043s-vm1:~#
root@u24043s-vm1:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@u24043s-vm1:~#
root@u24043s-vm1:~# systemctl reload nginx
root@u24043s-vm1:~#

これで、別のフォーマットで、ログが出ました。

root@u24043s-vm1:~# curl http://localhost
Hello, world
root@u24043s-vm1:~# curl http://localhost
Hello, world
root@u24043s-vm1:~# curl http://localhost
Hello, world
root@u24043s-vm1:~#
root@u24043s-vm1:~# cat /var/log/nginx/access.log
127.0.0.1 - - [11/Aug/2025:09:48:46 +0900] "GET / HTTP/1.1" 200 13 "-" "curl/8.5.0"
{"time":"11/Aug/2025:09:55:48 +0900","remote_addr":"127.0.0.1","request":"GET / HTTP/1.1","status":200,"body_bytes_sent":13,"referer":"","user_agent":"curl/8.5.0"}
{"time":"11/Aug/2025:09:56:31 +0900","remote_addr":"127.0.0.1","request":"GET / HTTP/1.1","status":200,"body_bytes_sent":13,"referer":"","user_agent":"curl/8.5.0"}
{"time":"11/Aug/2025:09:56:31 +0900","remote_addr":"127.0.0.1","request":"GET / HTTP/1.1","status":200,"body_bytes_sent":13,"referer":"","user_agent":"curl/8.5.0"}
root@u24043s-vm1:~#

4. パッケージの上書き

書き換えた設定ファイル(/etc/nginx/nginx.conf)は、nginx-commonパッケージのファイルでした。

root@u24043s-vm1:~# dpkg -S /etc/nginx/nginx.conf
nginx-common: /etc/nginx/nginx.conf
root@u24043s-vm1:~#
root@u24043s-vm1:~# dpkg -l | grep -e Version -e nginx
||/ Name                                         Version                                 Architecture Description
ii  nginx                                        1.24.0-2ubuntu7.4                       amd64        small, powerful, scalable web/proxy server
ii  nginx-common                                 1.24.0-2ubuntu7.4                       all          small, powerful, scalable web/proxy server - common files
root@u24043s-vm1:~#

nginx-commonパッケージの上書きを試みてみます。
apt、apt-get、dpkgを試すので、dpkg用にファイルをDLしておきます。

root@u24043s-vm1:~# apt download nginx-common
Get:1 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 nginx-common all 1.24.0-2ubuntu7.4 [43.4 kB]
Fetched 43.4 kB in 1s (30.6 kB/s)
W: Download is performed unsandboxed as root as file '/root/nginx-common_1.24.0-2ubuntu7.4_all.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
root@u24043s-vm1:~#
root@u24043s-vm1:~# apt download nginx
Get:1 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 nginx amd64 1.24.0-2ubuntu7.4 [521 kB]
Fetched 521 kB in 2s (331 kB/s)
W: Download is performed unsandboxed as root as file '/root/nginx_1.24.0-2ubuntu7.4_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
root@u24043s-vm1:~#
root@u24043s-vm1:~# ls -lh
total 7.5M
drwxr-xr-x 2 root root 4.0K Aug 11 09:11 debs
-rw-r--r-- 1 root root 509K Jun 14 00:42 nginx_1.24.0-2ubuntu7.4_amd64.deb
-rw-r--r-- 1 root root  43K Jun 14 00:42 nginx-common_1.24.0-2ubuntu7.4_all.deb
-rw-r--r-- 1 root root 7.0M Aug 10 22:58 Packages
root@u24043s-vm1:~#

以下のように、Aug 11に、/etc/nginx/以下のいくつかのファイルを書き換えています。nginx.confの更新日時は、Aug 11 09:54です。

root@u24043s-vm1:~# ls -lt /etc/nginx/
total 72
-rw-r--r-- 1 root root 1742 Aug 11 09:54 nginx.conf
-rw-r--r-- 1 root root 1446 Aug 11 09:52 nginx.conf.org
drwxr-xr-x 2 root root 4096 Aug 11 09:47 sites-enabled
drwxr-xr-x 2 root root 4096 Aug 11 09:46 sites-available
drwxr-xr-x 2 root root 4096 Aug 11 09:39 snippets
drwxr-xr-x 2 root root 4096 May 27 12:28 conf.d
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-available
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-enabled
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec  1  2023 koi-utf
-rw-r--r-- 1 root root 2223 Dec  1  2023 koi-win
-rw-r--r-- 1 root root 5465 Dec  1  2023 mime.types
-rw-r--r-- 1 root root  180 Dec  1  2023 proxy_params
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
-rw-r--r-- 1 root root  664 Dec  1  2023 uwsgi_params
-rw-r--r-- 1 root root 3071 Dec  1  2023 win-utf
root@u24043s-vm1:~#

(1) apt

まず、apt installすると、確かに、dnfやyum同様、すでに入っている、と表示され上書きされません。

root@u24043s-vm1:~# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nginx is already the newest version (1.24.0-2ubuntu7.4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@u24043s-vm1:~#

ファイルを明示しても、上書きされません。

root@u24043s-vm1:~# apt install ./nginx_1.24.0-2ubuntu7.4_amd64.deb ./nginx-common_1.24.0-2ubuntu7.4_all.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'nginx' instead of './nginx_1.24.0-2ubuntu7.4_amd64.deb'
Note, selecting 'nginx-common' instead of './nginx-common_1.24.0-2ubuntu7.4_all.deb'
nginx is already the newest version (1.24.0-2ubuntu7.4).
nginx-common is already the newest version (1.24.0-2ubuntu7.4).
nginx-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@u24043s-vm1:~#

(2) apt-get

apt-getも、apt同様、上書きされません。

root@u24043s-vm1:~# apt-get install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nginx is already the newest version (1.24.0-2ubuntu7.4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@u24043s-vm1:~#

(3) dpkg

dpkgは、apt、apt-getのように、「nginx is already the newest version」のようなことを言いません。メッセージ的には、無条件に上書きしているように出力します。

root@u24043s-vm1:~# dpkg -i ./nginx_1.24.0-2ubuntu7.4_amd64.deb ./nginx-common_1.24.0-2ubuntu7.4_all.deb
(Reading database ... 95196 files and directories currently installed.)
Preparing to unpack .../nginx_1.24.0-2ubuntu7.4_amd64.deb ...
Unpacking nginx (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Preparing to unpack .../nginx-common_1.24.0-2ubuntu7.4_all.deb ...
Unpacking nginx-common (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Setting up nginx-common (1.24.0-2ubuntu7.4) ...
Setting up nginx (1.24.0-2ubuntu7.4) ...
 * Upgrading binary nginx                                                                                                 [ OK ]
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for ufw (0.36.2-6) ...
root@u24043s-vm1:~#

ただ、Copilotによると、全部が上書きされているわけではないそうです。
・バイナリや共有ファイルは問答無用に上書きされる
 - /usr/sbin/nginxなどの実行ファイル
 - /usr/share/nginx/以下の静的ファイル
 - /usr/share/doc/nginx-commonなどのドキュメント
・設定ファイル(conffile、コンフファイル)はdpkgによって保護される
 - /etc/nginx/nginx.confなどの設定ファイル

設定ファイルを見ると、確かに、nginx.confなどは、上書きされていませんでした(nginx.confの更新日時が、Aug 11 09:54のまま)。

root@u24043s-vm1:~# ls -lt /etc/nginx/
total 72
drwxr-xr-x 2 root root 4096 Aug 11 10:54 snippets
drwxr-xr-x 2 root root 4096 Aug 11 10:54 sites-available
-rw-r--r-- 1 root root 1742 Aug 11 09:54 nginx.conf
-rw-r--r-- 1 root root 1446 Aug 11 09:52 nginx.conf.org
drwxr-xr-x 2 root root 4096 Aug 11 09:47 sites-enabled
drwxr-xr-x 2 root root 4096 May 27 12:28 conf.d
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-available
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-enabled
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec  1  2023 koi-utf
-rw-r--r-- 1 root root 2223 Dec  1  2023 koi-win
-rw-r--r-- 1 root root 5465 Dec  1  2023 mime.types
-rw-r--r-- 1 root root  180 Dec  1  2023 proxy_params
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
-rw-r--r-- 1 root root  664 Dec  1  2023 uwsgi_params
-rw-r--r-- 1 root root 3071 Dec  1  2023 win-utf
root@u24043s-vm1:~#

内容も、書き換えたままでした。

root@u24043s-vm1:~# diff -urN /etc/nginx/nginx.conf.org /etc/nginx/nginx.conf
--- /etc/nginx/nginx.conf.org   2025-08-11 09:52:15.218960034 +0900
+++ /etc/nginx/nginx.conf       2025-08-11 09:54:25.692685189 +0900
@@ -36,8 +36,18 @@
        ##
        # Logging Settings
        ##
+
+       log_format json_format escape=json '{'
+           '"time":"$time_local",'
+           '"remote_addr":"$remote_addr",'
+           '"request":"$request",'
+           '"status":$status,'
+           '"body_bytes_sent":$body_bytes_sent,'
+           '"referer":"$http_referer",'
+           '"user_agent":"$http_user_agent"'
+       '}';

-       access_log /var/log/nginx/access.log;
+       access_log /var/log/nginx/access.log json_format;

        ##
        # Gzip Settings
root@u24043s-vm1:~#

ファイルとしても、nginx-commonに所属したままです。

root@u24043s-vm1:~# dpkg -S /etc/nginx/nginx.conf
nginx-common: /etc/nginx/nginx.conf
root@u24043s-vm1:~#

では、nginx-commonパッケージの一部ファイルを手動で消して、dpkg -iで入れるとどうなるか。パッケージに含まれるファイルをいくつか消してみます。

root@u24043s-vm1:~# rm /usr/share/doc/nginx/copyright
root@u24043s-vm1:~# rm /usr/share/man/man8/nginx.8.gz
root@u24043s-vm1:~# rm /etc/nginx/mime.types
root@u24043s-vm1:~# rm -rf /etc/nginx/snippets
root@u24043s-vm1:~# rm /usr/share/nginx/html/index.html
root@u24043s-vm1:~#
root@u24043s-vm1:~# ls -l /etc/nginx/
total 60
drwxr-xr-x 2 root root 4096 May 27 12:28 conf.d
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec  1  2023 koi-utf
-rw-r--r-- 1 root root 2223 Dec  1  2023 koi-win
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-available
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-enabled
-rw-r--r-- 1 root root 1742 Aug 11 09:54 nginx.conf
-rw-r--r-- 1 root root 1446 Aug 11 09:52 nginx.conf.org
-rw-r--r-- 1 root root  180 Dec  1  2023 proxy_params
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
drwxr-xr-x 2 root root 4096 Aug 11 10:54 sites-available
drwxr-xr-x 2 root root 4096 Aug 11 09:47 sites-enabled
-rw-r--r-- 1 root root  664 Dec  1  2023 uwsgi_params
-rw-r--r-- 1 root root 3071 Dec  1  2023 win-utf
root@u24043s-vm1:~#

これで入れると、エラーが出ました。

root@u24043s-vm1:~# dpkg -i ./nginx_1.24.0-2ubuntu7.4_amd64.deb ./nginx-common_1.24.0-2ubuntu7.4_all.deb
(Reading database ... 95196 files and directories currently installed.)
Preparing to unpack .../nginx_1.24.0-2ubuntu7.4_amd64.deb ...
Unpacking nginx (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Preparing to unpack .../nginx-common_1.24.0-2ubuntu7.4_all.deb ...
Unpacking nginx-common (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Setting up nginx-common (1.24.0-2ubuntu7.4) ...
Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line 148.
Setting up nginx (1.24.0-2ubuntu7.4) ...
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
invoke-rc.d: initscript nginx, action "start" failed.
× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2025-08-11 11:02:22 JST; 10ms ago
   Duration: 8min 21.450s
       Docs: man:nginx(8)
    Process: 8220 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 3ms

Aug 11 11:02:22 u24043s-vm1 systemd[1]: Starting nginx.service - A high performance web server and a reverse proxy server...
Aug 11 11:02:22 u24043s-vm1 nginx[8220]: 2025/08/11 11:02:22 [emerg] 8220#8220: open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:26
Aug 11 11:02:22 u24043s-vm1 nginx[8220]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 11 11:02:22 u24043s-vm1 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Aug 11 11:02:22 u24043s-vm1 systemd[1]: nginx.service: Failed with result 'exit-code'.
Aug 11 11:02:22 u24043s-vm1 systemd[1]: Failed to start nginx.service - A high performance web server and a reverse proxy server.
dpkg: error processing package nginx (--install):
 installed nginx package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for ufw (0.36.2-6) ...
Errors were encountered while processing:
 nginx
root@u24043s-vm1:~#
root@u24043s-vm1:~# echo $?
1
root@u24043s-vm1:~#

エラーの原因は、
・/etc/nginx/mime.typesが、nginx.confでincludeされているため、nginx -tの構文チェックに失敗
・ExecStartPreの処理が失敗したため、nginx.serviceの起動が失敗。
・postinst処理がexit 1で終わり、dpkgがエラー終了
とのこと。

dpkg -iで入れようとしましたが、消した/etc/nginx/mime.typesは追加されなかった、ということです。これは、mime.typesがconffile扱いのため、削除はユーザの意図とみなされ、dpkgはその意思を尊重して再配置しないため、とのこと。

--force-confmissを付けると、欠けている設定ファイルを再配置してくれます。

root@u24043s-vm1:~# dpkg --force-confmiss -i ./nginx_1.24.0-2ubuntu7.4_amd64.deb ./nginx-common_1.24.0-2ubuntu7.4_all.deb
(Reading database ... 95196 files and directories currently installed.)
Preparing to unpack .../nginx_1.24.0-2ubuntu7.4_amd64.deb ...
Unpacking nginx (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Preparing to unpack .../nginx-common_1.24.0-2ubuntu7.4_all.deb ...
Unpacking nginx-common (1.24.0-2ubuntu7.4) over (1.24.0-2ubuntu7.4) ...
Setting up nginx-common (1.24.0-2ubuntu7.4) ...

Configuration file '/etc/nginx/mime.types', does not exist on system.
Installing new config file as you requested.

Configuration file '/etc/nginx/snippets/fastcgi-php.conf', does not exist on system.
Installing new config file as you requested.

Configuration file '/etc/nginx/snippets/snakeoil.conf', does not exist on system.
Installing new config file as you requested.
Setting up nginx (1.24.0-2ubuntu7.4) ...
 * Upgrading binary nginx
                                                                                                                                                      [ OK ]
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for ufw (0.36.2-6) ...
root@u24043s-vm1:~#
root@u24043s-vm1:~# echo $?
0
root@u24043s-vm1:~#

これで、消した各設定ファイルが再配置されています。(Dec 1 2023になっています)


root@u24043s-vm1:~# ls -l /etc/nginx/
total 72
drwxr-xr-x 2 root root 4096 May 27 12:28 conf.d
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec  1  2023 koi-utf
-rw-r--r-- 1 root root 2223 Dec  1  2023 koi-win
-rw-r--r-- 1 root root 5465 Dec  1  2023 mime.types
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-available
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-enabled
-rw-r--r-- 1 root root 1742 Aug 11 09:54 nginx.conf
-rw-r--r-- 1 root root 1446 Aug 11 09:52 nginx.conf.org
-rw-r--r-- 1 root root  180 Dec  1  2023 proxy_params
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
drwxr-xr-x 2 root root 4096 Aug 11 11:05 sites-available
drwxr-xr-x 2 root root 4096 Aug 11 09:47 sites-enabled
drwxr-xr-x 2 root root 4096 Aug 11 11:05 snippets
-rw-r--r-- 1 root root  664 Dec  1  2023 uwsgi_params
-rw-r--r-- 1 root root 3071 Dec  1  2023 win-utf
root@u24043s-vm1:~#

また、nginx.confは、Aug 11 09:54のままなので、設定ファイルを問答無用にパッケージのファイルで上書きする、という動作でもないことが、ここから分かります。(欠けているファイルは再配置。そうじゃないファイルはそのまま)

5. パッケージの削除

削除は、apt removeか、apt purgeです。
・apt removeだと、バイナリや共有ファイルは削除されるが、/etc/nginx/などの設定ファイルは残る。
・apt purgeだと、設定ファイルも削除される。(ただし、手動で編集・作成したファイルがある場合は残る場合もある)

purgeの方で消してみます。

root@u24043s-vm1:~# apt purge nginx nginx-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  nginx* nginx-common*
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 1,596 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 95196 files and directories currently installed.)
Removing nginx (1.24.0-2ubuntu7.4) ...

Removing nginx-common (1.24.0-2ubuntu7.4) ...
Processing triggers for man-db (2.12.0-4build2) ...
(Reading database ... 95171 files and directories currently installed.)
Purging configuration files for nginx-common (1.24.0-2ubuntu7.4) ...
Processing triggers for ufw (0.36.2-6) ...
needrestart is being skipped since dpkg has failed
root@u24043s-vm1:~#

パッケージ消えました。

root@u24043s-vm1:~# dpkg -l | grep -e Version -e nginx
||/ Name                                         Version                                 Architecture Description
root@u24043s-vm1:~#

設定ファイルのある、/etc/nginx/ディレクトリごと、全部消えていました。(nginx.conf.orgは手動作成ファイルだったんですが)

root@u24043s-vm1:~# ls -l /etc/ | grep nginx
root@u24043s-vm1:~#

もう一度入れます。OS上にパッケージがないためか、再配置云々は関係なく、--force-confmissなしでもエラーは出ませんでした。

root@u24043s-vm1:~# dpkg -i ./nginx_1.24.0-2ubuntu7.4_amd64.deb ./nginx-common_1.24.0-2ubuntu7.4_all.deb
Selecting previously unselected package nginx.
(Reading database ... 95148 files and directories currently installed.)
Preparing to unpack .../nginx_1.24.0-2ubuntu7.4_amd64.deb ...
Unpacking nginx (1.24.0-2ubuntu7.4) ...
Selecting previously unselected package nginx-common.
Preparing to unpack .../nginx-common_1.24.0-2ubuntu7.4_all.deb ...
Unpacking nginx-common (1.24.0-2ubuntu7.4) ...
Setting up nginx-common (1.24.0-2ubuntu7.4) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Setting up nginx (1.24.0-2ubuntu7.4) ...
 * Upgrading binary nginx                                                                                                 [ OK ]
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for ufw (0.36.2-6) ...
root@u24043s-vm1:~#
root@u24043s-vm1:~# dpkg -l | grep -e Version -e nginx
||/ Name                                         Version                                 Architecture Description
ii  nginx                                        1.24.0-2ubuntu7.4                       amd64        small, powerful, scalable web/proxy server
ii  nginx-common                                 1.24.0-2ubuntu7.4                       all          small, powerful, scalable web/proxy server - common files
root@u24043s-vm1:~#

設定ファイルも、再度、パッケージのものが置かれています。

root@u24043s-vm1:~# ls -l /etc/nginx/
total 68
drwxr-xr-x 2 root root 4096 May 27 12:28 conf.d
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec  1  2023 koi-utf
-rw-r--r-- 1 root root 2223 Dec  1  2023 koi-win
-rw-r--r-- 1 root root 5465 Dec  1  2023 mime.types
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-available
drwxr-xr-x 2 root root 4096 May 27 12:28 modules-enabled
-rw-r--r-- 1 root root 1446 Dec  1  2023 nginx.conf
-rw-r--r-- 1 root root  180 Dec  1  2023 proxy_params
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
drwxr-xr-x 2 root root 4096 Aug 11 18:47 sites-available
drwxr-xr-x 2 root root 4096 Aug 11 18:47 sites-enabled
drwxr-xr-x 2 root root 4096 Aug 11 18:47 snippets
-rw-r--r-- 1 root root  664 Dec  1  2023 uwsgi_params
-rw-r--r-- 1 root root 3071 Dec  1  2023 win-utf
root@u24043s-vm1:~#

6. ソースコードの入手

ソースコードを得るには、sources.list設定の、「Types: deb」を、「Types: deb deb-src」のように変えます。

root@u24043s-vm1:~# vim /etc/apt/sources.list.d/ubuntu.sources
root@u24043s-vm1:~#
root@u24043s-vm1:~# cat /etc/apt/sources.list.d/ubuntu.sources
Types: deb deb-src
URIs: http://jp.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb deb-src
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
root@u24043s-vm1:~#

変更を反映します。

root@u24043s-vm1:~# apt update
Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Hit:2 http://ddebs.ubuntu.com noble InRelease
Hit:3 http://jp.archive.ubuntu.com/ubuntu noble InRelease
Get:4 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Hit:5 http://ddebs.ubuntu.com noble-updates InRelease
Hit:6 http://ddebs.ubuntu.com noble-proposed InRelease
Get:7 http://security.ubuntu.com/ubuntu noble-security/restricted Sources [45.6 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:9 http://jp.archive.ubuntu.com/ubuntu noble/multiverse Sources [299 kB]
Get:10 http://security.ubuntu.com/ubuntu noble-security/universe Sources [320 kB]
Get:11 http://jp.archive.ubuntu.com/ubuntu noble/main Sources [1,384 kB]
Get:12 http://security.ubuntu.com/ubuntu noble-security/main Sources [195 kB]
Get:13 http://security.ubuntu.com/ubuntu noble-security/multiverse Sources [10.2 kB]
Get:14 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [21.6 kB]
Get:15 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Components [212 B]
Get:16 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [52.2 kB]
Get:17 http://jp.archive.ubuntu.com/ubuntu noble/universe Sources [19.8 MB]
Get:18 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [212 B]
Get:19 http://jp.archive.ubuntu.com/ubuntu noble/restricted Sources [18.7 kB]
Get:20 http://jp.archive.ubuntu.com/ubuntu noble-updates/main Sources [439 kB]
Get:21 http://jp.archive.ubuntu.com/ubuntu noble-updates/multiverse Sources [20.9 kB]
Get:22 http://jp.archive.ubuntu.com/ubuntu noble-updates/universe Sources [454 kB]
Get:23 http://jp.archive.ubuntu.com/ubuntu noble-updates/restricted Sources [48.9 kB]
Get:24 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [163 kB]
Get:25 http://jp.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Get:26 http://jp.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [377 kB]
Get:27 http://jp.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Get:28 http://jp.archive.ubuntu.com/ubuntu noble-backports/main Sources [5,932 B]
Get:29 http://jp.archive.ubuntu.com/ubuntu noble-backports/universe Sources [12.0 kB]
Get:30 http://jp.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [7,076 B]
Get:31 http://jp.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [216 B]
Get:32 http://jp.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [30.8 kB]
Get:33 http://jp.archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B]
Fetched 24.1 MB in 6s (3,784 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@u24043s-vm1:~#

また、ソースファイルを扱うためのツールを入れます。

root@u24043s-vm1:~# apt install dpkg-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  build-essential bzip2 cpp cpp-13 cpp-13-x86-64-linux-gnu cpp-x86-64-linux-gnu fakeroot g++ g++-13 g++-13-x86-64-linux-gnu
  g++-x86-64-linux-gnu gcc gcc-13 gcc-13-base gcc-13-x86-64-linux-gnu gcc-x86-64-linux-gnu libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan8 libatomic1 libcc1-0 libdpkg-perl libfakeroot
  libfile-fcntllock-perl libgcc-13-dev libgomp1 libhwasan0 libisl23 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-13-dev
  libtsan2 libubsan1 lto-disabled-list make
Suggested packages:
  bzip2-doc cpp-doc gcc-13-locales cpp-13-doc debian-keyring g++-multilib g++-13-multilib gcc-13-doc gcc-multilib autoconf
  automake libtool flex bison gdb gcc-doc gcc-13-multilib gdb-x86-64-linux-gnu bzr libstdc++-13-doc make-doc
The following NEW packages will be installed:
  build-essential bzip2 cpp cpp-13 cpp-13-x86-64-linux-gnu cpp-x86-64-linux-gnu dpkg-dev fakeroot g++ g++-13
  g++-13-x86-64-linux-gnu g++-x86-64-linux-gnu gcc gcc-13 gcc-13-base gcc-13-x86-64-linux-gnu gcc-x86-64-linux-gnu
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan8 libatomic1 libcc1-0 libdpkg-perl
  libfakeroot libfile-fcntllock-perl libgcc-13-dev libgomp1 libhwasan0 libisl23 libitm1 liblsan0 libmpc3 libquadmath0
  libstdc++-13-dev libtsan2 libubsan1 lto-disabled-list make
0 upgraded, 39 newly installed, 0 to remove and 0 not upgraded.
Need to get 62.5 MB of archives.
After this operation, 209 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 gcc-13-base amd64 13.3.0-6ubuntu2~24.04 [51.5 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libisl23 amd64 0.26-3build1.1 [680 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libmpc3 amd64 1.3.1-1build1.1 [54.6 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 cpp-13-x86-64-linux-gnu amd64 13.3.0-6ubuntu2~24.04 [10.7 MB]
Get:5 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 cpp-13 amd64 13.3.0-6ubuntu2~24.04 [1,038 B]
Get:6 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 cpp-x86-64-linux-gnu amd64 4:13.2.0-7ubuntu1 [5,326 B]
Get:7 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 cpp amd64 4:13.2.0-7ubuntu1 [22.4 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libcc1-0 amd64 14.2.0-4ubuntu2~24.04 [48.0 kB]
Get:9 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libgomp1 amd64 14.2.0-4ubuntu2~24.04 [148 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libitm1 amd64 14.2.0-4ubuntu2~24.04 [29.7 kB]
Get:11 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libatomic1 amd64 14.2.0-4ubuntu2~24.04 [10.5 kB]
Get:12 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libasan8 amd64 14.2.0-4ubuntu2~24.04 [3,031 kB]
Get:13 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 liblsan0 amd64 14.2.0-4ubuntu2~24.04 [1,322 kB]
Get:14 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libtsan2 amd64 14.2.0-4ubuntu2~24.04 [2,772 kB]
Get:15 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libubsan1 amd64 14.2.0-4ubuntu2~24.04 [1,184 kB]
Get:16 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libhwasan0 amd64 14.2.0-4ubuntu2~24.04 [1,641 kB]
Get:17 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libquadmath0 amd64 14.2.0-4ubuntu2~24.04 [153 kB]
Get:18 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libgcc-13-dev amd64 13.3.0-6ubuntu2~24.04 [2,681 kB]
Get:19 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 gcc-13-x86-64-linux-gnu amd64 13.3.0-6ubuntu2~24.04 [21.1 MB]
Get:20 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 gcc-13 amd64 13.3.0-6ubuntu2~24.04 [494 kB]
Get:21 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 gcc-x86-64-linux-gnu amd64 4:13.2.0-7ubuntu1 [1,212 B]
Get:22 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 gcc amd64 4:13.2.0-7ubuntu1 [5,018 B]
Get:23 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libstdc++-13-dev amd64 13.3.0-6ubuntu2~24.04 [2,420 kB]
Get:24 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 g++-13-x86-64-linux-gnu amd64 13.3.0-6ubuntu2~24.04 [12.2 MB]
Get:25 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 g++-13 amd64 13.3.0-6ubuntu2~24.04 [16.1 kB]
Get:26 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 g++-x86-64-linux-gnu amd64 4:13.2.0-7ubuntu1 [964 B]
Get:27 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 g++ amd64 4:13.2.0-7ubuntu1 [1,100 B]
Get:28 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 make amd64 4.3-4.1build2 [180 kB]
Get:29 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 libdpkg-perl all 1.22.6ubuntu6.1 [269 kB]
Get:30 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 bzip2 amd64 1.0.8-5.1build0.1 [34.5 kB]
Get:31 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 lto-disabled-list all 47 [12.4 kB]
Get:32 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 dpkg-dev all 1.22.6ubuntu6.1 [1,074 kB]
Get:33 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 build-essential amd64 12.10ubuntu1 [4,928 B]
Get:34 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libfakeroot amd64 1.33-1 [32.4 kB]
Get:35 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 fakeroot amd64 1.33-1 [67.2 kB]
Get:36 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libalgorithm-diff-perl all 1.201-1 [41.8 kB]
Get:37 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libalgorithm-diff-xs-perl amd64 0.04-8build3 [11.2 kB]
Get:38 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libalgorithm-merge-perl all 0.08-5 [11.4 kB]
Get:39 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libfile-fcntllock-perl amd64 0.22-4ubuntu5 [30.7 kB]
Fetched 62.5 MB in 8s (7,943 kB/s)
Extracting templates from packages: 100%
Selecting previously unselected package gcc-13-base:amd64.
(Reading database ... 95196 files and directories currently installed.)
Preparing to unpack .../00-gcc-13-base_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking gcc-13-base:amd64 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package libisl23:amd64.
Preparing to unpack .../01-libisl23_0.26-3build1.1_amd64.deb ...
Unpacking libisl23:amd64 (0.26-3build1.1) ...
Selecting previously unselected package libmpc3:amd64.
Preparing to unpack .../02-libmpc3_1.3.1-1build1.1_amd64.deb ...
Unpacking libmpc3:amd64 (1.3.1-1build1.1) ...
Selecting previously unselected package cpp-13-x86-64-linux-gnu.
Preparing to unpack .../03-cpp-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking cpp-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package cpp-13.
Preparing to unpack .../04-cpp-13_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking cpp-13 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package cpp-x86-64-linux-gnu.
Preparing to unpack .../05-cpp-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking cpp-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package cpp.
Preparing to unpack .../06-cpp_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking cpp (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package libcc1-0:amd64.
Preparing to unpack .../07-libcc1-0_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libcc1-0:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libgomp1:amd64.
Preparing to unpack .../08-libgomp1_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libgomp1:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libitm1:amd64.
Preparing to unpack .../09-libitm1_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libitm1:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libatomic1:amd64.
Preparing to unpack .../10-libatomic1_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libatomic1:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libasan8:amd64.
Preparing to unpack .../11-libasan8_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libasan8:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package liblsan0:amd64.
Preparing to unpack .../12-liblsan0_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking liblsan0:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libtsan2:amd64.
Preparing to unpack .../13-libtsan2_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libtsan2:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libubsan1:amd64.
Preparing to unpack .../14-libubsan1_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libubsan1:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libhwasan0:amd64.
Preparing to unpack .../15-libhwasan0_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libhwasan0:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libquadmath0:amd64.
Preparing to unpack .../16-libquadmath0_14.2.0-4ubuntu2~24.04_amd64.deb ...
Unpacking libquadmath0:amd64 (14.2.0-4ubuntu2~24.04) ...
Selecting previously unselected package libgcc-13-dev:amd64.
Preparing to unpack .../17-libgcc-13-dev_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking libgcc-13-dev:amd64 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package gcc-13-x86-64-linux-gnu.
Preparing to unpack .../18-gcc-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking gcc-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package gcc-13.
Preparing to unpack .../19-gcc-13_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking gcc-13 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package gcc-x86-64-linux-gnu.
Preparing to unpack .../20-gcc-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking gcc-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package gcc.
Preparing to unpack .../21-gcc_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking gcc (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package libstdc++-13-dev:amd64.
Preparing to unpack .../22-libstdc++-13-dev_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking libstdc++-13-dev:amd64 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package g++-13-x86-64-linux-gnu.
Preparing to unpack .../23-g++-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking g++-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package g++-13.
Preparing to unpack .../24-g++-13_13.3.0-6ubuntu2~24.04_amd64.deb ...
Unpacking g++-13 (13.3.0-6ubuntu2~24.04) ...
Selecting previously unselected package g++-x86-64-linux-gnu.
Preparing to unpack .../25-g++-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking g++-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package g++.
Preparing to unpack .../26-g++_4%3a13.2.0-7ubuntu1_amd64.deb ...
Unpacking g++ (4:13.2.0-7ubuntu1) ...
Selecting previously unselected package make.
Preparing to unpack .../27-make_4.3-4.1build2_amd64.deb ...
Unpacking make (4.3-4.1build2) ...
Selecting previously unselected package libdpkg-perl.
Preparing to unpack .../28-libdpkg-perl_1.22.6ubuntu6.1_all.deb ...
Unpacking libdpkg-perl (1.22.6ubuntu6.1) ...
Selecting previously unselected package bzip2.
Preparing to unpack .../29-bzip2_1.0.8-5.1build0.1_amd64.deb ...
Unpacking bzip2 (1.0.8-5.1build0.1) ...
Selecting previously unselected package lto-disabled-list.
Preparing to unpack .../30-lto-disabled-list_47_all.deb ...
Unpacking lto-disabled-list (47) ...
Selecting previously unselected package dpkg-dev.
Preparing to unpack .../31-dpkg-dev_1.22.6ubuntu6.1_all.deb ...
Unpacking dpkg-dev (1.22.6ubuntu6.1) ...
Selecting previously unselected package build-essential.
Preparing to unpack .../32-build-essential_12.10ubuntu1_amd64.deb ...
Unpacking build-essential (12.10ubuntu1) ...
Selecting previously unselected package libfakeroot:amd64.
Preparing to unpack .../33-libfakeroot_1.33-1_amd64.deb ...
Unpacking libfakeroot:amd64 (1.33-1) ...
Selecting previously unselected package fakeroot.
Preparing to unpack .../34-fakeroot_1.33-1_amd64.deb ...
Unpacking fakeroot (1.33-1) ...
Selecting previously unselected package libalgorithm-diff-perl.
Preparing to unpack .../35-libalgorithm-diff-perl_1.201-1_all.deb ...
Unpacking libalgorithm-diff-perl (1.201-1) ...
Selecting previously unselected package libalgorithm-diff-xs-perl:amd64.
Preparing to unpack .../36-libalgorithm-diff-xs-perl_0.04-8build3_amd64.deb ...
Unpacking libalgorithm-diff-xs-perl:amd64 (0.04-8build3) ...
Selecting previously unselected package libalgorithm-merge-perl.
Preparing to unpack .../37-libalgorithm-merge-perl_0.08-5_all.deb ...
Unpacking libalgorithm-merge-perl (0.08-5) ...
Selecting previously unselected package libfile-fcntllock-perl.
Preparing to unpack .../38-libfile-fcntllock-perl_0.22-4ubuntu5_amd64.deb ...
Unpacking libfile-fcntllock-perl (0.22-4ubuntu5) ...
Setting up lto-disabled-list (47) ...
Setting up libfile-fcntllock-perl (0.22-4ubuntu5) ...
Setting up libalgorithm-diff-perl (1.201-1) ...
Setting up libgomp1:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up bzip2 (1.0.8-5.1build0.1) ...
Setting up libfakeroot:amd64 (1.33-1) ...
Setting up fakeroot (1.33-1) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode
Setting up gcc-13-base:amd64 (13.3.0-6ubuntu2~24.04) ...
Setting up make (4.3-4.1build2) ...
Setting up libquadmath0:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libmpc3:amd64 (1.3.1-1build1.1) ...
Setting up libatomic1:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libdpkg-perl (1.22.6ubuntu6.1) ...
Setting up libubsan1:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libhwasan0:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libasan8:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libtsan2:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libisl23:amd64 (0.26-3build1.1) ...
Setting up libalgorithm-diff-xs-perl:amd64 (0.04-8build3) ...
Setting up libcc1-0:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up liblsan0:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libitm1:amd64 (14.2.0-4ubuntu2~24.04) ...
Setting up libalgorithm-merge-perl (0.08-5) ...
Setting up cpp-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Setting up dpkg-dev (1.22.6ubuntu6.1) ...
Setting up libgcc-13-dev:amd64 (13.3.0-6ubuntu2~24.04) ...
Setting up libstdc++-13-dev:amd64 (13.3.0-6ubuntu2~24.04) ...
Setting up cpp-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Setting up cpp-13 (13.3.0-6ubuntu2~24.04) ...
Setting up gcc-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Setting up gcc-13 (13.3.0-6ubuntu2~24.04) ...
Setting up cpp (4:13.2.0-7ubuntu1) ...
Setting up g++-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Setting up gcc-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Setting up gcc (4:13.2.0-7ubuntu1) ...
Setting up g++-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Setting up g++-13 (13.3.0-6ubuntu2~24.04) ...
Setting up g++ (4:13.2.0-7ubuntu1) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (12.10ubuntu1) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.5) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@u24043s-vm1:~#

これで、入手できます。

root@u24043s-vm1:~# mkdir src
root@u24043s-vm1:~#
root@u24043s-vm1:~# cd src
root@u24043s-vm1:~/src#
root@u24043s-vm1:~/src# apt source nginx
Reading package lists... Done
NOTICE: 'nginx' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/nginx-team/nginx.git
Please use:
git clone https://salsa.debian.org/nginx-team/nginx.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 1,200 kB of source archives.
Get:1 http://jp.archive.ubuntu.com/ubuntu noble-updates/main nginx 1.24.0-2ubuntu7.4 (dsc) [3,617 B]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble-updates/main nginx 1.24.0-2ubuntu7.4 (tar) [1,112 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu noble-updates/main nginx 1.24.0-2ubuntu7.4 (diff) [83.8 kB]
Fetched 1,200 kB in 2s (595 kB/s)
dpkg-source: info: extracting nginx in nginx-1.24.0
dpkg-source: info: unpacking nginx_1.24.0.orig.tar.gz
dpkg-source: info: unpacking nginx_1.24.0-2ubuntu7.4.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying 0003-define_gnu_source-on-other-glibc-based-platforms.patch
dpkg-source: info: applying nginx-fix-pidfile.patch
dpkg-source: info: applying nginx-ssl_cert_cb_yield.patch
dpkg-source: info: applying CVE-2023-44487.patch
dpkg-source: info: applying ubuntu-branding.patch
dpkg-source: info: applying CVE-2024-7347-1.patch
dpkg-source: info: applying CVE-2024-7347-2.patch
dpkg-source: info: applying CVE-2025-23419.patch
W: Download is performed unsandboxed as root as file 'nginx_1.24.0-2ubuntu7.4.dsc' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
root@u24043s-vm1:~/src#

debやddebといった拡張子の、まとまったファイルはありません。3つのファイル(debian.tar.xz、dsc、orig.tar.gz)と、展開されたディレクトリが作られます。

root@u24043s-vm1:~/src# ls -lh
total 1.2M
drwxr-xr-x 10 root root 4.0K Aug 12 10:05 nginx-1.24.0
-rw-r--r--  1 root root  82K Jun 14 00:41 nginx_1.24.0-2ubuntu7.4.debian.tar.xz
-rw-r--r--  1 root root 3.6K Jun 14 00:41 nginx_1.24.0-2ubuntu7.4.dsc
-rw-r--r--  1 root root 1.1M Jun 28  2023 nginx_1.24.0.orig.tar.gz
root@u24043s-vm1:~/src#

展開されたディレクトリには、ソースファイルがあります。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/468232/4af1d025-19a0-491a-a64e-4a8845fa2beb.png)
root@u24043s-vm1:~/src# find ./nginx-1.24.0/ -name *.c | wc -l
237
root@u24043s-vm1:~/src#
root@u24043s-vm1:~/src# find ./nginx-1.24.0/ -name *.c | head -n3
./nginx-1.24.0/.pc/nginx-ssl_cert_cb_yield.patch/src/event/ngx_event_openssl.c
./nginx-1.24.0/.pc/CVE-2023-44487.patch/src/http/v2/ngx_http_v2.c
./nginx-1.24.0/.pc/CVE-2024-7347-2.patch/src/http/modules/ngx_http_mp4_module.c
root@u24043s-vm1:~/src#
root@u24043s-vm1:~/src# find ./nginx-1.24.0/ -name *.c | tail -n3
./nginx-1.24.0/src/core/ngx_proxy_protocol.c
./nginx-1.24.0/src/core/ngx_rbtree.c
./nginx-1.24.0/src/core/ngx_log.c
root@u24043s-vm1:~/src#

7. ソースコードのビルド

入手したソースコードをビルドし、debパッケージを自作します。
まず、ビルドに必要なパッケージを入れます。ここでは、190+65パッケージ入りました。

root@u24043s-vm1:~/src# apt install build-essential devscripts fakeroot dh-autoreconf
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.10ubuntu1).
build-essential set to manually installed.
fakeroot is already the newest version (1.33-1).
fakeroot set to manually installed.
The following additional packages will be installed:
  autoconf automake autopoint autotools-dev dctrl-tools diffstat dput gettext intltool-debian libaliased-perl
  libarchive-zip-perl libarray-intspan-perl libauthen-sasl-perl libb-hooks-endofscope-perl libb-hooks-op-check-perl
~
0 upgraded, 190 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.9 MB of archives.
After this operation, 46.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 m4 amd64 1.4.19-4build1 [244 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 autoconf all 2.71-3 [339 kB]
~
Processing triggers for man-db (2.12.0-4build2) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@u24043s-vm1:~/src#
root@u24043s-vm1:~/src# apt build-dep .
Note, using directory '.' to get the build dependencies
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  debhelper debugedit dh-strip-nondeterminism dwz geoip-bin icu-devtools libaom-dev libbrotli-dev libbz2-dev libdav1d-dev
  libdav1d7 libde265-dev libdeflate-dev libexpat1-dev libfile-stripnondeterminism-perl libfontconfig-dev libfreetype-dev
~
0 upgraded, 65 newly installed, 0 to remove and 0 not upgraded.
Need to get 33.6 MB of archives.
After this operation, 159 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libsub-override-perl all 0.10-1 [10.0 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libfile-stripnondeterminism-perl all 1.13.1-1 [18.1 kB]
~
Setting up libgd-dev:amd64 (2.3.3-9ubuntu5) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@u24043s-vm1:~/src#

展開されたディレクトリ(nginx-1.24.0/)に移動し、dchコマンドを実行して、changelogを更新します。

root@u24043s-vm1:~/src# ls
nginx-1.24.0  nginx_1.24.0-2ubuntu7.4.debian.tar.xz  nginx_1.24.0-2ubuntu7.4.dsc  nginx_1.24.0.orig.tar.gz
root@u24043s-vm1:~/src#
root@u24043s-vm1:~/src# cd nginx-1.24.0/
root@u24043s-vm1:~/src/nginx-1.24.0#
root@u24043s-vm1:~/src/nginx-1.24.0# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  debian  html  LICENSE  man  README  src
root@u24043s-vm1:~/src/nginx-1.24.0#
root@u24043s-vm1:~/src/nginx-1.24.0# dch -i
dch warning: neither DEBEMAIL nor EMAIL environment variable is set
dch warning: building email address from username and FQDN
dch: Did you see those 2 warnings?  Press RETURN to continue...

Enterキーを押すと、エディタが開かれます。「nginx (1.24.0~」ごとに1つのchangelogが書かれています。

nginx (1.24.0-2ubuntu7.5) UNRELEASED; urgency=medium

  *

 -- root <root@u24043s-vm1>  Tue, 12 Aug 2025 10:19:11 +0900

nginx (1.24.0-2ubuntu7.4) noble; urgency=medium

  [ Thomas Ward ]
  * d/control: Resolve dependency loop between nginx and nginx-common.
  * d/nginx-common.nginx.service: Add ConditionFileIsExecutable to
    SystemD service file, prevents starting of service if nginx is
    not installed (which can happen if nginx-common is installed
    independently from `nginx` itself (LP: #2081308)

 -- Matthew Ruffell <matthew.ruffell@canonical.com>  Tue, 27 May 2025 15:28:18 +1200

nginx (1.24.0-2ubuntu7.3) noble-security; urgency=medium

  * SECURITY UPDATE: Session resumption
    - debian/patches/CVE-2025-23419.patch: added restriction for TLSv1.3
      cross-SNI session resumption in files src/http/ngx_http_request.c.
    - CVE-2025-23419

 -- Leonidas Da Silva Barbosa <leo.barbosa@canonical.com>  Mon, 31 Mar 2025 15:38:37 -0300

nginx (1.24.0-2ubuntu7.1) noble-security; urgency=medium

このように、デバッグ用ビルドであることが分かるようchangelogを書きました。

nginx (1.24.0-2ubuntu7.4+debug1) UNRELEASED; urgency=medium

  * debug1.

 -- root <root@u24043s-vm1>  Tue, 12 Aug 2025 10:19:11 +0900

nginx (1.24.0-2ubuntu7.4) noble; urgency=medium

  [ Thomas Ward ]
  * d/control: Resolve dependency loop between nginx and nginx-common.

デフォルトの記載候補は「nginx (1.24.0-2ubuntu7.5)」ですが、7.5というのは公式が将来的に使う可能性があり、勝手に使うのは良くないということで、次のようなルールで付けると良い、とのこと。
・+debugNを付加:デバッグ目的のビルドであることを明示
・+localNを付加:ローカルビルドであることを示し、公式より低い優先度
・+rebuildNを付加:再ビルドであることを明示(再現性テストなど)
・+testNを付加:テスト目的のビルドであることを明示

書き換えたら、保存(:wq)します。

root@u24043s-vm1:~/src/nginx-1.24.0# dch -i
dch warning: neither DEBEMAIL nor EMAIL environment variable is set
dch warning: building email address from username and FQDN
dch: Did you see those 2 warnings?  Press RETURN to continue...

root@u24043s-vm1:~/src/nginx-1.24.0#

changelogは、以下のファイルに記録されます。

root@u24043s-vm1:~/src/nginx-1.24.0# head debian/changelog
nginx (1.24.0-2ubuntu7.4+debug1) UNRELEASED; urgency=medium

  * debug1.

 -- root <root@u24043s-vm1>  Tue, 12 Aug 2025 10:19:11 +0900

nginx (1.24.0-2ubuntu7.4) noble; urgency=medium

  [ Thomas Ward ]
  * d/control: Resolve dependency loop between nginx and nginx-common.
root@u24043s-vm1:~/src/nginx-1.24.0#

ビルドします。

root@u24043s-vm1:~/src/nginx-1.24.0# debuild -us -uc
 dpkg-buildpackage -us -uc -ui
dpkg-buildpackage: info: source package nginx
dpkg-buildpackage: info: source version 1.24.0-2ubuntu7.4+debug1
dpkg-buildpackage: info: source distribution UNRELEASED
dpkg-buildpackage: info: source changed by root <root@u24043s-vm1>
 dpkg-source --before-build .
dpkg-buildpackage: info: host architecture amd64
 debian/rules clean
dh clean --without autoreconf
~
dpkg-deb: building package 'libnginx-mod-http-image-filter' in '../libnginx-mod-http-image-filter_1.24.0-2ubuntu7.4+debug1_amd64.deb'.
 dpkg-genbuildinfo -O../nginx_1.24.0-2ubuntu7.4+debug1_amd64.buildinfo
 dpkg-genchanges -O../nginx_1.24.0-2ubuntu7.4+debug1_amd64.changes
dpkg-genchanges: info: not including original source code in upload
 dpkg-source --after-build .
dpkg-buildpackage: info: binary and diff upload (original source NOT included)
Now running lintian nginx_1.24.0-2ubuntu7.4+debug1_amd64.changes ...
running with root privileges is not recommended!
E: nginx changes: bogus-mail-host Changed-By root@u24043s-vm1
E: libnginx-mod-http-geoip: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-http-geoip/changelog.Debian.gz:1]
E: libnginx-mod-http-image-filter: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-http-image-filter/changelog.Debian.gz:1]
E: libnginx-mod-http-perl: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-http-perl/changelog.Debian.gz:1]
E: libnginx-mod-http-xslt-filter: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-http-xslt-filter/changelog.Debian.gz:1]
E: libnginx-mod-mail: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-mail/changelog.Debian.gz:1]
E: libnginx-mod-stream: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-stream/changelog.Debian.gz:1]
E: libnginx-mod-stream-geoip: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/libnginx-mod-stream-geoip/changelog.Debian.gz:1]
E: nginx: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx/changelog.Debian.gz:1]
E: nginx-common: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-common/changelog.Debian.gz:1]
E: nginx-core: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-core/changelog.Debian.gz:1]
E: nginx-dev: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-dev/changelog.Debian.gz:1]
E: nginx-doc: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-doc/changelog.Debian.gz:1]
E: nginx-extras: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-extras/changelog.Debian.gz:1]
E: nginx-full: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-full/changelog.Debian.gz:1]
E: nginx-light: bogus-mail-host-in-debian-changelog root@u24043s-vm1 (for version 1.24.0-2ubuntu7.4+debug1) [usr/share/doc/nginx-light/changelog.Debian.gz:1]
E: nginx changes: root-in-contact Changed-By root <root@u24043s-vm1>
W: nginx source: orig-tarball-missing-upstream-signature nginx_1.24.0.orig.tar.gz
Finished running lintian.
root@u24043s-vm1:~/src/nginx-1.24.0#

エラーが出ていますが、返値は0です。

root@u24043s-vm1:~/src/nginx-1.24.0# echo $?
0
root@u24043s-vm1:~/src/nginx-1.24.0#

親ディレクトリに、パッケージができています。

root@u24043s-vm1:~/src/nginx-1.24.0# ls -lh ..
total 4.5M
-rw-r--r--  1 root root  22K Aug 12 10:32 libnginx-mod-http-geoip_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  36K Aug 12 10:32 libnginx-mod-http-geoip-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  26K Aug 12 10:32 libnginx-mod-http-image-filter_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  43K Aug 12 10:32 libnginx-mod-http-image-filter-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  34K Aug 12 10:32 libnginx-mod-http-perl_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root 106K Aug 12 10:32 libnginx-mod-http-perl-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  25K Aug 12 10:32 libnginx-mod-http-xslt-filter_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  53K Aug 12 10:32 libnginx-mod-http-xslt-filter-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  57K Aug 12 10:32 libnginx-mod-mail_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root 104K Aug 12 10:32 libnginx-mod-mail-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  83K Aug 12 10:32 libnginx-mod-stream_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root 171K Aug 12 10:32 libnginx-mod-stream-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root  21K Aug 12 10:32 libnginx-mod-stream-geoip_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  22K Aug 12 10:32 libnginx-mod-stream-geoip-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
drwxr-xr-x 10 root root 4.0K Aug 12 10:05 nginx-1.24.0
-rw-r--r--  1 root root  82K Jun 14 00:41 nginx_1.24.0-2ubuntu7.4.debian.tar.xz
-rw-r--r--  1 root root 354K Aug 12 10:33 nginx_1.24.0-2ubuntu7.4+debug1_amd64.build
-rw-r--r--  1 root root  17K Aug 12 10:32 nginx_1.24.0-2ubuntu7.4+debug1_amd64.buildinfo
-rw-r--r--  1 root root  11K Aug 12 10:32 nginx_1.24.0-2ubuntu7.4+debug1_amd64.changes
-rw-r--r--  1 root root 509K Aug 12 10:32 nginx_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  82K Aug 12 10:31 nginx_1.24.0-2ubuntu7.4+debug1.debian.tar.xz
-rw-r--r--  1 root root 2.7K Aug 12 10:31 nginx_1.24.0-2ubuntu7.4+debug1.dsc
-rw-r--r--  1 root root 3.6K Jun 14 00:41 nginx_1.24.0-2ubuntu7.4.dsc
-rw-r--r--  1 root root 1.1M Jun 28  2023 nginx_1.24.0.orig.tar.gz
-rw-r--r--  1 root root  43K Aug 12 10:32 nginx-common_1.24.0-2ubuntu7.4+debug1_all.deb
-rw-r--r--  1 root root  17K Aug 12 10:32 nginx-core_1.24.0-2ubuntu7.4+debug1_all.deb
-rw-r--r--  1 root root 1.3M Aug 12 10:32 nginx-dbgsym_1.24.0-2ubuntu7.4+debug1_amd64.ddeb
-rw-r--r--  1 root root 120K Aug 12 10:32 nginx-dev_1.24.0-2ubuntu7.4+debug1_all.deb
-rw-r--r--  1 root root  25K Aug 12 10:32 nginx-doc_1.24.0-2ubuntu7.4+debug1_all.deb
-rw-r--r--  1 root root  17K Aug 12 10:32 nginx-extras_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  17K Aug 12 10:32 nginx-full_1.24.0-2ubuntu7.4+debug1_all.deb
-rw-r--r--  1 root root  17K Aug 12 10:32 nginx-light_1.24.0-2ubuntu7.4+debug1_all.deb
root@u24043s-vm1:~/src/nginx-1.24.0#

+debug1の、nginx、nginx-commonがあります。

-rw-r--r--  1 root root 509K Aug 12 10:32 nginx_1.24.0-2ubuntu7.4+debug1_amd64.deb
-rw-r--r--  1 root root  43K Aug 12 10:32 nginx-common_1.24.0-2ubuntu7.4+debug1_all.deb

+debug1の、ソースコードのファイルがあります。

-rw-r--r--  1 root root  82K Aug 12 10:31 nginx_1.24.0-2ubuntu7.4+debug1.debian.tar.xz
-rw-r--r--  1 root root 2.7K Aug 12 10:31 nginx_1.24.0-2ubuntu7.4+debug1.dsc
-rw-r--r--  1 root root 1.1M Jun 28  2023 nginx_1.24.0.orig.tar.gz

debian.tar.xzとdscファイルは、+debug1がありますが、orig.tar.gzはないです(そもそも、バージョン体系が違う)。

これは、orig.tar.gzをベースとし、そこからの変更を、残り2ファイルで管理する、ということをしているからかと思います。

まとめ

Ubuntuのパッケージの使い方について、確認しました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?