APT
Linux manages all software in the form of packages which are individual branches of software that contain;
- user interfaces
- modules
- libraries
Most applications branch from dependencies or several inter dependent packages together where as some let you choose which packages to install instead. This can get complicated especially if you are new or learning Linux. The solution to this issue is to have a central place where packages are mantained which allow you to simply update the whole package from a reliable source – introducing Linux package manager!
All Linux distributions or distros have their own package management system, since we’re focusing on Debian/Ubuntu, we’ll be talking about APT, the Advanced Packaging Tool. If you have ever run sudo apt-get update
then you have already used APT.
APT requires super-user permissions (sudo), as it deals with core aspects of the system, so you’ll need to run most commands with sudo at the beginning.
Search packages
apt search [package name]
We can search repositories by using the above command. while APT is very useful, you need to know/input the exact package name. Let me provide an example by searching for Google Chrome. We can take a guess and assume it may have “chrome” in the package title, so our command will be apt search chrome
Once we press enter to run the command, we get a result in seconds. We now get the package name on the left and a description on the right. The results are limited so we can simply read down the list and this will give us a clue as to the name of the package we want to install. The 5th entry in our list is google-chrome-stable which is the name of the package we want to install. This would be the GUI equivilent of installing Google Chrome from Google’s website.
If we need more detailed information, we can use the following command instead
apt show [package name]
Install packages
Once we have the name of our package we can then instruct Linux APT to install the package onto our system. If there are dependencies (any prerequisite packages) they will also be installed.
sudo apt-get install [package name]
Example: sudo apt-get install google-chrome-stable
Remove packages
In some cases we may need to remove packages, this is simply done by running the following command;
sudo apt-get remove [package name]
In the majority of instances if you run the remove command on the core package then it’s associated packages should be removed too. If you find this hasn’t happended then try the following command;
sudo apt-get autoremove
This becomes useful in the instance you attempted to remove a core package but it didn’t fully complete the task.The autoremove
will get rid of a packages associated packages and any dependencies it had. What if another package is using a dependency? Autoremove
will execute subject to no other program using it/them. Clearly this is a great way to clear up any unused libraries and packages using up unnecessary storage. Here is an example of the command in action;
Upgrading packages
To upgrade individual packages we first need to find out which packages have an available update and then grab the update repositories. This process will upgrade to the newest versions that maybe available. This is a replacement process, meaning the same package name is required and the older version is replaced with a newer version. Once we have these packages, we run the following command
sudo apt-get upgrade [package name]
Or we can upgrade all packages on our system by not adding an argument
sudo apt-get upgrade
TIP: We can check for updates, grab any available update packages and upgrade them all in a single command
sudo apt-get update && sudo apt-get upgrade -y
If you just want to check which packages would be upgraded before executing the command then we can run use the –s option first
sudo apt-get –s upgrade
Cleaning
Ubuntu by default caches downloaded packages in case it may need them again. If you have limited storage space remaining then you can delete the cache and reclaim space with the following command
sudo apt-get clean
If you want to retain the newest file versions of packages in your cache but delete older archive files, then run the following command instead
sudo apt-get autoclean
Installed packages list
We can compile a list of Debian packages (dpkg) by running the following command
dpkg -l
Search for an installed package
We can search for a package we want to confirm is/isn’t installed by running the following command, ensuring you input the single quote and asterisk as shown
dpkg -l '*package_name*'