Scope
- Understand what APT and dpkg is
- Effectively use APT and dpkg from CLI/Terminal
dpkg is a tool for installing, removing and building Debian packages. Shortly told, it handles *.deb packages.
Using dpkg
Knowing some basic dpkg commands can make your life allot easier. For one you can retrieve a ton of information of installed packages, or installing new packages, and even build your own deb packages.
dpkg options
-i | --install
Usage:
Code: Select all
dpkg -i /path/to.deb
Code: Select all
dpkg --install /path/to.deb
--unpack
Usage:
Code: Select all
dpkg --unpack /path/to.deb
--configure
Usage:
Code: Select all
dpkg --configure package
Code: Select all
dpkg --configure -a
Code: Select all
dpkg --configure --pending
-r | --remove | -P | --purge
Usage:
Code: Select all
dpkg -r /path/to.deb
Code: Select all
dpkg --remove /path/to.deb
Code: Select all
dpkg -P /path/to.deb
Code: Select all
dpkg --purge /path/to.deb
-p | --print-avail
Usage:
Code: Select all
dpkg -p package
Code: Select all
dpkg --print-avail package
-I
Usage:
Code: Select all
dpkg -I /path/to.deb
There are more options available, but these are the basic options. You could use Google if you want more.
Combining APT and dpkg to "backup"
Not really a back up, but more exporting the list of installed packages to a file, then import it again. You could also use APTOnCD for this, but if you got to configure a ton of machines with different hardware setup, this can be just as useful (I.e. open the file and remove packages you don't need after a stock install).
Code: Select all
sudo dpkg --get-selections > mypackages.txt
sudo dpkg --set-selections < mypackages.txt
sudo apt-get dselect-upgrade
APT
APT is a combination of wget and dpkg, simply put. It keeps a list of available packages in the repositories and can be used to download and install those packages. It can also be used to remove these packages.
aptitude vs. apt-get
I prefer aptitude over apt-get any day. It handle dependencies better (especially noticeable when removing packages), it offers better upgrade options (not recommended in Mint), and is not divided like apt-get it (more on that later). My recommendation is to get used to aptitude from the start, and it is what I will focus on in this howto. Aptitude can also run as a "Synaptic in terminal". If you want to look at it, I recommend starting it by using:
Code: Select all
sudo aptitude -u
Updating list of packages
Since the repositories are constantly being updated, new packages added or packages being updated etc, so it could be a good idea to update the local list of available packages. Both aptitude and apt-get handles updates:
Code: Select all
sudo aptitude update
sudo apt-get update
Using the CLI for searching is faster than loading synaptic and gives the same results, hence, in my opinion, better.
Code: Select all
aptitude search string
Code: Select all
apt-cache search string
And aptitude offers additional information about the package, like whether it is installed or not, with the first (few) characters on left of the package name. The first character(s):
i: Installed
p: No trace found on the system
c: Packages has been deleted, but the configuration files exists.
v: Virtual package.
The second character(s) are the action which is to be taken with the package:
i: Going to be installed
d: Going to be deleted
p: Going to be deleted, including configuration files.
If the third character is A it means the package was automatically installed.
Here is an example of a search result (taken from the aptitude man pages):
Here you see apt is installed, apt-build does not have any files on the system, but is going to be installed, apt-file only has the configuration files on the system, but those are to be removed, and raptor-utils is installed, no changes to it, and was automatically installed.i apt - Advanced front-end for dpkg
pi apt-build - frontend to apt to build, optimize and in
cp apt-file - APT package searching utility -- command-
ihA raptor-utils - Raptor RDF Parser utilities
Installing packages
So after updating the list, and you know what to install after the search it is just using:
Code: Select all
sudo aptitude install package
sudo apt-get install package
-d
Download only, you just download the package to a local repository, you do not install it.
-y
Assume yes on yes/no prompts.
--force-yes
Not recommended to use, this forces yes on even warning messages. By using this you might end up doing something harmful to your system.
Using options:
Code: Select all
sudo aptitude -option install package
sudo apt-get -option install package
Removing packages
So you got tired or don't need a package any more and are ready to remove it. This is pretty straightforward:
Code: Select all
sudo aptitude remove package
sudo apt-get remove package
Fixing broken dependencies
From time to time, and for some reason, you can get packages with broken dependencies. These can be a pain, as APT usually refuse to install or remove any packages before this is fixed. Luckily this can be done automagically:
Code: Select all
sudo aptitude -f install
sudo apt-get -f install
Updating your system
It is not recommended using APT to keep Mint up to date, you should use mintUpdate for this. But I will still include a few words of this here, as there are a few ways of doing this. Again, aptitude is the preferred way of upgrading:
Code: Select all
sudo aptitude safe-upgrade
Why you should not update Mint using CLI
Mint is based on Ubuntu, and use Ubuntu repositories, but that does not mean Mint IS Ubuntu, Mint (Main) forked from Edgy (or 6.10), and thus has it's differences from the current stable Ubuntu. This also means that not all updates from Ubuntu is safe/stable on Mint. To prevent the installation of these updates, the Mint development team has built mintUpdate, that should be your primary update tool. Not only does this filter out known "ugly updates", it also filters out potential "ugly updates", like kernel updates. One of the reasons for excluding kernel updates is to provide a consistent desktop for the user, without having to recompile drivers after a update, but if you are a security freak, feel free to include all updates, but do not come back and complain because X fails to start or similar (but we will of course help you set things straight again, if you ask politely ).
And UNDER NO circumstances should you EVER do a dist-upgrade *, unless there is an official announcement that explicitly states that this is possible and even then you should read carefully and follow the directions given. After almost every Ubuntu release there are some who run a dist-upgrade on their system and end up with a mix between Mint and Ubuntu, and often a buggy mix. The only solution for this is a FRESH INSTALL!
*Note - if you have the correct sources.list for your version of Mint you can do a dist-upgrade. But the minute you add repositories from the next (or previous) generation you're done (like adding Hardy repos for Daryna). But the dist-upgrade option is the only way to get new applications added even in mintUpdate. But remember to have the right sources.list
It is (always) safe (and recommended) to use the dist-upgrade option in mintUpdate. Nothing is installed until you click apply. This note added by husse
If you do not feel confident with apt and Synaptic (or package management in general) you should stay away from upgrading your system via CLI.
Cleaning out the local repository
APT keeps a local repository of all packages you install. This can be very useful, especially if you want to reconfigure a packages or re install it. But this could take up allot of space if you install a few packages, so a clean out once in a while could be useful.
Now, there are two ways of doing this:
Code: Select all
sudo aptitude autoclean
Code: Select all
sudo aptitude clean
Cleaning out dependencies
If you haven't followed my recommendations and used aptitude to remove packages, some of your installed packages might not be needed any longer. Fear not, the can easily be removed:
Code: Select all
sudo apt-get autoremove
No proper software is complete without any easter eggs, and APT has some. First apt-get:
Code: Select all
apt-get --help
Code: Select all
apt-get moo
Aptitude:
Code: Select all
aptitude --help
Code: Select all
aptitude moo
aptitude -v moo
aptitude -vv moo
aptitude -vvv moo
aptitude -vvvv moo
aptitude -vvvvv moo
aptitude -vvvvvv moo