APT によるパッケージの更新方法
Ubuntu のパッケージ管理には APT を使います。サーバーを最新の状態に保つ手順と、更新対象の確認、不要になったパッケージの削除、パッケージ情報の調べ方までを解説します。
コマンドには apt と apt-get の2種類があります。対話的な操作には apt、スクリプトの中では出力の形式が変わらない apt-get を使うのが基本です。
kazulog@sv2:~$ apt --version
apt 3.2.0 (amd64)
kazulog@sv2:~$パッケージリストの更新(apt update)
apt update は、リポジトリからパッケージの一覧と最新バージョンの情報を取得します。この時点ではパッケージそのものは変更されません。
sudo apt updatekazulog@sv2:~$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu resolute-security InRelease [137 kB]
Hit:2 http://archive.ubuntu.com/ubuntu resolute InRelease
Get:3 http://archive.ubuntu.com/ubuntu resolute-updates InRelease [137 kB]
Get:4 http://security.ubuntu.com/ubuntu resolute-security/main amd64 Packages [471 kB]
Hit:5 http://archive.ubuntu.com/ubuntu resolute-backports InRelease
Get:6 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 Packages [602 kB]
Get:7 http://security.ubuntu.com/ubuntu resolute-security/universe amd64 Packages [171 kB]
Get:8 http://security.ubuntu.com/ubuntu resolute-security/restricted amd64 Packages [399 kB]
Get:9 http://security.ubuntu.com/ubuntu resolute-security/restricted Translation-en [77.7 kB]
Get:10 http://security.ubuntu.com/ubuntu resolute-security/multiverse amd64 Packages [10.8 kB]
Get:11 http://security.ubuntu.com/ubuntu resolute-security/multiverse Translation-en [2844 B]
Get:12 http://archive.ubuntu.com/ubuntu resolute-updates/main Translation-en [143 kB]
Get:13 http://archive.ubuntu.com/ubuntu resolute-updates/universe amd64 Packages [268 kB]
Get:14 http://archive.ubuntu.com/ubuntu resolute-updates/universe Translation-en [88.4 kB]
Fetched 2508 kB in 3s (727 kB/s)
93 packages can be upgraded. Run 'apt list --upgradable' to see them.
kazulog@sv2:~$| 表示 | 意味 |
|---|---|
Hit | 前回から変わっていないため取得しなかった |
Get | 新しい情報を取得した |
Fetched | 取得した容量と所要時間 |
| 末尾の行 | 更新可能なパッケージ数 |
更新できるパッケージの確認
更新可能なパッケージの一覧は apt list --upgradable で確認します。
apt list --upgradablekazulog@sv2:~$ apt list --upgradable 2>/dev/null | head -8
Listing...
base-files/resolute-updates 14ubuntu6.2 amd64 [upgradable from: 14ubuntu6.1]
bind9-dnsutils/resolute-updates,resolute-security 1:9.20.24-1ubuntu0.3 amd64 [upgradable from: 1:9.20.24-1ubuntu0.2]
bind9-host/resolute-updates,resolute-security 1:9.20.24-1ubuntu0.3 amd64 [upgradable from: 1:9.20.24-1ubuntu0.2]
bind9-libs/resolute-updates,resolute-security 1:9.20.24-1ubuntu0.3 amd64 [upgradable from: 1:9.20.24-1ubuntu0.2]
bpftool/resolute-updates,resolute-security 7.7.0+7.0.0-31.31 amd64 [upgradable from: 7.7.0+7.0.0-30.30]
bsdextrautils/resolute-updates,resolute-security 2.41.3-3ubuntu2.2 amd64 [upgradable from: 2.41.3-3ubuntu2]
bsdutils/resolute-updates,resolute-security 1:2.41.3-3ubuntu2.2 amd64 [upgradable from: 1:2.41.3-3ubuntu2]各行は「パッケージ名 / 取得元のリポジトリ 新しいバージョン アーキテクチャ [現在のバージョン]」の形式です。取得元が -security を含む場合はセキュリティ更新です。
実際に何が起きるかを変更せずに確認したい場合は、apt-get に -s(シミュレーション)を付けます。Inst が更新されるパッケージ、Conf が設定されるパッケージです。
sudo apt-get -s upgradekazulog@sv2:~$ sudo apt-get -s upgrade | tail -12
Conf libssh2-1t64 (1.11.1-1ubuntu0.26.04.4 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf curl (8.18.0-1ubuntu2.5 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf libcurl4t64 (8.18.0-1ubuntu2.5 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf gnupg-l10n (2.4.8-4ubuntu3.1 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [all])
Conf libcurl3t64-gnutls (8.18.0-1ubuntu2.5 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf libevent-core-2.1-7t64 (2.1.12-stable-10ubuntu0.1 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf libflashrom1 (1.6.0-2ubuntu1.1 Ubuntu:26.04/resolute-updates [amd64])
Conf udisks2 (2.10.91-1ubuntu2.1 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf libudisks2-0 (2.10.91-1ubuntu2.1 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf linux-perf (7.0.0-31.31 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [amd64])
Conf linux-tools-common (7.0.0-31.31 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [all])
Conf python3-pyasn1 (0.6.3-1ubuntu0.1 Ubuntu:26.04/resolute-updates, Ubuntu:26.04/resolute-security [all])
kazulog@sv2:~$パッケージの更新(apt upgrade)
sudo apt upgrade -y-yを付けると、確認のプロンプトにすべて自動で応答します。
実行すると、更新されるパッケージの一覧と概要が表示されてから適用されます。
kazulog@sv2:~$ sudo apt upgrade -y
Upgrading:
base-files eject gpgv libcurl3t64-gnutls libpam0g linux-headers-virtual openssh-server python3.14 vim-runtime
bind9-dnsutils fdisk libattr1 libcurl4t64 libperl5.40 linux-image-virtual openssh-sftp-server python3.14-gdbm vim-tiny
bind9-host gnu-coreutils libaudit-common libevent-core-2.1-7t64 libpython3.14 linux-libc-dev openssl python3.14-minimal xxd
bind9-libs gnupg libaudit1 libfdisk1 libpython3.14-minimal linux-perf openssl-provider-legacy sudo-rs zlib1g
bpftool gnupg-l10n libblkid1 libflashrom1 libpython3.14-stdlib linux-tools-common perl ubuntu-release-upgrader-core
bsdextrautils gnupg-utils libbz2-1.0 libgcrypt20 libsmartcols1 linux-virtual perl-base udisks2
bsdutils gpg libc-bin liblastlog2-2 libssh2-1t64 locales perl-modules-5.40 util-linux
cpio gpg-agent libc-dev-bin libmount1 libssl3t64 login python-apt-common util-linux-extra
curl gpg-wks-client libc-gconv-modules-extra libpam-modules libudisks2-0 motd-news-config python3-apt uuid-runtime
diffutils gpgconf libc6 libpam-modules-bin libuuid1 mount python3-distupgrade vim
dirmngr gpgsm libc6-dev libpam-runtime linux-headers-generic openssh-client python3-pyasn1 vim-common
Installing dependencies:
linux-headers-7.0.0-31 linux-image-7.0.0-31-generic linux-modules-7.0.0-31-generic linux-tools-7.0.0-31-generic
linux-headers-7.0.0-31-generic linux-main-modules-zfs-7.0.0-31-generic linux-tools-7.0.0-31
Suggested packages:
linux-tools
Not upgrading yet due to phasing:
sos
/snip/末尾の Summary: の行で、更新・追加・削除されたパッケージの数が分かります。
Summary:
Upgrading: 92, Installing: 7, Removing: 0, Not Upgrading: 1
Space needed: 319 MB / 63.1 GB availableNot upgrading yet due to phasing: と表示されるパッケージがあります。 Ubuntu は更新を一度に全ユーザーへ配布せず、段階的に広げる仕組み(phased updates)を採っています。対象になっていないサーバーでは、その順番が来るまで更新が保留されます。不具合ではないので、そのまま待って問題ありません。apt upgrade と apt full-upgrade の違い
| コマンド | 動作 |
|---|---|
apt upgrade | インストール済みパッケージを更新する。更新のために他のパッケージを削除する必要がある場合、そのパッケージは更新しない |
apt full-upgrade | 同じく更新するが、必要であればパッケージの削除も行う |
通常の運用では apt upgrade を使い、upgrade で更新されないパッケージが残る場合に full-upgrade を検討します。
なお、段階的配布によって保留されているパッケージは full-upgrade でも更新されません。次は upgrade の後に full-upgrade を実行した例で、保留されたままであることが分かります。
kazulog@sv2:~$ apt list --upgradable 2>/dev/null
sos/resolute-updates 4.11.2-0ubuntu0.1 all [upgradable from: 4.10.2-1]
kazulog@sv2:~$ sudo apt full-upgrade -y
Not upgrading yet due to phasing:
sos
Summary:
Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 1
kazulog@sv2:~$ apt-cache policy sos | head -4
sos:
Installed: 4.10.2-1
Candidate: 4.11.2-0ubuntu0.1
Version table:再起動が必要かどうかの確認
カーネルや libc が更新されると、再起動を促すファイルが作成されます。更新しただけでは再起動されません。
ls -l /var/run/reboot-required
cat /var/run/reboot-required.pkgskazulog@sv2:~$ ls -l /var/run/reboot-required /var/run/reboot-required.pkgs
-rw-r--r-- 1 root root 32 Sep 11 00:01 /var/run/reboot-required
-rw-r--r-- 1 root root 46 Sep 11 00:01 /var/run/reboot-required.pkgs
kazulog@sv2:~$ cat /var/run/reboot-required
*** System restart required ***
kazulog@sv2:~$ cat /var/run/reboot-required.pkgs
libc6
linux-image-7.0.0-31-generic
linux-base.pkgs には再起動を必要とするパッケージ名が並びます。再起動するとこのファイルは消えます。
不要になったパッケージの削除
パッケージを削除しても、依存関係のために自動で入れられたパッケージは残ります。これらは apt autoremove でまとめて削除します。
sudo apt autoremove次は tcpdump を導入してから削除し、一緒に入った4つのパッケージを autoremove で削除した例です。削除時に「自動でインストールされ、もう必要ない」と案内されます。
kazulog@sv2:~$ sudo apt remove -y tcpdump | cat
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
The following packages were automatically installed and are no longer required:
ibverbs-providers libibverbs1 libnl-route-3-200 libpcap0.8t64
Use 'sudo apt autoremove' to remove them.
REMOVING:
tcpdump
Summary:
Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 1
Freed space: 1357 kB
(Reading database ... 132310 files and directories currently installed.)
Removing tcpdump (4.99.6-1) ...
Processing triggers for man-db (2.13.1-1build1) ...
kazulog@sv2:~$ sudo apt autoremove -y | cat
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
REMOVING:
ibverbs-providers libibverbs1 libnl-route-3-200 libpcap0.8t64
Summary:
Upgrading: 0, Installing: 0, Removing: 4, Not Upgrading: 1
Freed space: 2739 kB
(Reading database ... 132295 files and directories currently installed.)
Removing ibverbs-providers:amd64 (61.0-2ubuntu3) ...
Removing libpcap0.8t64:amd64 (1.10.6-1ubuntu1) ...
Removing libibverbs1:amd64 (61.0-2ubuntu3) ...
Removing libnl-route-3-200:amd64 (3.12.0-2) ...
Processing triggers for man-db (2.13.1-1build1) ...
Processing triggers for libc-bin (2.43-2ubuntu2.4) ...
kazulog@sv2:~$ダウンロードしたパッケージファイルは apt clean で削除できます。
sudo apt cleanUbuntu 26.04 では、インストール後にパッケージファイルを保持しない設定になっています(APT::Keep-Downloaded-Packages "0")。そのためキャッシュはほとんど溜まらず、apt clean で減る容量もわずかです。
kazulog@sv2:~$ apt-config dump | grep -i 'keep-downloaded'
Version::1.2::APT::Keep-Downloaded-Packages "0";
kazulog@sv2:~$ ls /var/cache/apt/archives/*.deb 2>&1 | head -3
ls: cannot access '/var/cache/apt/archives/*.deb': No such file or directoryパッケージの情報を調べる
| コマンド | 内容 |
|---|---|
apt show [PACKAGE] | パッケージの説明、バージョン、依存関係 |
apt-cache policy [PACKAGE] | インストール済みのバージョンと、取得できるバージョンの一覧 |
apt search [KEYWORD] | パッケージの検索 |
dpkg -l | インストール済みパッケージの一覧 |
kazulog@sv2:~$ apt show nginx 2>/dev/null | head -12
Package: nginx
Version: 1.28.3-2ubuntu1.10
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Nginx Maintainers <pkg-nginx-maintainers@alioth-lists.debian.net>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1627 kB
Provides: httpd, httpd-cgi, nginx-abi-1.28.3-1
Depends: libc6 (>= 2.34), libcrypt1 (>= 1:4.1.0), libpcre2-8-0 (>= 10.22), libssl3t64 (>= 3.0.0), zlib1g (>= 1:1.1.4), nginx-common (= 1.28.3-2ubuntu1.10)
Breaks: nginx-core (<< 1.22.1-6~), nginx-extras (<< 1.22.1-6~), nginx-light (<< 1.22.1-6~)
kazulog@sv2:~$ apt-cache policy nginx
nginx:
Installed: 1.28.3-2ubuntu1.10
Candidate: 1.28.3-2ubuntu1.10
Version table:
*** 1.28.3-2ubuntu1.10 500
500 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu resolute-security/main amd64 Packages
100 /var/lib/dpkg/status
1.28.3-2ubuntu1 500
500 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages
kazulog@sv2:~$apt-cache policy は、どのリポジトリから、どのバージョンが取得できるかを確認できます。上の例では -updates と -security の両方から同じバージョンが提供されています。
kazulog@sv2:~$ apt search '^tcpdump$' 2>/dev/null
tcpdump/resolute,now 4.99.6-1 amd64 [residual-config]
command-line network traffic analyzer
kazulog@sv2:~$ dpkg -l | grep -c '^ii'
682リポジトリの設定ファイル
取得元のリポジトリは /etc/apt/sources.list.d/ubuntu.sources に定義されています。Ubuntu 24.04 以降は deb822 形式と呼ばれる新しい書式で、1行に詰め込む従来の /etc/apt/sources.list とは異なります。
cat /etc/apt/sources.list.d/ubuntu.sourcesTypes: deb
URIs: http://archive.ubuntu.com/ubuntu
Suites: resolute resolute-updates resolute-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu
Suites: resolute-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg| 項目 | 内容 |
|---|---|
Types | deb(バイナリ)。ソースを取得する場合は deb-src を追加 |
URIs | リポジトリのURL |
Suites | 取得する範囲。resolute は 26.04 のコードネーム。-updates は不具合修正、-security はセキュリティ更新、-backports は新しいバージョンの提供 |
Components | main(公式サポート)、universe(コミュニティ)、restricted、multiverse |
Signed-By | 署名の検証に使う鍵 |
更新の履歴を確認する
APT の実行履歴は /var/log/apt/history.log に残ります。いつ、どのコマンドで、何が変更されたかを後から追えます。
sudo tail /var/log/apt/history.logkazulog@sv2:~$ sudo tail -12 /var/log/apt/history.log
Start-Date: 2026-09-11 00:04:43
Commandline: apt remove -y tcpdump
Requested-By: kazulog (1000)
Remove: tcpdump:amd64 (4.99.6-1)
End-Date: 2026-09-11 00:04:43
Start-Date: 2026-09-11 00:04:47
Commandline: apt autoremove -y
Requested-By: kazulog (1000)
Remove: libpcap0.8t64:amd64 (1.10.6-1ubuntu1), libnl-route-3-200:amd64 (3.12.0-2), libibverbs1:amd64 (61.0-2ubuntu3), ibverbs-providers:amd64 (61.0-2ubuntu3)
End-Date: 2026-09-11 00:04:48
kazulog@sv2:~$ ls /var/log/apt/
eipp.log.xz history.log term.logterm.log には、パッケージの展開時の詳細な出力が記録されています。
セキュリティ更新の自動適用
Ubuntu は既定で、セキュリティ更新を毎日自動で適用します。手動での apt upgrade と併せて、自動更新設定(unattended-upgrades)も確認してください。
検証環境と実行ログ
本記事の実行例は、CML 上の Ubuntu 26.04 LTS Server(apt 3.2.0)で採取したものです。各手順の実行ログを以下からダウンロードできます。
| 手順 | 実行ログ |
|---|---|
| 初期状態(APT のバージョンとリポジトリ設定) | log |
| パッケージリストの更新と更新可能な一覧 | log |
| 更新内容のシミュレーション | log |
| パッケージの更新(92件) | log |
| full-upgrade と段階的配布の確認 | log |
| 再起動要否の確認 | log |
| 再起動後の状態と不要パッケージの削除 | log |
| キャッシュの設定確認 | log |
| パッケージ情報の確認 | log |
| 更新履歴の確認 | log |
参考リンク
Ubuntu Server documentation: Package management
関連記事
- Ubuntu 26.04 LTS Server のホスト名の変更(hostnamectl)
- Ubuntu 26.04 LTS Server のパッケージ更新(apt update / upgrade)
- Ubuntu 26.04 LTS Server のタイムゾーン設定と時刻同期
- Ubuntu 26.04 LTS Server のユーザー作成と sudo 権限の設定
- Ubuntu 26.04 LTS Server の SSH サーバー設定(公開鍵認証)
- Ubuntu 26.04 LTS Server の telnet サーバー設定
- Ubuntu 26.04 LTS Server の inetd(スーパーサーバー)設定
- Ubuntu 26.04 LTS Server の TFTP サーバー設定(tftpd-hpa)
- Ubuntu 26.04 LTS Server の FTP サーバー設定(vsftpd)
- Ubuntu 26.04 LTS Server の syslog サーバー設定(rsyslog)
- Ubuntu 26.04 LTS Server のサービス管理(systemctl)とログ確認(journalctl)
- Ubuntu 26.04 LTS Server の自動更新設定(unattended-upgrades)
- Ubuntu 26.04 LTS Server の初期設定を自動化する(cloud-init)
- Ubuntu 26.04 LTS Server のカーネルパラメータ設定(sysctl)
- Ubuntu 26.04 LTS Server のネットワーク設定(Netplan)
- Ubuntu 26.04 LTS Server の名前解決設定(systemd-resolved)
- Ubuntu 26.04 LTS Server の NTP 同期先の変更(chrony)
- Ubuntu 26.04 LTS Server のスタティックルート設定(Netplan)
- neovim 公式サイトから最新バージョンをインストールする手順 Ubuntu 26.04 LTS Server