APT is an acronym for Advanced Packaging Tool. It is an easy-to-use feature-rich software management tool that works on Debian Based Linux distributions (e.g. Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, Debian 8, Debian 9, etc). APT was first released in 1998 and a Debian version that included it by default saw the light the following year.
APT simplifies the process of installing, removing and upgrading packages through the Command Line Interface (CLI). The Debian project maintains a central repository with over 25,000 packages that can be downloaded and installed on your Linux system.
With its automated retrieval, configuration and installation of software packages, APT is considered to be one of the best Debian features. APT works by querying a software repository (networked or in a CD ROM location) to find packages and dependencies required.
In this article, we will show you how to find, install, remove and upgrade software packages on your Debian based Linux machines hosted on Alibaba Cloud Elastic Compute Service (ECS).
Locate the public IP address associated with your Alibaba Cloud ECS instance on the console and use it to connect to your server. You will need to provide a non-root username and password to continue.
You may establish an SSH connection through the built-in command line tool if you are running macOS or Linux on your local computer. If you are using Windows, consider downloading PuTTY SSH client.
Managing applications using APT commands on your Linux system requires superuser privileges apart from the search command. So we will run all commands using sudo.
To display information about installable packages, use the apt-cache command. The information about the packages is obtained from different sources and stored in a local database. The cache is updated during the apt-get update operation.
Run the command as shown below to list available packages:
$ apt-cache pkgnames
... tomcat8-examples libignition-transport4-dev liblrmd1 liblualib50 python3-prelude libvtkgdcm-tools libtree-simple-visitorfactory-perl libfontenc1-dbg libnet-abuse-utils-perl node-source-map-support libewf-dbg bhl ...
The apt-cache pkgnames is too basic and returns a lot of results. A more elegant way is to use the apt-cache command alongside a keyword to filter results using the syntax below:
$ sudo apt-cache search [keyword]
$ sudo apt-cache search mysql-server
mysql-server - MySQL database server (metapackage depending on the latest version) mysql-server-5.7 - MySQL database server binaries and system database setup mysql-server-core-5.7 - MySQL database server binaries default-mysql-server - MySQL database server binaries and system database setup (metapackage) default-mysql-server-core - MySQL database server binaries (metapackage) mariadb-server-10.1 - MariaDB database server binaries mariadb-server-core-10.1 - MariaDB database core server files percona-xtradb-cluster-server-5.7 - Percona XtraDB Cluster database server binaries
In case you don't get any results, it means the package information is not available or you haven't update the package list using apt-get update command. We will see this command later in the guide.
You can display more information about a package using the apt-cache show command. This displays the version number, maintainer, bugs, filename, size and description. For instance, to display more information about mysql-server package, run the command below:
$ apt-cache show mysql-server
Package: mysql-server Architecture: all Version: 5.7.23-0ubuntu0.18.04.1 Priority: optional Section: database Source: mysql-5.7 Origin: Ubuntu Maintainer: Ubuntu Developers <firstname.lastname@example.org> Original-Maintainer: Debian MySQL Maintainers <email@example.com> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 107 Depends: mysql-server-5.7 Filename: pool/main/m/mysql-5.7/mysql-server_5.7.23-0ubuntu0.18.04.1_all.deb Size: 9940 MD5sum: 5924d9a404e932a26ba81aee5023c741 SHA1: b440e27d9522a63b7a7de1bc02ced943cc234a7f SHA256: a1b90faa3dce9dda6bdb9a25d4e2a40b2ba0a5de5953348444591dc842958661 Homepage: http://dev.mysql.com/ Description-en: MySQL database server (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mysql-server (currently mysql-server-5.7), as determined by the MySQL maintainers. Install this package if in doubt about which MySQL version you need. That will install the version recommended by the package maintainers. . MySQL 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 MySQL are speed, robustness and ease of use. Description-md5: b8b44aa3bf1e86bb2834ded6d9d869b5 Task: lamp-server Supported: 5y
To ensure you have the latest package list or index, use the apt-get update command. Please note, this command does not update the software installed on your system as its name suggests.
It simply synchronizes the installable packages index to ensure that you have the newest information should you need to install any application. Indexes about available information are read from the /etc/apt/sources.list file.
Always run this command before installing or upgrading an application as shown below:
$ sudo apt-get update
Ign:1 http://mirrors.cloud.aliyuncs.com/debian stretch InRelease Get:2 http://mirrors.cloud.aliyuncs.com/debian stretch-updates InRelease [91.0 kB] Get:3 http://mirrors.cloud.aliyuncs.com/debian stretch-proposed-updates InRelease [96.3 kB] Get:4 http://mirrors.cloud.aliyuncs.com/debian stretch-backports InRelease [91.8 kB] Get:5 http://mirrors.cloud.aliyuncs.com/debian-security stretch/updates InRelease [94.3 kB] Get:6 http://mirrors.cloud.aliyuncs.com/debian stretch Release [118 kB] Get:7 http://mirrors.cloud.aliyuncs.com/debian stretch Release.gpg [2,434 B] Get:8 http://mirrors.cloud.aliyuncs.com/debian stretch-updates/main Sources [3,752 B] Get:9 http://mirrors.cloud.aliyuncs.com/debian stretch-updates/main amd64 Packages [5,148 B] ... Get:40 http://mirrors.cloud.aliyuncs.com/debian stretch/contrib amd64 Packages [50.9 kB] Get:41 http://mirrors.cloud.aliyuncs.com/debian stretch/contrib Translation-en [45.9 kB] Get:42 http://mirrors.cloud.aliyuncs.com/debian stretch/non-free amd64 Packages [78.7 kB] Get:43 http://mirrors.cloud.aliyuncs.com/debian stretch/non-free Translation-en [80.6 kB] Fetched 22.2 MB in 5s (4,344 kB/s) Reading package lists... Done
Once you ensure the package information index is up-to-date by running apt-get update, you can install any package of your choice by running the apt-get install command.
You can install multiple packages in one command or install the software one by one. Use the syntax below:
$ sudo apt-get install [package name 1] [package name 2] [package name 3] [package name n...]
Here are some of the most popular packages that you can install on your Debian based Linux system using the apt command.
$ sudo apt-get install apache2
$ sudo apt-get install php
$ sudo apt-get install mysql-server
$ sudo apt-get install postfix
Press Y and hit Enter when prompted to confirm the installation of new packages.
The apt-get upgrade command installs newer versions of the current installed packages on your system. As we indicated earlier, you must update the package information list before upgrading any packages so that APT can enumerate sources of new packages from /etc/apt/sources.list.
To upgrade the packages, use the command below. Please note, this command will never remove or install new packages. it will simply update the currently installed packages.
$ sudo apt-get upgrade
Press Y and hit Enter when prompted to confirm the upgrade.
An upgrade may take a few minutes to complete, so it is advisable to run it when the system is not busy.
You can also use apt-get dist-upgrade to upgrade the package list but this command is more advanced because it changes package dependencies with a smart conflict resolution method. Please note, this command may remove or install new packages to satisfy dependencies.
$ sudo apt-get dist-upgrade
So here is the difference between apt-get upgrade and apt-get dist-upgrade:
If an upgrade is run, new packages are never installed neither are old packages removed to satisfy dependencies, it simply changes the versions of existing packages. However, a dist-upgrade may install new packages and remove others to resolve dependencies issues.
APT has great commands for removing packages and cleaning temporary installation files on your system.
You can use the apt-get remove command to remove packages from your Debian based system. Here is the syntax for the command:
$ sudo apt-get remove [package name]
$ sudo apt-get remove php
Please note, the above command will uninstall the package but leave the configuration files, data files and dependency information intact. To remove everything about a package apart from the dependency packages, use the apt-get purge or apt-get remove --purge commands.
$ sudo apt-get purge [package name]
$ sudo apt-get remove --purge [package name]
$ sudo apt-get purge php
$ sudo apt-get remove --purge php
Press Y and hit Enter when prompted to confirm the uninstallation process.
To remove orphaned packages, use the apt-get autoremove command shortly after uninstalling software. This will ensure that packages that worked as dependencies for other applications but are no longer required are removed from your system.
$ sudo apt-get autoremove
To clean your system and free some disk space after installing packages, use the apt-get clean command. This will ensure that the retrieved deb package files are deleted from your system after installation.
This command may free up a substantial disk space on your server. For instance, a du command shows deb files may take disk space in the ranges of hundreds of megabytes:
$ sudo du /var/cache/apt/archives/ -h
4.0K /var/cache/apt/archives/partial 214M /var/cache/apt/archives/
Use the command below to reclaim the space and delete the temporary files:
$ sudo apt-get clean
We have taken you through the steps of searching, updating, installing, upgrading and removing packages on your Linux System through APT commands. This guide will help you to better manage the software applications running on your Alibaba Cloud Linux server based on the Debian platform.
It will also ensure that you have the latest software with new features and bug fixes. If you are new to Alibaba Cloud, Signup and enjoy up to $300 worth of credit to test over 40 products including ECS instances running Debian based Linux distributions that support apt commands.
Alibaba Clouder - December 24, 2018
Alibaba Clouder - February 13, 2018
Alibaba Clouder - June 4, 2018
Alibaba Clouder - October 1, 2018
Alibaba Clouder - January 2, 2019
Alibaba Clouder - June 13, 2018
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
Powerful parallel computing capabilities based on GPU technology.Learn More
Resource management and task scheduling for large-scale batch processingLearn More
Super Computing Service provides ultimate computing performance and parallel computing cluster services for high-performance computing through high-speed RDMA network and heterogeneous accelerators such as GPU.Learn More
More Posts by francisndungu