Apt command

Revision as of 08:29, 16 November 2017 by Admin (talk | contribs) (→‎See also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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"

 

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) ...

Show information about the package called mariadb-server

apt show mariadb-server

Sample session:

Package: mariadb-server
Version: 10.1.25-1
Priority: optional
Section: universe/database
Source: mariadb-10.1
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 64.5 kB
Depends: mariadb-server-10.1 (>= 10.1.25-1)
Homepage: https://mariadb.org/
Download-Size: 12.8 kB
APT-Sources: http://in.archive.ubuntu.com/ubuntu artful/universe amd64 Packages
Description: MariaDB database server (metapackage depending on the latest version)
 This is an empty package that depends on the current "best" version of
 mariadb-server (currently mariadb-server-10.0), as determined by the MariaDB
 maintainers. Install this package if in doubt about which MariaDB
 version you need. That will install the version recommended by the
 package maintainers.
 .
 MariaDB is a fast, stable and true multi-user, multi-threaded SQL database
 server. SQL (Structured Query Language) is the most popular database query
 language in the world. The main goals of MariaDB are speed, robustness and
 ease of use.

Display all available versions of the software package mysql-client

apt list --all-versions mysql-client

Sample outputs:

Listing... Done
mysql-client/artful-updates,artful-updates,artful-security,artful-security 5.7.20-0ubuntu0.17.10.1 all
mysql-client/artful,artful 5.7.19-0ubuntu1 all

To install version 5.7.19-0ubuntu1 of mysql-client, run:

sudo apt install mysql-client=5.7.19-0ubuntu1

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  mysql-client-5.7 mysql-client-core-5.7
The following NEW packages will be installed:
  mysql-client mysql-client-5.7 mysql-client-core-5.7
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,365 kB of archives.
After this operation, 65.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu artful-updates/main amd64 mysql-client-core-5.7 amd64 5.7.20-0ubuntu0.17.10.1 [6,938 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu artful-updates/main amd64 mysql-client-5.7 amd64 5.7.20-0ubuntu0.17.10.1 [2,417 kB]                                                                                     
Get:3 http://in.archive.ubuntu.com/ubuntu artful/main amd64 mysql-client all 5.7.19-0ubuntu1 [10.0 kB]                                                                                                            
Fetched 9,365 kB in 20s (468 kB/s)                                                                                                                                                                                
Selecting previously unselected package mysql-client-core-5.7.
(Reading database ... 197788 files and directories currently installed.)
Preparing to unpack .../mysql-client-core-5.7_5.7.20-0ubuntu0.17.10.1_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.20-0ubuntu0.17.10.1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.20-0ubuntu0.17.10.1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.20-0ubuntu0.17.10.1) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.7.19-0ubuntu1_all.deb ...
Unpacking mysql-client (5.7.19-0ubuntu1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up mysql-client-core-5.7 (5.7.20-0ubuntu0.17.10.1) ...
Setting up mysql-client-5.7 (5.7.20-0ubuntu0.17.10.1) ...
Setting up mysql-client (5.7.19-0ubuntu1) ...


Remove the package named mysql-client

sudo apt remove mysql-client

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  mysql-client-5.7 mysql-client-core-5.7
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-client
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 177 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 197837 files and directories currently installed.)
Removing mysql-client (5.7.19-0ubuntu1) ...

Delete the package nginx, and install the package lighttpd

sudo apt remove nginx lighttpd+

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream mysql-client-5.7 mysql-client-core-5.7 nginx-common nginx-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  gamin libgamin0 spawn-fcgi
Suggested packages:
  rrdtool php5-cgi apache2-utils lighttpd-doc
The following packages will be REMOVED:
  nginx
The following NEW packages will be installed:
  gamin libgamin0 lighttpd spawn-fcgi
0 upgraded, 4 newly installed, 1 to remove and 0 not upgraded.
Need to get 346 kB of archives.
After this operation, 1,238 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/universe amd64 libgamin0 amd64 0.1.10-5 [16.2 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 gamin amd64 0.1.10-5 [41.3 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 lighttpd amd64 1.4.45-1ubuntu1 [273 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 spawn-fcgi amd64 1.6.4-2 [14.9 kB]
Fetched 346 kB in 2s (122 kB/s)    
(Reading database ... 197833 files and directories currently installed.)
Removing nginx (1.12.1-0ubuntu2) ...
Selecting previously unselected package libgamin0.
(Reading database ... 197831 files and directories currently installed.)
Preparing to unpack .../libgamin0_0.1.10-5_amd64.deb ...
Unpacking libgamin0 (0.1.10-5) ...
Selecting previously unselected package gamin.
Preparing to unpack .../gamin_0.1.10-5_amd64.deb ...
Unpacking gamin (0.1.10-5) ...
Selecting previously unselected package lighttpd.
Preparing to unpack .../lighttpd_1.4.45-1ubuntu1_amd64.deb ...
Unpacking lighttpd (1.4.45-1ubuntu1) ...
Selecting previously unselected package spawn-fcgi.
Preparing to unpack .../spawn-fcgi_1.6.4-2_amd64.deb ...
Unpacking spawn-fcgi (1.6.4-2) ...
Processing triggers for ufw (0.35-5) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up spawn-fcgi (1.6.4-2) ...
Processing triggers for systemd (234-2ubuntu12.1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up gamin (0.1.10-5) ...
Setting up libgamin0 (0.1.10-5) ...
Setting up lighttpd (1.4.45-1ubuntu1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/lighttpd.service → /lib/systemd/system/lighttpd.service.
Processing triggers for libc-bin (2.26-0ubuntu2) ...
Processing triggers for systemd (234-2ubuntu12.1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for ufw (0.35-5) ...

See also