Saturday, May 28, 2016

Using apt on ubuntu

For a while, i've been an ardent fan of synaptic package manager, and have delegated to synaptic, the gory details of dealing with the apt command line.

However, recently, I started playing with docker (https://www.docker.com) a little. Also, I'm building a 10 node raspberry pi cluster ( http://varghese85-cs.blogspot.com/2016/05/10-node-raspberry-pi-cluster-part-1.html ). Towards this I'll be running the Pis headless, using Ubuntu-Mate's convenient command:
graphical disable/enable
That means I need to learn the gory details of  using apt on the command line.

NOTE: apt needs to run as root. In the example below, I'm assuming you are running as root. If not, prefix sudo appropriately.

The first lesson is apt vs. apt-get.
Historically, the command has been apt-get. However, recently I noticed apt-get has been deprecated in favor of apt. There isn't much of a difference; the sub commands are all the same. Apt also has a little more color and output formatting than apt-get. Otherwise, they are a horse a piece.

Finding the right packages:
On ubuntu, apt supports auto-completion on package names. So you can for instance do
apt install pyt
and hit the tab key, and you can sea  list of all options (except there are som 4000+ with the pyt prefix, so try something else).

apt list will print a list of all available packages. Obviously, this is too long of a list, but you can pass it to grep. Also, you can specify a wildcard search expression to apt list. For example:
apt list *java*
Additionally, there are some parameters you can pass to apt list. For instance,
apt list --installed
will list all the installed packages
apt list --upgradable 
will list all the packages that have upgrades available.

To search for a package, use apt search. For example,
apt search condor 
lists all packages that have condor in the name or description.

To see full details of a package, use
apt show <packagename>
Keeping your system up to date:
The usual way of updating your system is;
apt update; apt upgrade
The first command fetches the new list of packages. The second command does the actual upgrade.

Installing a specific package:
It usually helps to have done an apt update (or that and an apt upgrade) before installing a new package. To install a package, do
apt install <packagename>
Removing a package:
To remove a package, one would usually do
apt remove <packagename>
However, this does keep some of the configuration etc around. So to fully remove a package, one should do:
apt --purge remove <packagename>
Now, when you install a package, that pulls in dependencies. So when you remove a package, some dependencies it pulled in may have become no longer needed. So to remove those, you can do
apt --purge autoremove
Remember to not include the --purge option if you want the configuration to stick around.

If apt was interrupted:
Another common problem that happens is if apt was interrupted. For example, you hit CTRL+C on the console while apt was running. This can leave the packages in a broker state. To fix that, run
[sudo] dpkg --configure -a
.

No comments: