Insight: Apt-get Command Examples In Ubuntu [ Beginner’s Guide ]
Ubuntu is one of the popular Linux based operating system. Ubuntu is based on Debian and Debian uses a dpkg packing system. APT or advanced package tool does the work of package management. Apt-get works with Apt command to install software or package in Ubuntu or Debian based system. Apt command manages the dpkg packages.
In this tutorial post, we are going to show you the simple example of Apt-get command. This post is intended for beginner level of users.
Apt-get Command Examples In Ubuntu [ Beginner’s Guide ]
Apt-get requires administrative privileges while executing the apt-get command.
1. Update Package Database
To upgrade our system or packages to the new version, The system should know that the newer packages are available. To make aware our system regarding new version, we should run this command. It resynchronize the package index files from the the sources in /etc/apt/sources.list and the index files is updated.
sudo apt-get update
2. Upgrade Package Database
Once you run the apt-get update command, Your package database will get updated has been updated and you can easily upgrade your package to the newer version. It also update your Ubuntu to the latest version if available.
sudo apt-get upgrade
To upgrade only specific pacakge, run the following command:
sudo apt-get upgrade package-name
To upgrade the system without caring any consequences like removal of some packages or even addition of extra packages then run the following command:
sudo apt-get upgrade dist-upgrade
To run update and upgrade one after another.
sudo apt-get update -y && sudo apt-get upgrade -y
Here, -y flag will provide yes answer to any prompts during the command execution.
3. Install Multiple Packages
You can even install multiple packages through single command. It will save your time too.
sudo apt-get install package-name1 package-name2 package-name3
4. Install Package With Specific Version.
Run the following command to install a specific version of a package:
sudo apt-get install [package_name]=[version_number]
5. Install Packages Without Upgrading
Run the following command to install packages without upgrading. Here –no-upgrade will prevent any upgrading of the package.
$ sudo apt-get install package_name --no-upgrade
6. Upgrade Only Specific Packages
Run the following command to upgrade only specific package. It will only upgrade the already installed packages.
$ sudo apt-get install package-name --only-upgrade
7. Remove Installed Package
Run the following command to remove installed package from your system. This command won’t remove any configuration file associated to the package.
sudo apt-get remove package_name
If you want to remove both the package and configuration files associated with the package then run this command.
sudo apt-get purge package_name
If you want to automatically removes any packages that aren’t associated with any installed program then run the following command.
sudo apt-get autoremove
8. Clean Up Disk Space
Run the following command to clean up the disk.
$ sudo apt-get clean
9. Download Only Source Code Of Package
If you want to download only source code of the package, then run the following command with ‘–download-only source‘ option.
$ sudo apt-get --download-only source package-name
10. Download, Unpack And Compile a Package
Run the following command to download, unpack and compile the source code through a single command at the same time.
$ sudo apt-get --compile source package-name
11. Check Change Log Of Installed Package
Run the following command to check the change long of installed package.
$ sudo apt-get changelog package-name
12. Check Broken Dependencies
Run the following command to check any possible broken dependencies.
$ sudo apt-get check
Let us know if there is any error in this post regarding apt-get command examples tutorial post.