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
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
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
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
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*'
6. Install Package Without Upgrading
Using sub ‘--no-upgrade
‘ command will prevent already installed packages from upgrading.
$ sudo apt-get install packageName --no-upgrade
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
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
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
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
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
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
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
You may encounter one common error “E: You must put some ‘deb-src’ URIs in your sources.list” when attempting to download the source code of a package from the repositories.
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
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
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
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
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
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
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
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
I installed a package by compiling it and using checkinstall. The package name is different from the Ubuntu packages. It is actually an all-in-one package.
Other packages depend on those other named packages. I want to set those packages as being installed, but not actually install any files.
(They are already there) So I am wondering if there is a way to just change the package database to say that a given package is installed.
What’s the command for getting apt-utils it is telling me that I need to install it can someone please help me?
@Heather,
You can install apt-utils on your Debian system using the following command.
How can I see the installed package in my system?
@Rahul,
Run the following command to list all installed packages on the Ubuntu system
this is my “daily” check and upgrade command:
$ sudo apt-get update && sudo apt-get upgrade && sudo apt-get full-upgrade && sudo apt-get check && sudo apt-get -f install && sudo apt-get -y clean && sudo apt-get -y autoclean && sudo apt-get autoremove && sudo dpkg --configure -a && sudo apt --fix-broken install
Try these commands to update and fix Ubuntu…
$ sudo apt update
$ sudo apt upgrade
$ sudo apt full-upgrade
$ sudo apt dist-upgrade
$ sudo apt-get check
$ sudo apt -f install
$ sudo apt -y clean
$ sudo apt -y autoclean
$ sudo apt autoremove
$ sudo dpkg --configure -a
$ sudo apt --fix-broken install --fix-missing
Can you share some information about apt-cache implementation? I couldn’t find anywhere.
How the cache is created, refreshed (is it periodic, once a day or manual). As far as I read, the cache is refreshed manually.
Assuming there is one package that has the new version, how does apt-cache updates its cache? Does the apt-cache send the current cache information ( like the list of pkg names and it’s version) to server then the server sends what has changed?
Hi, How can i search through installed applications ? In particular I want to search with a keyword in both package name and description for installed package?
apt-cache search --installed
keyword does not work.@Sansu,
You can use the following command to search for a particular packages, for example apache in this case.
Sorry if I was not clear. I specifically need to look into list of packages that are installed in my system.
will list all the packages available but i need only those which are installed in my system.
Instead of using the CLI tool ‘apt-cache’. use the GUI tool, Synaptic. When you search for ‘apache’, Synaptic will display on one screen all packages with ‘apache’ in the name or the description, and whether they are installed or not.
I work in many places offline (no Internet access). I had to use apt clean to fix a bad installation issue, and don’t know how to download again all the
.deb
files again, which I used in my installation, since I usually need to reinstall packages that I need from offline places.So how do I re-download all
.deb
files that were installed on my system (official and ppa repositories) ?If there a apt-cache –only-download “all-installed” type of command ?
I am still using trusty 14.04.5 (64 bits) here.
@John,
This following command will download all installed packages to directory /var/cache/apt/archives.
$ sudo dpkg -l | grep "^ii"| awk ' {print $2} ' | xargs sudo apt-get -y install --reinstall --download-only
Is there any way to check met/unmet dependencies of package? What I mean is, if I wanted to install some package then I wan to check its dependencies and see which are already met and first of all which are required to download and install?
For example:
is showing only dependencies but how do I know which packages are already installed and which are not?
@Tansy,
There is no such command that will display a installed packages of a dependencies, the only way is to list all installed packages using following command in Ubuntu.
Perfect. It helped me a lot.
how do i become an expert in Linux and UNIX operating system?
@Juuko,
If you want to be a expert in Linux, then you should take one of these courses here: https://www.tecmint.com/linux-online-training-courses/
I want to be a database administrator but how can u help me
My husband has always carried out all the maintenance, unfortunately he is very ill and cannot help me. I am trying to use the
'sudo apt-get clean'
command in the terminal, I type it in, hit enter, it asks for the password I enter that and the same line comes up (bronwyn@bronwyn-Lenovo-ideapad-100-141BY:~$) and nothing happens. What am I doing wrong?@Bronwyn,
Running
sudo apt-get clean
command will remove all the local packages that you’ve download during the package installation, the downloaded files resides under/var/cache/apt/archives
directory, it seems empty in your case..But this is not the only place, where huge amount of disk space wasted, there are other places such as:
/var/log directory contains all the system logs, you may want to remove these logs or you can use log-rotation program to lower the amount of logs saved and archived.
Read more here: https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/
Your own
Trash
directory may be full of files that can be purged on regular time.If you still want to clean more space , you can use bleachbit program, read more here: https://www.tecmint.com/bleachbit-a-free-disk-space-cleaner-and-privacy-guard-for-linux-systems/
Hi Ravi, Thank you for that information. I checked in my Package Manager and it informs me that I have log-rotation already installed. I installed the bleachbit program, then ran the software updater and it still tells me that I need to clear at least 19.9M of space for a 76m update. Is there something else I can try?
Bronwyn
@Bronwyn,
Nothing to worry, just run bleachbit every month twice to clear unwanted downloaded packages and files to clear space…
Hi Sir, how to get remote desktop in Ubuntu and windows 7
@Subindas,
You can use VNC application to access any remote Desktop machine, as explained in this article..
https://www.tecmint.com/vnc-desktop-access-from-web-browser/
How do I only update amd64 architecture. I tried sudo apt-get update -a=amd64 and it doesn’t work.
page is broken while printing
when i type apt-cache pkgnames it says -bash: apt-cache: command not found. Please advise
@Uday,
You failed to add ‘search‘ to apt-cache command, the right way to do is:
you should type sudo apt-get
This is outdated now. You can just use the apt command.
@Luca,
It’s not outdated or not depreciated, the introduce of APT new tool is to reduce some extra work, here is the complete guide on how to use new APT tool on Debian/Ubuntu systems with 15 practical examples https://www.tecmint.com/apt-advanced-package-command-examples-in-ubuntu/
You missed one command that can be useful at times, the ‘sudo apt-get install -f ‘ command
@Peter,
Thanks for the tip, we will include this command to list as per your suggestion..
somebody help me i want to install all package through apt-get command without cd / dvd but when i am trying to install is always asking cd / dvd i want all package and dependency install through apt. i am using debian linux . if it’s possible
This is literally the most useful thing. Ever.
Thank you that was very useful!
The best article and tips I’ve seen in a long time !
Thank you
Great article. Thanks!
I’m trying to get the installed packages/softwares from corporate ubuntu machines using apt –installed list or dpkg commands.
Can you pls help how to do it?
This is excellent. Thank you for creating this guide :)
After digesting this article, I can do ubuntu system management with confidence!
A huge THANK YOU!
Just to say “THANK YOU”, i have search all over the net after a solution to fix my broken depencies….and after tried 40 commands on my terminal (i am on Lubuntu 64-bits), and 2 hours of hell… I found your website…
Without conviction, i have type in my term : “sudo apt-get autoremove libatk-wrapper-java”
And it works, it solves my problem…. So thank you, because, i will not have to format, back up and restore my data, it was my last solution.
@Jipe
That’s really great…you saved your hell of time…:)
apt-get download will download a deb package. I need to use this to download package files for another computer that is not on the internet. However, the computer where I can download is a 64-bit (amd64) while the one for which I need the package is i386. How do I specify the architecture? The options -a and –host-architecture are listed in the man pages but they do not seem to work and seem intended only for source compilation.
Hi Ravi,
How to search for a particular package through apt-get? I am looking for a functionality like yum search Can we do a similar search in ubuntu?
Yes, you can use ‘apt-cache’ command to search for the packages before installing them. For example,
How do i upgrade a pc manually? I have the *.deb packages in my /../archive folder on a pc that does not have net access. I copied them from a pc on the net.
is there an apt-get command? Do i have to update my package list manually?
thankx for a good site.
The commands to restore the system to a certain point(Time) or the point of last update.
Guys can you tell me the Fedora equivalent of these commands
Ravi Saive,
It is very useful quick reference, I have Bookmarked it.
Thank you.
Dear Ajay,
Thanks for bookmarking our site, and if possible please share with your friends. Let us spread…
Excellent site for reference, very intuitive and easy to read!
Thanks!
Excellent compilation of commands. Found this page very useful.
Good job! thanks! :)
I have recently upgraded ubuntu 13.10. Now when I run the command sudo apt-get autoremove my system wants to remove 4 packages starting with Linux.1.11 and something. I remember that these were the last packages which were downloaded and installed in my system.
My question is can I repack these packages and store in another file for future use without removing completely. So that If my system asks me to install them again during upgrade I can just install them manually.
Is there any way to do so. Kindly let me know.
Rajesh
Yes, you can backup/restore your packages for future use. This can be done using Aptik utility.
Two very handy and useful commands are:
apt-cache depends
which shows the package dependencies and
apt-cache rdepends
which shows packages depending on (reverse depends)
When I ran debian & debian based distro’s I always used aptitude for installing packages & upgrades as well as searches, yes I know ubuntu removed it!
apt-get has some great uses (–compile) but I found aptitude was far better & more intelligent in it’s responses.
In the wrong hands apt-get can brick a system but aptitude appears to be “aware of your actions & the outcome”
very useful information. I learn two new things
–no-upgrade
–only-upgrade
apt-get source –compile
Thank you for a very useful reference! I will be using this for some time to come!!
I really liked the way this article presented the information. I saved it for future use. Well written.
Number 10 should be quoted:
$ sudo apt-get install ‘*name*’
Otherwise the shell will attempt to expand those wildcards using the file names in the current directory. A lot of the time, that won’t be an issue, because the fallback when there is no matching file name is to pass the unexpanded string to the command.
Thanks corrected.
You miss ” apt-get install -f ”
for fix dependencies from offline installer like sample from Malmasa in above.
Trims
Oh yeah, I forget. I wanna ask you:
How to track dependency of 1 application in cache (/var/cache/apt/archives)? I wanna take only 1 application completely into one folder to install in another computers (sudo dpkg -i *.deb). Is it possible? I think it is possible but I don’t know what the command for. You can see complete explanation here: http://ubuntuforums.org/showthread.php?t=2123602. I need this, and many users need this feature in Indonesia. I have subscribed into this post.
Thank you for replying.
Thank you for your this very useful apt-cheat! May I translate this into Indonesian?
Thank you from Indonesia.
Thanks, this is very helpful.