10 Examples of How to Use New Advanced Package Tool (APT) in Ubuntu/Debian


Ubuntu and Debian are two of the most popular Linux distributions available today, and they both use the Advanced Package Tool (APT) for package management. APT is a powerful tool that allows users to easily manage software installations, updates, and removals. In this article, we'll take a look at some examples of how to use APT in Ubuntu and Debian.

Updating the Package Cache

Before we dive into installing or updating packages, it's important to update the package cache first. The package cache is a list of all the available software packages that APT can install. To update the package cache, simply open a terminal and type the following command −

sudo apt update

This will download the latest package information from the software repositories and update the package cache.

Installing Packages

Installing packages in Ubuntu and Debian is a simple process. To install a package, simply use the following command −

sudo apt install package-name

For example, to install the popular text editor, Vim, we can use the following command −

sudo apt install vim

This will download and install the Vim text editor on your system. You can replace "vim" with the name of any other package you wish to install.

Updating Packages

Keeping your system up-to-date is essential for security and stability reasons. To update all installed packages on your system, use the following command −

sudo apt upgrade

This will download and install the latest versions of all the installed packages on your system. If a newer version is available, APT will upgrade the package.

Removing Packages

If you no longer need a package installed on your system, you can easily remove it using APT. To remove a package, use the following command −

sudo apt remove package-name

For example, to remove the Vim text editor we installed earlier, we can use the following command −

sudo apt remove vim

This will remove the Vim text editor from your system.

Purging Packages

When you remove a package using the "apt remove" command, it only removes the package files, leaving behind any configuration files. If you want to completely remove a package, including its configuration files, use the following command −

sudo apt purge package-name

For example, to completely remove the Vim text editor and its configuration files, we can use the following command −

sudo apt purge vim

This will remove the Vim text editor and any associated configuration files.

Searching for Packages

If you're looking for a particular package to install, you can use the "apt search" command to search the package cache. For example, to search for the Python programming language, use the following command −

sudo apt search python

This will display a list of all the packages related to Python.

Viewing Package Information

If you want to view information about a particular package, such as its version number or description, use the following command −

apt show package-name

For example, to view information about the Vim text editor, we can use the following command −

apt show vim

This will display detailed information about the Vim package.

Cleaning Up

Over time, APT can accumulate a lot of package cache files and other temporary files. To clean up these files and free up disk space, use the following command −

sudo apt autoclean

This will remove any package cache files that are no longer needed.

Here are some additional examples of how to use APT in Ubuntu and Debian −

Installing Multiple Packages

If you want to install multiple packages at once, you can simply list them all after the "apt install" command. For example, to install both the Vim and Nano text editors, you can use the following command −

sudo apt install vim nano

This will install both packages at once, saving you time and effort.

Upgrading a Single Package

If you only want to upgrade a specific package to its latest version, you can use the following command −

sudo apt install package-name

This will upgrade the specified package to its latest version, while leaving all other packages unchanged.

Installing Packages from a Specific Repository

If you want to install a package from a specific software repository, you can use the following command −

sudo apt install package-name/repository-name

For example, to install the latest version of the Firefox web browser from the Mozilla repository, you can use the following command −

sudo apt install firefox/mozilla

This will download and install the Firefox package from the Mozilla repository.

Installing a Package without its Dependencies

If you want to install a package without its dependencies, you can use the following command −

sudo apt install --no-install-recommends package-name

This will install the specified package, but exclude any recommended packages or dependencies that are not strictly required.

Removing Unused Packages

Over time, your system can accumulate a lot of unused packages that are no longer needed. To remove these packages and free up disk space, use the following command −

sudo apt autoremove

This will remove any packages that were automatically installed as dependencies for other packages, but are no longer required.

Adding a New Repository

If you want to install a package that is not available in the default repositories, you can add a new repository to your system. To add a new repository, create a file named "repository-name.list" in the /etc/apt/sources.list.d/ directory, and add the following line −

deb repository-url distribution component

Replace "repository-name" with a name for the repository, "repository-url" with the URL of the repository, "distribution" with the Ubuntu or Debian distribution codename, and "component" with the component of the repository (e.g. "main", "contrib", "non-free", etc.).

For example, to add the Docker CE repository to your system, create a file named "docker-ce.list" in the sources.list.d/ directory, and add the following line −

deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable

Save the file and run the following command to add the repository key −

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Finally, run the following commands to update the package cache and install Docker CE −

sudo apt update
sudo apt install docker-ce

APT will now use the new repository to install and update packages.

Conclusion

APT is a powerful package management tool that makes it easy to manage software installations, updates, and removals in Ubuntu and Debian. In this article, we covered some of the most common APT commands and their usage. By mastering these commands, you can take full advantage of APT's capabilities and keep your system up-to-date, secure, and efficient. With a little bit of practice and experimentation, you can become proficient in using APT to manage your software packages.

Updated on: 27-Apr-2023

315 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements