apt

apt はパッケージ管理システムの CLI(コマンドラインインタフェース)である。Debian 並びにその派生ディストリビューションである Ubuntu 及び Linux Mint で apt コマンドを使用できる。

apt [option]... list
apt [option]... search
apt [option]... show
apt [option]... update
apt [option]... install pkg...
apt [option]... upgrade
apt [option]... full-upgrade
apt [option]... edit-sources

引数

apt コマンドには以下に示す引数を指定できる。

list
パッケージの一覧を表示する。
$ apt list

更新可能なパッケージの一覧を表示する。

$ apt list --upgradable
一覧表示... 完了
linux-generic/jammy-updates 5.15.0.138.134 amd64 [5.15.0.136.134 からアップグレード可]
linux-headers-generic/jammy-updates 5.15.0.138.134 amd64 [5.15.0.136.134 からアップグレード可]
linux-image-generic/jammy-updates 5.15.0.138.134 amd64 [5.15.0.136.134 からアップグレード可]
linux-libc-dev/jammy-updates 5.15.0-138.148 amd64 [5.15.0-136.147 からアップグレード可]
update
パッケージのインデックスを更新する。パッケージのインデックスを更新するには、スーパーユーザー(rootユーザー)の権限が必要である。
$ sudo apt update
install pkg...
パッケージをインストールする。空白で区切って、複数のパッケージを指定できる。パッケージをインストールするには、スーパーユーザー(rootユーザー)の権限が必要である。
$ sudo apt install default-jre
remove pkg ...
パッケージをアンインストールする。パッケージをアンインストールするには、スーパーユーザー(rootユーザー)の権限が必要である。
$ sudo apt remove default-jre
upgrade
パッケージを更新する。パッケージを更新するには、スーパーユーザー(rootユーザー)の権限が必要である。
$ sudo apt upgrade

オプション

以下に示すオプションを apt コマンドに指定できる。

-h
ヘルプを表示して、コマンドを終了する。 (POSIX)
$ apt -h
apt
Usage: apt command [options]
       apt help command [options]

Commands:
  add-repository   - Add entries to apt sources.list
  autoclean        - Erase old downloaded archive files
  autopurge        - Remove packages with their configuration files and automatically remove all unused packages
  autoremove       - Remove automatically all unused packages
  build            - Build binary or source packages from sources
  build-dep        - Configure build-dependencies for source packages
  changelog        - View a package's changelog
  check            - Verify that there are no broken dependencies
  clean            - Erase downloaded archive files
  contains         - List packages containing a file
  content          - List files contained in a package
  deb              - Install a .deb package
  depends          - Show raw dependency information for a package
  dist-upgrade     - Upgrade the system by removing/installing/upgrading packages
  download         - Download the .deb file for a package
  edit-sources     - Edit /etc/apt/sources.list with your preferred text editor
  dselect-upgrade  - Follow dselect selections
  full-upgrade     - Same as 'dist-upgrade'
  held             - List all held packages
  help             - Show help for a command
  hold             - Hold a package
  install          - Install/upgrade packages
  list             - List packages based on package names
  policy           - Show policy settings
  purge            - Remove packages and their configuration files
  recommends       - List missing recommended packages for a particular package
  rdepends         - Show reverse dependency information for a package
  reinstall        - Download and (possibly) reinstall a currently installed package
  remove           - Remove packages
  search           - Search for a package by name and/or expression
  show             - Display detailed information about a package
  showhold         - Same as 'held'
  showsrc          - Display all the source package records that match the given package name
  source           - Download source archives
  sources          - Same as 'edit-sources'
  unhold           - Unhold a package
  update           - Download lists of new/upgradable packages
  upgrade          - Perform a safe upgrade
  version          - Show the installed version of a package
--help
ヘルプを表示して、コマンドを終了する。 (GNU)
-v
バージョン情報を出力して、コマンドを終了する。 (POSIX)
--version
バージョン情報を出力して、コマンドを終了する。 (GNU)

ファイル

apt コマンドに関するファイルには次のものがある。

/etc/apt/sources.list
パッケージのフェッチ元の場所
/etc/apt/apt.conf
APT構成ファイル

Advanced Packaging Tool (APT)

Advanced Packaging Tool (APT)とは、Debian用に開発されたパッケージ管理システムである。

リポジトリの設定は、/etc/apt/sources.listファイルに記載されている。

deb file:///home/horiuchi/installer/packages ./

apt-get と apt の違い

apt-get コマンドの設計上のミスを克服したものが apt コマンドである。

対応表

apt コマンドは Debian 系の Linux で使用できる。

対応表
系統 OS 対応
Debian Debian
elementary OS
Linux Mint
MX Linux
Ubuntu
Zorin OS
Red Hat CentOS Stream
Fedora
Red Hat Enterprise Linux
Slackware Salix OS
Slackware
その他Linux Arch Linux
Gentoo Linux
openSUSE
Manjaro
UNIX FreeBSD
macOS

関連記事

参考文献

Software in the Public Interest (2023) 6.2. aptitude、apt-get、apt コマンド Debian 管理者ハンドブック