apt - Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

apt - command-line tool for handling packages

SYNOPSIS

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

DESCRIPTION

apt (Advanced Package Tool) is the command-line tool for handling packages. It provides a command-line interface for the package management of the system.

OPTIONS

COMMAND DESCRIPTION
list list is used to display a list of packages. It supports shell pattern for matching package names and the following options: --installed, --upgradable, --all-versions are supported.
search search searches for the given terms and display matching packages.
show show shows the package information for the given packages.
install install is followed by one or more package names desired for installation or upgrading.

A specific version of a package can be selected for installation by following the package name with an equals and the version of the package to select. This will cause that version to be located and selected for install. Alternatively a specific distribution can be selected by following the package name with a slash and the version of thee distribution or the archive name (stable, testing, unstable).

remove remove is identical to install to install except that packages are removed instead of installed. Note that removing a package leaves its configuration files on the system. If a plus sign is appended to the package name (with no intervening space), the indentified package will be installed instead of removed.
autoremove remove automatically all unused packages
Edit-sources edit-sources lets you edit your sources. List file and provides basic sanity checks.
update update is used to resynchronize the package index files from their sources.
upgrade upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. New package will be installed, but existing package will never removed.
full-upgrade full-upgrade performs the function of upgrade but may also remove installed packages if that is required in order to resolve a package conflict.
-h,--help Show a short usage summary.
-v,--version Show the program version.
-c,-config-file Configuration File; specify a configuration file to use. The program will read the default configuration file and then this configuration file. If configuration settings need to be set before the default configuration files are parsed specify a file with the APT-CONFIG environment variable.
-o,--option Set a Configuration Option; This will set a arbitrary configuration option. The syntax is –o Foo::Bar=bar. –o and –option can be used multiple times to set different option.

EXAMPLES

Example-1:

 To list all available/installed packages:

# apt list

output:
1 Listing...
2 0ad/trusty 0.0.15+dfsg-3 amd64
3 0ad-data/trusty 0.0.15-1 all
4 0ad-data-common/trusty 0.0.15-1 all
5 0ad-dbg/trusty 0.0.15+dfsg-3 amd64
6 0xffff/trusty 0.6~git20130406-1 amd64
7 2ping/trusty 2.0-1 all
-------------------------------------------------

-------------------------------------------------

-------------------------------------------------

47927 zynaddsubfx-dbg/trusty 2.4.3-4 amd64
47928 zynaddsubfx-dssi/trusty 2.4.3-4 amd64
47929 zynjacku/trusty 6-4 amd64
47930 zziplib-bin/trusty 0.13.62-2 amd64
47931 zzuf/trusty 0.13.svn20100215-4 amd64

Example-2:

To fetch package updates:

# apt update (it may ask for admin/root privillage, in case of ubuntu it is sudo apt update )

output:
[sudo] password: ********
Hit http://security.ubuntu.com trusty-security InRelease
Ign http://extras.ubuntu.com trusty InRelease
Hit http://ppa.launchpad.net trusty InRelease
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://ppa.launchpad.net trusty/main amd64 Packages
Hit http://security.ubuntu.com trusty-security/restricted Sources
Hit http://ppa.launchpad.net trusty/main i386 Packages
Hit http://security.ubuntu.com trusty-security/universe Sources
------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------
Hit http://in.archive.ubuntu.com trusty/universe Translation-en
Ign http://in.archive.ubuntu.com trusty/main Translation-en_IN
Ign http://in.archive.ubuntu.com trusty/multiverse Translation-en_IN
Ign http://in.archive.ubuntu.com trusty/restricted Translation-en_IN
Ign http://in.archive.ubuntu.com trusty/universe Translation-en_IN
Reading package lists... Done


Example-3:

To upgrade all packages currently installed on the system, run:
# apt upgrade (it may ask for admin/root privillage, in case of ubuntu it is sudo apt upgrade )

