20 Useful ‘apt-get’ Commands for Ubuntu Package Management

Introduction

The apt-get command is a powerful command-line tool used to work with Ubuntu’s Advanced Packaging Tool (APT) system. It is used to install, remove, and manage packages in the Ubuntu operating system. It is a great tool for managing packages and can be used to quickly and easily install, update, and remove packages. In this article, we will discuss 20 useful apt-get commands for Ubuntu package management. We will cover how to install, update, and remove packages, as well as how to search for packages and view package information. We will also discuss how to use apt-get to manage repositories and how to use apt-get to upgrade the entire system. By the end of this article, you will have a better understanding of how to use apt-get to manage packages in Ubuntu.

20 Useful ‘apt-get’ Commands for Ubuntu Package Management

1. apt-get update: Update the list of available packages and their versions.

2. apt-get upgrade: Upgrade all installed packages to their latest versions.

3. apt-get install: Install a package from the repository.

4. apt-get remove: Remove a package from the system.

5. apt-get autoremove: Remove packages that were installed as dependencies but are no longer needed.

6. apt-get purge: Completely remove a package and its configuration files.

7. apt-get search: Search for a package in the repository.

8. apt-get clean: Clean up the local repository of downloaded package files.

9. apt-get check: Verify that all packages are up to date.

10. apt-get source: Download the source code of a package.

11. apt-get build-dep: Install the build dependencies for a package.

12. apt-get dist-upgrade: Upgrade the system by installing/removing packages if necessary.

13. apt-get dselect-upgrade: Follow the instructions of dselect to upgrade the system.

14. apt-get autoclean: Remove old package files from the local repository.

15. apt-get moo: Display an ASCII cow.

16. apt-get help: Display a help message.

17. apt-get changelog: Display the changelog of a package.

18. apt-get show: Display detailed information about a package.

19. apt-get download: Download a package without installing it.

20. apt-get -f install: Fix broken packages and install them.
[ad_1]

The apt-get command was the primary package management command used in Debian-based Linux distributions prior to the introduction of the apt command.

With the apt-get command, you could install, remove, upgrade, search, and manage packages on your system. However, starting from Ubuntu 16.04 and Debian 9, the apt command became the recommended command-line tool for package management, although apt-get is still available and functional.

What is apt-get Command?

The apt-get command is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform the installation of new software packages, removing existing software packages, upgrading of existing software packages, and even used to upgrading the entire operating system.

The syntax for the apt-get command is as follows:

$ sudo apt-get <options> <command>

Here, <options> represent any additional flags or modifiers you can use with the command, and <command> specifies the action you want to perform, such as installing, upgrading, removing, or searching for packages.

1. Update Ubuntu System Packages

The ‘update‘ command is used to resynchronize the package index files from the sources specified in /etc/apt/sources.list file. The update command fetched the packages from their locations and update the packages to newer versions.

$ sudo apt-get update
Update Ubuntu Packages
Update Ubuntu Packages

2. Upgrade Ubuntu System Packages

The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages that are not already installed neither retrieved nor installed to satisfy upgrade dependencies.

$ sudo apt-get upgrade
Upgrade Ubuntu Packages
Upgrade Ubuntu Packages

3. Install Package in Ubuntu

The ‘install‘ sub command is tracked by one or more packages wishing for installation or upgrading from the repositories. For example, to install or update the package named wget, you can run:

$ sudo apt-get install wget
Install Package in Ubuntu
Install Package in Ubuntu

Alternatively, you can also use the apt-cache command to search for a package before installing in the system package cache based on a given search term such as name or description.

4. Install Multiple Packages in Ubuntu

You can add more than one package name along with the command in order to install multiple packages at the same time. For example, the following command will install packages ‘nethogs‘ and ‘goaccess‘.

$ sudo apt-get install nethogs goaccess
Install Multiple Packages in Ubuntu
Install Multiple Packages in Ubuntu

5. Install Several Packages Using Wildcard

With the help of regular expression, you can add several packages with one string. For example, we use * wildcard to install several packages that contain the ‘*name*‘ string, the name would be ‘package-name‘.

$ sudo apt-get install '*name*'
Install Package Using Wildcard in Ubuntu
Install Package Using Wildcard in Ubuntu

6. Install Package Without Upgrading

Using sub ‘--no-upgrade‘ command will prevent already installed packages from upgrading.

