LoginSignup
7
1

apt update と apt upgradeの違いと指定したパッケージだけを個別にアップグレードする方法

Posted at

ヘルプを見てみる

なにはともあれ、まずは公式の説明を読んでみましょう。

$ apt -h
<中略>
Most used commands:
  update - update list of available packages
  upgrade - upgrade the system by installing/upgrading packages

めっちゃざっくり言うと

apt update:アップデートが可能なパッケージのリストを更新する。あくまでリストを更新するだけで、リストが表示されるわけでもなければ、実際にインストール済みのパッケージになにか更新が加えられることはない。
apt upgrade:実際にインストールされているパッケージのバージョンアップを行う。

といった具合になります。upgradeを行うまで、特に環境に影響を及ぶわけではないですね。

実際にコマンドを叩いてみる

$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [461 kB]
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:5 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [124 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [721 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [190 kB]
Get:9 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [15.3 kB]
Get:10 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [418 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy-updates/restricted Translation-en [63.8 kB]
Get:12 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [927 kB]
Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/universe Translation-en [197 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 c-n-f Metadata [20.4 kB]
Fetched 3474 kB in 5s (633 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
18 packages can be upgraded. Run 'apt list --upgradable' to see them.

上記のログでは18個のパッケージがアップグレード可能と表示されます。
ここでapt list --upgradableで、アップグレード可能となったパッケージのリストが確認できるわけです。

リストを確認する

というわけで、実際にコマンドを打って確認してみましょう。

$ apt list --upgradable
[sudo] password for hogehoge:
Listing... Done
apport/jammy-updates 2.20.11-0ubuntu82.5 all [upgradable from: 2.20.11-0ubuntu82.4]
distro-info-data/jammy-updates 0.52ubuntu0.4 all [upgradable from: 0.52ubuntu0.3]
dpkg/jammy-updates 1.21.1ubuntu2.2 amd64 [upgradable from: 1.21.1ubuntu2.1]
iptables/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libgssapi-krb5-2/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libip4tc2/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libip6tc2/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libk5crypto3/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libkrb5-3/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libkrb5support0/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libx11-6/jammy-updates,jammy-security 2:1.7.5-1ubuntu0.2 amd64 [upgradable from: 2:1.7.5-1]
libx11-data/jammy-updates,jammy-security 2:1.7.5-1ubuntu0.2 all [upgradable from: 2:1.7.5-1]
libxtables12/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
python3-apport/jammy-updates 2.20.11-0ubuntu82.5 all [upgradable from: 2.20.11-0ubuntu82.4]
python3-problem-report/jammy-updates 2.20.11-0ubuntu82.5 all [upgradable from: 2.20.11-0ubuntu82.4]
python3-software-properties/jammy-updates 0.99.22.7 all [upgradable from: 0.99.22.6]
software-properties-common/jammy-updates 0.99.22.7 all [upgradable from: 0.99.22.6]
tzdata/jammy-updates 2023c-0ubuntu0.22.04.2 all [upgradable from: 2023c-0ubuntu0.22.04.1]

18個のパッケージがリストとして出力されましたね。
早速、アップグレードしていきましょう。

特定のパッケージだけを指定してアップグレードする

アップグレードそのものはsudo apt upgradeとコマンドを打てば可能ですが、今回は指定したパッケージだけを個別にアップグレードしていきたいと思います。
その際のコマンドは下記の具合になります。

$ sudo apt install --only-upgrade <パッケージ名>

upgradeじゃなくてinstallなところが間違えやすいですね。
今回はpython3関連のパッケージのみアップグレードしていきたいと思います。

~$ sudo apt install --only-upgrade python3*
[sudo] password for kztk:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'python3-trufont' for glob 'python3*'
Note, selecting 'python3-pypubsub' for glob 'python3*'

<中略>

The following packages will be upgraded:
  python3-apport python3-problem-report python3-software-properties software-properties-common
4 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Need to get 143 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-problem-report all 2.20.11-0ubuntu82.5 [11.1 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-apport all 2.20.11-0ubuntu82.5 [88.9 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 software-properties-common all 0.99.22.7 [14.1 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-software-properties all 0.99.22.7 [28.8 kB]
Fetched 143 kB in 2s (76.3 kB/s)
(Reading database ... 24150 files and directories currently installed.)
Preparing to unpack .../python3-problem-report_2.20.11-0ubuntu82.5_all.deb ...
Unpacking python3-problem-report (2.20.11-0ubuntu82.5) over (2.20.11-0ubuntu82.4) ...
Preparing to unpack .../python3-apport_2.20.11-0ubuntu82.5_all.deb ...
Unpacking python3-apport (2.20.11-0ubuntu82.5) over (2.20.11-0ubuntu82.4) ...
Preparing to unpack .../software-properties-common_0.99.22.7_all.deb ...
Unpacking software-properties-common (0.99.22.7) over (0.99.22.6) ...
Preparing to unpack .../python3-software-properties_0.99.22.7_all.deb ...
Unpacking python3-software-properties (0.99.22.7) over (0.99.22.6) ...
Setting up python3-problem-report (2.20.11-0ubuntu82.5) ...
Setting up python3-apport (2.20.11-0ubuntu82.5) ...
Setting up python3-software-properties (0.99.22.7) ...
Setting up software-properties-common (0.99.22.7) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...

リストから、アップグレードしたpython3関連のパッケージが無くなっていることも確認してみます。

$ sudo apt list --upgradable
apport/jammy-updates 2.20.11-0ubuntu82.5 all [upgradable from: 2.20.11-0ubuntu82.4]
distro-info-data/jammy-updates 0.52ubuntu0.4 all [upgradable from: 0.52ubuntu0.3]
dpkg/jammy-updates 1.21.1ubuntu2.2 amd64 [upgradable from: 1.21.1ubuntu2.1]
iptables/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libgssapi-krb5-2/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libip4tc2/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libip6tc2/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
libk5crypto3/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libkrb5-3/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libkrb5support0/jammy-updates 1.19.2-2ubuntu0.2 amd64 [upgradable from: 1.19.2-2ubuntu0.1]
libxtables12/jammy-updates 1.8.7-1ubuntu5.1 amd64 [upgradable from: 1.8.7-1ubuntu5]
tzdata/jammy-updates 2023c-0ubuntu0.22.04.2 all [upgradable from: 2023c-0ubuntu0.22.04.1]

これで無事に指定したパッケージがアップグレードされたことが確認できました。

参照

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