aptコマンドはパッケージ管理のコマンドです。
やすひら
aptコマンドの概要と使用方法を紹介します
この記事でわかること
- aptコマンドの概要
- aptコマンドの使い方
目次
コマンド概要
aptコマンドは、Debian系Linuxディストリビューション(Ubuntu等)で使用されるパッケージ管理のコマンドです。
aptコマンドを使用することで、ソフトウェアのインストール、アップデート、削除、検索を行うことができます。
従来のapt-getコマンドの使いやすさを向上させたのがaptコマンドです。
コマンドオプション
コマンドオプションを紹介します。
コマンドオプション | 意味 |
---|---|
update | アップデート |
upgrade | アップグレード |
install | インストール |
remove | パッケージを削除(設定ファイルは残る) |
purge | パッケージを完全に削除 |
autoremove | 不要なパッケージを削除 |
search | キーワード検索 |
show | パッケージの詳細情報を表示 |
コマンドの使い方
aptコマンドの使い方を紹介します。
パッケージをアップデート
パッケージをアップデートします。
コマンド形式
sudo apt update
コマンド実行例
$ sudo apt update -y
[sudo] password for user:
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
パッケージをアップグレード
パッケージをアップグレードします。
コマンド形式
sudo apt upgrade
コマンド実行例
$ sudo apt upgrade -y
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
libfile-copy-recursive-perl openbsd-inetd tcpd update-inetd
Use 'sudo apt autoremove' to remove them.
The following security updates require Ubuntu Pro with 'esm-infra' enabled:
libpam0g libc-ares2 screen libwebp6 libkrb5-3 libgssapi-krb5-2 python2.7-dev
libpython3.6-minimal libnghttp2-14 libisccfg160 intel-microcode
linux-headers-generic libsndfile1-dev linux-libc-dev vim-common libcurl4
libldap-2.4-2 libpam-modules openssl libgdk-pixbuf2.0-0 libc6-dev
libpython3.6-dev libsystemd0 linux-image-generic python2.7-minimal
libpam-cap libpython3.6-stdlib libelf1 python3-urllib3 binutils libirs160
bind9-host librbd1 open-iscsi dnsutils libpython2.7 libncurses5 python2.7
dnsmasq-base libc6 libpython3.6 python3.6 open-vm-tools openssh-sftp-server
gawk libk5crypto3 libisc169 python3-idna libpython2.7-dev udev locales
passwd procps libklibc libpam-runtime amd64-microcode libncursesw5
libprocps6 libx11-6 python3-requests linux-signed-generic libudev1 libvpx5
libapparmor1 lxd libflac-dev krb5-locales python3.6-minimal
python-cryptography binutils-x86-64-linux-gnu libtiff5 libisc-export169
python3-cryptography busybox-static libc-bin libtinfo5 libkrb5support0
libcap2 qemu-utils tar systemd-sysv libcap2-bin libldap-common liblwres160
vim-runtime vim libpam-systemd libsndfile1 ncurses-term systemd
libgdk-pixbuf2.0-bin login libssh-gcrypt-4 xxd libwebpmux3 ncurses-bin
libpam-modules-bin openssh-server libx11-data libgdk-pixbuf2.0-common
openssh-client libdns-export1100 libnss-systemd binutils-common
libglib2.0-data ncurses-base libc-dev-bin libxml2 libflac8 libbinutils
libpython2.7-minimal multiarch-support libgnutls30 qemu-guest-agent vim-tiny
apparmor dns-root-data libisccc160 python-idna libssl1.1 libbind9-160
python3-jinja2 accountsservice python3.6-dev libdns1100 libpython2.7-stdlib
curl qemu-block-extra klibc-utils linux-generic lxd-client libglib2.0-0
librados2 uidmap libcurl3-gnutls less libx11-xcb1 libaccountsservice0
libssl1.0.0 tzdata busybox-initramfs
Learn more about Ubuntu Pro for 18.04 at https://ubuntu.com/18-04
The following NEW packages will be installed:
efibootmgr libefiboot1 libefivar1 ubuntu-pro-client ubuntu-pro-client-l10n
The following packages will be upgraded:
grub-common grub-pc grub-pc-bin grub2-common python3-update-manager
ubuntu-advantage-tools update-manager-core update-notifier-common
8 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 3895 kB of archives.
After this operation, 662 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 update-manager-core all 1:18.04.12 [8512 B]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-update-manager all 1:18.04.12 [35.3 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 ubuntu-advantage-tools all 32.3~18.04 [11.0 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 ubuntu-pro-client amd64 32.3~18.04 [207 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 update-notifier-common all 3.192.1.21 [172 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 ubuntu-pro-client-l10n amd64 32.3~18.04 [18.5 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic/main amd64 libefivar1 amd64 34-1 [46.2 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 libefiboot1 amd64 34-1 [23.5 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 efibootmgr amd64 15-1 [28.2 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 grub2-common amd64 2.02-2ubuntu8.26 [533 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 grub-pc amd64 2.02-2ubuntu8.26 [138 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 grub-pc-bin amd64 2.02-2ubuntu8.26 [901 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 grub-common amd64 2.02-2ubuntu8.26 [1773 kB]
Fetched 3895 kB in 5s (733 kB/s)
Preconfiguring packages ...
(Reading database ... 116853 files and directories currently installed.)
Preparing to unpack .../00-update-manager-core_1%3a18.04.12_all.deb ...
Unpacking update-manager-core (1:18.04.12) over (1:18.04.11.13) ...
Preparing to unpack .../01-python3-update-manager_1%3a18.04.12_all.deb ...
Unpacking python3-update-manager (1:18.04.12) over (1:18.04.11.13) ...
Preparing to unpack .../02-ubuntu-advantage-tools_32.3~18.04_all.deb ...
Unpacking ubuntu-advantage-tools (32.3~18.04) over (29.4~18.04) ...
dpkg: warning: unable to delete old directory '/var/lib/ubuntu-advantage': Direc
tory not empty
dpkg: warning: unable to delete old directory '/etc/ubuntu-advantage': Directory
not empty
Selecting previously unselected package ubuntu-pro-client.
Preparing to unpack .../03-ubuntu-pro-client_32.3~18.04_amd64.deb ...
Unpacking ubuntu-pro-client (32.3~18.04) ...
Preparing to unpack .../04-update-notifier-common_3.192.1.21_all.deb ...
Unpacking update-notifier-common (3.192.1.21) over (3.192.1.19) ...
Selecting previously unselected package ubuntu-pro-client-l10n.
Preparing to unpack .../05-ubuntu-pro-client-l10n_32.3~18.04_amd64.deb ...
Unpacking ubuntu-pro-client-l10n (32.3~18.04) ...
Selecting previously unselected package libefivar1:amd64.
Preparing to unpack .../06-libefivar1_34-1_amd64.deb ...
Unpacking libefivar1:amd64 (34-1) ...
Selecting previously unselected package libefiboot1:amd64.
Preparing to unpack .../07-libefiboot1_34-1_amd64.deb ...
Unpacking libefiboot1:amd64 (34-1) ...
Selecting previously unselected package efibootmgr.
Preparing to unpack .../08-efibootmgr_15-1_amd64.deb ...
Unpacking efibootmgr (15-1) ...
Preparing to unpack .../09-grub2-common_2.02-2ubuntu8.26_amd64.deb ...
Unpacking grub2-common (2.02-2ubuntu8.26) over (2.02-2ubuntu8.25) ...
Preparing to unpack .../10-grub-pc_2.02-2ubuntu8.26_amd64.deb ...
Unpacking grub-pc (2.02-2ubuntu8.26) over (2.02-2ubuntu8.25) ...
Preparing to unpack .../11-grub-pc-bin_2.02-2ubuntu8.26_amd64.deb ...
Unpacking grub-pc-bin (2.02-2ubuntu8.26) over (2.02-2ubuntu8.25) ...
Preparing to unpack .../12-grub-common_2.02-2ubuntu8.26_amd64.deb ...
Unpacking grub-common (2.02-2ubuntu8.26) over (2.02-2ubuntu8.25) ...
Setting up python3-update-manager (1:18.04.12) ...
Setting up libefivar1:amd64 (34-1) ...
Setting up libefiboot1:amd64 (34-1) ...
Setting up ubuntu-pro-client (32.3~18.04) ...
Setting up ubuntu-advantage-tools (32.3~18.04) ...
Removing obsolete conffile /etc/ubuntu-advantage/help_data.yaml ...
Setting up update-manager-core (1:18.04.12) ...
Setting up update-notifier-common (3.192.1.21) ...
Setting up efibootmgr (15-1) ...
Setting up ubuntu-pro-client-l10n (32.3~18.04) ...
Setting up grub-common (2.02-2ubuntu8.26) ...
update-rc.d: warning: start and stop actions are no longer supported; falling ba
ck to defaults
Setting up grub-pc-bin (2.02-2ubuntu8.26) ...
Setting up grub2-common (2.02-2ubuntu8.26) ...
Setting up grub-pc (2.02-2ubuntu8.26) ...
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50-curtin-settings.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-213-generic
Found initrd image: /boot/initrd.img-4.15.0-213-generic
Found linux image: /boot/vmlinuz-4.15.0-211-generic
Found initrd image: /boot/initrd.img-4.15.0-211-generic
done
Processing triggers for systemd (237-3ubuntu10.57) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for install-info (6.5.0.dfsg.1-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
パッケージをインストール
パッケージをインストールします。
コマンド形式
sudo apt install [パッケージ名]
コマンド実行例
$ sudo apt install sl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
sl
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 12.8 kB of archives.
After this operation, 56.3 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com jammy/universe arm64 sl arm64 5.02-1 [12.8 kB]
Fetched 12.8 kB in 1s (14.5 kB/s)
Selecting previously unselected package sl.
(Reading database ... 229970 files and directories currently installed.)
Preparing to unpack .../archives/sl_5.02-1_arm64.deb ...
Unpacking sl (5.02-1) ...
Setting up sl (5.02-1) ...
Processing triggers for man-db (2.10.2-1) ...
パッケージを削除(設定ファイルの削除なし)
設定ファイルの削除なしで、パッケージを削除します。
コマンド形式
sudo apt remove [パッケージ名]
コマンド実行例
$ sudo apt remove sl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
sl
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 56.3 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 229993 files and directories currently installed.)
Removing sl (5.02-1) ...
Processing triggers for man-db (2.10.2-1) ...
パッケージを削除(設定ファイルの削除あり)
設定ファイルの削除ありで、パッケージを削除します。
コマンド形式
sudo apt purge [パッケージ名]
コマンド実行例
$ sudo apt purge sl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
sl*
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 56.3 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 229993 files and directories currently installed.)
Removing sl (5.02-1) ...
Processing triggers for man-db (2.10.2-1) ...
不要パッケージを自動削除する
不要パッケージを自動削除します。
コマンド形式
sudo apt autoremove
コマンド実行例
$ sudo apt autoremove -y
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libfile-copy-recursive-perl openbsd-inetd tcpd update-inetd
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
After this operation, 304 kB disk space will be freed.
(Reading database ... 116932 files and directories currently installed.)
Removing openbsd-inetd (0.20160825-3) ...
Removing update-inetd (4.44) ...
Removing libfile-copy-recursive-perl (0.40-1) ...
Removing tcpd (7.6.q-27) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
パッケージを検索
パッケージを検索します。
コマンド形式
sudo apt search [キーワード]
コマンド実行例
$ sudo apt search sl
Sorting...
Full Text Search...
2048/jammy 0.20210105.1243-1 arm64
Slide and add puzzle game for text mode
2048-qt/jammy 0.1.6-2build1 arm64
mathematics based puzzle game
4g8/jammy 1.0-3.3 arm64
Packet Capture and Interception for Switched Networks
9base/jammy 1:6-11 arm64
Plan 9 userland tools
abcm2ps/jammy 8.14.11-0.1 arm64
Translates ABC music description files to PostScript
abcmidi/jammy 20220218+ds1-1 arm64
converter from ABC to MIDI format and back
abiword/jammy 3.0.5~dfsg-1 arm64
efficient, featureful word processor with collaboration
-- 以下省略 --
パッケージの詳細情報を表示
パッケージの詳細情報を表示します。
コマンド形式
sudo apt show [パッケージ名]
コマンド実行例
$ sudo apt show sl
Package: sl
Version: 5.02-1
Priority: optional
Section: universe/games
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Markus Frosch <lazyfrosch@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 56.3 kB
Depends: libc6 (>= 2.17), libncurses6 (>= 6), libtinfo6 (>= 6)
Homepage: https://github.com/mtoyoda/sl
Download-Size: 12.8 kB
APT-Sources: http://ports.ubuntu.com jammy/universe arm64 Packages
Description: Correct you if you type `sl' by mistake
Sl is a program that can display animations aimed to correct you
if you type 'sl' by mistake.
SL stands for Steam Locomotive.
まとめ
aptコマンドの概要と使い方を紹介しました。
aptコマンドは
- パッケージをアップデートできる
- パッケージをアップグレードできる
- パッケージをインストールできる
- パッケージを削除できる
- パッケージを検索できる
- パッケージ情報を表示できる
aptコマンドは、システムを最新状態に保ったり、ソフトウェアをインストールするために必要なコマンドです。
かなり多用するコマンドですので、覚えて実践していきましょう。