$ sudo apt-get install packageName --no-upgrade
Install Package Without Updating
Install Package Without Updating

7. Update a Single Package

The ‘--only-upgrade‘ command does not install new packages but it only upgrades the already installed packages and disables new installation of packages.

$ sudo apt-get install packageName --only-upgrade
Update Single Package in Ubuntu
Update Single Package in Ubuntu

8. Install Specific Package Version on Ubuntu

Let’s say you wish to install only specific versions of packages, simply use the ‘=‘ with the package name and append desired version.

$ sudo apt-get install vsftpd=3.0.5-0ubuntu1
Install Specific Version of Package
Install Specific Version of Package

9. Uninstall Package Without Configuration

To uninstall software packages without removing their configuration files (for later re-use of the same configuration), use the remove command as shown.

$ sudo apt-get remove vsftpd
Remove Package Without Configuration in Ubuntu
Remove Package Without Configuration in Ubuntu

10. Completely Remove Package with Configuration

To remove software packages including their configuration files, use the ‘purge‘ sub-command as shown below.

$ sudo apt-get purge vsftpd
Remove Package With Configuration in Ubuntu
Remove Package With Configuration in Ubuntu

Alternatively, you can combine both commands together as shown below.

$ sudo apt-get remove --purge vsftpd

11. Clear Apt Cache to Save Disk Space

The ‘clean‘ command is used to free up the disk space by cleaning retrieved (downloaded) .deb files (packages) from the local repository.

$ sudo apt-get clean
OR
$ sudo apt-get autoclean
Clear Apt Cache
Clear Apt Cache

12. Download Source Code of a Package in Ubuntu

To download only the source code of a particular package, use the option ‘--download-only source‘ with ‘package-name‘ as shown.

$ sudo apt-get --download-only source vsftpd
Download Package Source Code in Ubuntu
Download Package Source Code in Ubuntu

13. Download and Extract Source Package in Ubuntu

To download and unpack the source code of a package to a specific directory, type the following command.

$ sudo apt-get source vsftpd
Download and Extract Source Package
Download and Extract Source Package

14. Compile Ubuntu Package from Source

You can also download, unpack and compile the source code at the same time, using the option ‘--compile‘ as shown below.

$ sudo apt-get --compile source goaccess
Compile Package from Source in Ubuntu
Compile Package from Source in Ubuntu

15. Download Package Without Installing

Using the ‘download‘ option, you can download any given package without installing it. For example, the following command will only download the ‘nethogs‘ package to the current working directory.

$ sudo apt-get download nethogs
Download Package Without Installing
Download Package Without Installing

16. View Package Changelog in Ubuntu

The ‘changelog‘ flag downloads a package change-log and shows the package version that is installed.

$ sudo apt-get changelog vsftpd
Check Package Changelog in Ubuntu
Check Package Changelog in Ubuntu

17. View Broken Dependencies in Ubuntu

The ‘check‘ command is a diagnostic tool, which is used to update the package cache and check for broken dependencies.

$ sudo apt-get check
Check Package Broken Dependencies
Check Package Broken Dependencies

18. Install Build Dependencies of Package

The ‘build-dep‘ command searches the local repositories in the system and installs the build dependencies for the curl package. If the package does not exist in the local repository it will return an error code.

$ sudo apt-get build-dep curl
Install Build Dependencies of Package
Install Build Dependencies of Package

19. Auto Remove Installed Packages

The ‘autoremove‘ sub-command is used to auto-remove packages that were certainly installed to satisfy dependencies for other packages but were now no longer required. For example, the following command will remove an installed package with its dependencies.

$ sudo apt-get autoremove vsftpd
Auto Remove Packages
Auto Remove Packages

20. apt-get Command Help

The apt-get help command displays the built-in help documentation with the available options to use with the apt-get command.

$ sudo apt-get help
apt-get Command Help
apt-get Command Help

I’ve covered most of the available options with the apt-get command, but still, there are more options available, you can check them out using ‘man apt-get‘ from the terminal.

I hope you enjoyed reading this article, If I’ve missed anything and you would like me to add to the list. Please feel free to mention this in the comment below.

Read Also : 20 Useful Linux YUM Commands for Package Management

[ad_2]

20 Useful ‘apt-get’ Commands for Ubuntu Package Management

