Apt command

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

The apt is a command used on Debian, Ubuntu and other Linux distribution. It provides a high-level commandline interface for the package management system. It is intended as an end user interface and enables some options better suited for interactive usage by default compared to more specialized APT tools like apt-get command and apt-cache command.

apt command Syntax

The syntax is

apt [-h] [-o=config_string] [-c=config_file] [-t=target_release] [-a=architecture] {list | search | show | update | install pkg [{=pkg_version_number | /target_release}]...  | remove pkg...  |
           upgrade | full-upgrade | edit-sources | {-v | --version} | {-h | --help}}

apt Commands

All apt command must run by the root user either using the sudo command or su command.

  • list - list packages based on package names
  • search - search in package descriptions
  • show - show package details
  • install - install packages
  • remove - remove packages
  • autoremove - Remove automatically all unused packages
  • update - update list of available packages
  • upgrade - upgrade the system by installing/upgrading packages
  • full-upgrade - upgrade the system by removing/installing/upgrading packages
  • edit-sources - edit the source information file

Examples

Let us see some example:

Upgrade all installed packages on your system

sudo apt update 
sudo apt upgrade

OR

sudo -- sh -c "apt update && apt upgrade"

Sudo-apt-update-upgrade-demo.png

Install the nginx software package

sudo apt install nginx

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx nginx-common nginx-core
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 582 kB of archives.
After this operation, 2,022 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu artful/main amd64 nginx-common all 1.12.1-0ubuntu2 [39.0 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnginx-mod-http-geoip amd64 1.12.1-0ubuntu2 [11.5 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnginx-mod-http-image-filter amd64 1.12.1-0ubuntu2 [14.9 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnginx-mod-http-xslt-filter amd64 1.12.1-0ubuntu2 [13.4 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnginx-mod-mail amd64 1.12.1-0ubuntu2 [42.1 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu artful/main amd64 libnginx-mod-stream amd64 1.12.1-0ubuntu2 [63.9 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu artful/main amd64 nginx-core amd64 1.12.1-0ubuntu2 [393 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu artful/main amd64 nginx all 1.12.1-0ubuntu2 [3,578 B]
Fetched 582 kB in 4s (128 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 197704 files and directories currently installed.)
Preparing to unpack .../0-nginx-common_1.12.1-0ubuntu2_all.deb ...
Unpacking nginx-common (1.12.1-0ubuntu2) ...
Selecting previously unselected package libnginx-mod-http-geoip.
Preparing to unpack .../1-libnginx-mod-http-geoip_1.12.1-0ubuntu2_amd64.deb ...
Unpacking libnginx-mod-http-geoip (1.12.1-0ubuntu2) ...
Selecting previously unselected package libnginx-mod-http-image-filter.
Preparing to unpack .../2-libnginx-mod-http-image-filter_1.12.1-0ubuntu2_amd64.deb ...
Unpacking libnginx-mod-http-image-filter (1.12.1-0ubuntu2) ...
Selecting previously unselected package libnginx-mod-http-xslt-filter.
Preparing to unpack .../3-libnginx-mod-http-xslt-filter_1.12.1-0ubuntu2_amd64.deb ...
Unpacking libnginx-mod-http-xslt-filter (1.12.1-0ubuntu2) ...
Selecting previously unselected package libnginx-mod-mail.
Preparing to unpack .../4-libnginx-mod-mail_1.12.1-0ubuntu2_amd64.deb ...
Unpacking libnginx-mod-mail (1.12.1-0ubuntu2) ...
Selecting previously unselected package libnginx-mod-stream.
Preparing to unpack .../5-libnginx-mod-stream_1.12.1-0ubuntu2_amd64.deb ...
Unpacking libnginx-mod-stream (1.12.1-0ubuntu2) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../6-nginx-core_1.12.1-0ubuntu2_amd64.deb ...
Unpacking nginx-core (1.12.1-0ubuntu2) ...
Selecting previously unselected package nginx.
Preparing to unpack .../7-nginx_1.12.1-0ubuntu2_all.deb ...
Unpacking nginx (1.12.1-0ubuntu2) ...
Processing triggers for ufw (0.35-5) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up nginx-common (1.12.1-0ubuntu2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up libnginx-mod-http-image-filter (1.12.1-0ubuntu2) ...
Processing triggers for systemd (234-2ubuntu12.1) ...
Setting up libnginx-mod-mail (1.12.1-0ubuntu2) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libnginx-mod-http-xslt-filter (1.12.1-0ubuntu2) ...
Setting up libnginx-mod-http-geoip (1.12.1-0ubuntu2) ...
Setting up libnginx-mod-stream (1.12.1-0ubuntu2) ...
Setting up nginx-core (1.12.1-0ubuntu2) ...
Setting up nginx (1.12.1-0ubuntu2) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for ufw (0.35-5) ...

See also