output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
libandroid-properties1 linux-headers-3.19.0-78
linux-headers-3.19.0-78-generic linux-image-3.19.0-78-generic
linux-image-extra-3.19.0-78-generic
The following packages will be upgraded:
apport apport-gtk apt apt-transport-https apt-utils bsdutils deja-dup
deja-dup-backend-gvfs firefox firefox-locale-en ghostscript ghostscript-x
gir1.2-gudev-1.0 init-system-helpers initramfs-tools initramfs-tools-bin
libapt-inst1.5 libapt-pkg4.12 libblkid1 libgs9 libgs9-common libgudev-1.0-0
After this operation, 317 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------------------------------
Setting up liboxideqtquick0:amd64 (1.19.4-0ubuntu0.14.04.1) ...
Setting up liboxideqt-qmlplugin:amd64 (1.19.4-0ubuntu0.14.04.1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Processing triggers for initramfs-tools (0.103ubuntu4.5) ...
update-initramfs: Generating /boot/initrd.img-3.19.0-78-generic
Software catalog update was successful.
Done

Example-4:

To update and upgrade packages at same time:

Simply type the following two commands to apply all security and package updates:
# sudo apt update && sudo apt upgrade

Example-5:

To see the list of packages that can be upgraded on the system, enter:

# apt list –upgradable

output:

Listing... Done
apport/xenial,xenial 2.20.1-0ubuntu1 all [upgradable from: 2.20-0ubuntu3]
bsdutils/xenial 1:2.27.1-6ubuntu2 amd64 [upgradable from: 1:2.27.1-6ubuntu1]
dbus/xenial 1.10.6-1ubuntu3 amd64 [upgradable from: 1.10.6-1ubuntu2]
dmeventd/xenial 2:1.02.110-1ubuntu8 amd64 [upgradable from: 2:1.02.110-1ubuntu7]
dmsetup/xenial 2:1.02.110-1ubuntu8 amd64 [upgradable from: 2:1.02.110-1ubuntu7]
ethtool/xenial 1:4.5-1 amd64 [upgradable from: 1:4.2-1]

 

Example-6:

To perform full system upgrade:

The full-upgrade command performs the function of upgrade but will remove currently installed packages if this is needed to upgrade the system as a whole.

# apt full-upgrade

output:

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:
libntdb1 python-ntdb
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Example-7:

To install  new packages:

To install a new package called (say) nginx, enter:
# apt install {pkgNameHere}
# apt install nginx

output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libntdb1 python-ntdb
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
nginx-common nginx-core
Suggested packages:
fcgiwrap nginx-doc
The following NEW packages will be installed:
nginx nginx-common nginx-core
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.

Example-8:

To remove a package:

To delete or remove a package called nginx, enter:
# apt remove {pkgNameHere}
# apt remove nginx

output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libntdb1 nginx-common nginx-core python-ntdb
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
nginx
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 96.3 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 205202 files and directories currently installed.)
Removing nginx (1.4.6-1ubuntu3.7) ...

Example-9:

 To remove both package and config files

Removing a package removes all packaged data, but leaves usually small (modified) user configuration files behind, in case the remove was an accident. Just issuing an installation request for the accidentally removed package will restore its function as before in that case. On the other hand you can get rid of these leftovers by calling purge even on already removed packages:

# apt purge {pkgNameHere}

# apt purge nginx

output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libntdb1 nginx-common nginx-core python-ntdb
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
nginx*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 96.3 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 205202 files and directories currently installed.)
Removing nginx (1.4.6-1ubuntu3.7) ...

Example-10:

The autoremove option

The autoremove option is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed as dependencies changed or the package(s) needing them were removed in the meantime. For example, when you upgrade Linux kernel to 4.1.5, you may not need Linux kernel version 3.8.5. The syntax is: # apt autoremove

output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libntdb1 nginx-common nginx-core python-ntdb
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
After this operation, 1,393 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 205197 files and directories currently installed.)
Removing python-ntdb (1.0-2ubuntu1) ...
Removing libntdb1:amd64 (1.0-2ubuntu1) ...
Removing nginx-core (1.4.6-1ubuntu3.7) ...
Removing nginx-common (1.4.6-1ubuntu3.7) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...


Example-11:

To search packages

The search option can be used to search for the given regex. To search for php packages, enter:
	# apt search php
	# apt search mysql-5.?
	# apt search mysql-server-5.?
	# apt search httpd*
	# apt search ^apache
	# apt search ^nginx
	# apt search ^nginx$

Example-12:

To find info about packages

To show or see information about the given package(s) including its dependencies, installation and download size, sources the package is available from, the description of the packages content and much more:
# apt show {pkgNamehere}
# apt show nginx

output:
Package: nginx
Priority: optional
Section: web
Installed-Size: 96.3 kB
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Kartik Mistry <kartik@debian.org>
Version: 1.4.6-1ubuntu3.7

Example-13:

To List specific packages

To list all packages, enter:
# apt list | grep foo
# apt list | grep php7-

output:

WARNING: apt does not have a stable CLI interface yet. Use with caution in scripts.

bygfoot/trusty 2.3.2-1.1 amd64
bygfoot-data/trusty 2.3.2-1.1 all
foo-yc20/trusty 1.3.0-6 amd64
foobillard/trusty 3.43~svn170+dfsg-1 all
foobillardplus/trusty 3.43~svn170+dfsg-1 amd64
foobillardplus-data/trusty 3.43~svn170+dfsg-1 all

 

Note: examples are given here are run as root user, if normal user use sudo i.e $ sudo "command options"


Previous Page
Next Page