Ubuntu is a popular Linux distribution that is based on Debian. It is widely used for its ease of use and its powerful package management system. The apt-get command is the most popular package management tool for Ubuntu. It is used to install, remove, and update packages on Ubuntu systems.

In this article, we will discuss some of the most useful apt-get commands for Ubuntu package management. We will also discuss some of the common options and arguments that can be used with apt-get.

1. Update the Package List

The first command that you should run when managing packages on Ubuntu is the apt-get update command. This command will update the list of available packages from the repositories. It is important to run this command before installing or upgrading packages.

$ sudo apt-get update

2. Upgrade Packages

The apt-get upgrade command is used to upgrade all the installed packages to their latest versions. This command will download and install the latest versions of the packages from the repositories.

$ sudo apt-get upgrade

3. Install Packages

The apt-get install command is used to install packages on Ubuntu. You can specify the package name after the install command to install a specific package. You can also specify multiple packages to install multiple packages at once.

$ sudo apt-get install [package_name]

4. Remove Packages

The apt-get remove command is used to remove packages from Ubuntu. You can specify the package name after the remove command to remove a specific package. You can also specify multiple packages to remove multiple packages at once.

$ sudo apt-get remove [package_name]

5. Search for Packages

The apt-cache search command is used to search for packages in the repositories. You can specify a keyword after the search command to search for packages that contain the keyword in their name or description.

$ apt-cache search [keyword]

6. Show Package Information

The apt-cache show command is used to show information about a package. You can specify the package name after the show command to show information about the package.

$ apt-cache show [package_name]

7. Download Packages

The apt-get download command is used to download packages from the repositories. You can specify the package name after the download command to download a specific package. You can also specify multiple packages to download multiple packages at once.

$ sudo apt-get download [package_name]

8. Clean Up Packages

The apt-get autoclean command is used to clean up packages that are no longer needed. This command will remove packages that were downloaded but are no longer needed.

$ sudo apt-get autoclean

9. Clean Up Cached Packages

The apt-get autoremove command is used to clean up cached packages. This command will remove packages that were downloaded but are no longer needed.

$ sudo apt-get autoremove

10. Show Package Dependencies

The apt-cache depends command is used to show the dependencies of a package. You can specify the package name after the depends command to show the dependencies of the package.

$ apt-cache depends [package_name]

11. Show Package Reverse Dependencies

The apt-cache rdepends command is used to show the reverse dependencies of a package. You can specify the package name after the rdepends command to show the reverse dependencies of the package.

$ apt-cache rdepends [package_name]

12. Show Package Files

The dpkg -L command is used to show the files of a package. You can specify the package name after the -L command to show the files of the package.

$ dpkg -L [package_name]

13. Show Package Version

The apt-cache policy command is used to show the version of a package. You can specify the package name after the policy command to show the version of the package.

$ apt-cache policy [package_name]

14. Show Package Source

The apt-cache showsrc command is used to show the source of a package. You can specify the package name after the showsrc command to show the source of the package.

$ apt-cache showsrc [package_name]

15. Show Package Maintainer

The apt-cache showpkg command is used to show the maintainer of a package. You can specify the package name after the showpkg command to show the maintainer of the package.

$ apt-cache showpkg [package_name]

16. Show Package Contents

The dpkg -c command is used to show the contents of a package. You can specify the package name after the -c command to show the contents of the package.

$ dpkg -c [package_name]

17. Show Package Configuration

The dpkg -p command is used to show the configuration of a package. You can specify the package name after the -p command to show the configuration of the package.

$ dpkg -p [package_name]

18. Show Package Status

The dpkg -s command is used to show the status of a package. You can specify the package name after the -s command to show the status of the package.

$ dpkg -s [package_name]

19. Show Package List

The dpkg -l command is used to show the list of packages. You can specify a keyword after the -l command to show the list of packages that contain the keyword in their name or description.

$ dpkg -l [keyword]

20. Show Package List with Versions

The dpkg -l command is used to show the list of packages with their versions. You can specify a keyword after the -l command to show the list of packages with their versions that contain the keyword in their name or description.

$ dpkg -l [keyword]

These are some of the most useful apt-get commands for Ubuntu package management. We have discussed some of the common options and arguments that can be used with apt-get. We hope this article has been helpful in understanding apt-get and Ubuntu package management.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00