apt, apt-getは、Debian用に開発されたパッケージ管理システムです。普段何気なく使っているこのコマンドについて、調べたので共有します。

ap-get,aptの違い

https://debian-handbook.info/browse/stable/sect.apt-get.html

APT is a vast project, whose original plans included a graphical interface. It is based on a library which contains the core application, and apt-get is the first front end — command-line based — which was developed within the project. apt is a second command-line based front end provided by APT which overcomes some design mistakes of apt-get.

と書かれています。訳すと

APTは、大きなプロジェクトで、当初の計画ではグラフィカルインターフェースが含まれていました。これは、コアアプリケーションを含むライブラリに基づいており、apt-getは、プロジェクト内で開発された最初のフロントエンド(コマンドラインベース)です。 aptは、APTによって提供される2番目のコマンドラインベースのフロントエンドで、apt-getの設計ミスをいくつか克服します。

こんな感じです。apt-getは、aptを改善したものということです。基本的には、aptを使うで問題ないということです。

CLI上で使う場合

Dockerfilenなどで、各種パッケージをインストールするようなことを行うこともよくあると思います。aptでパッケージのインストールを行うと次のような警告が出ることがあります。

RUN apt install -y nginx
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

これは、aptがCLI向けではないということみたいです。apt-getに変えることで警告は消えます。man apt等で調べると下記のように、aptは、エンドユーザ向け、apt-getは、コマンドライン向けと記載れています。

SCRIPT USAGE AND DIFFERENCES FROM OTHER APT TOOLS
       The apt(8) commandline is designed as an end-user tool and it may change behavior between versions. While it tries not to break backward compatibility this is not guaranteed either if a change seems beneficial for interactive use.

       All features of apt(8) are available in dedicated APT tools like apt-get(8) and apt-cache(8) as well.  apt(8) just changes the default value of some options (see apt.conf(5) and specifically the Binary scope). So you should prefer using these commands (potentially with some additional options enabled) in your scripts as they keep backward compatibility as much as possible.

まとめ

普段何気なく利用しているapt, apt-getですが、それぞれの特性があることがわかりました。用途に合わせて利用するようにしましょう。