A package management system is used in order to organize, track, and maintain the thousands of packages or software that exist in an operating system. It contains tools that are used to install, upgrade, remove, configure and create software packages on a computer.
A software package is a collection of files that contain the information about a program as well as the files that are needed to install the program on to the computer. The information contained within such packages is the software description, version numbers, dependencies, installation and upgrade requirements, etc. These packages are archived into a single file and these are uncompressed by the package manager, and placed into the appropriate locations on the file system. All of these files are then tracked by the package management system and they can easily be upgraded, removed, and tracked.
Functions of a package management system:
- File tracking: A database of installed files is maintained. This contains information about every file that is installed using the package system;
- Checksum and signature verification: This ensures that the package has downloaded correctly, and ensures the correct origin of packages;
- Software installation and upgrades: Software from a repository can be downloaded, installed, and then upgraded easily;
- Dependency checking: Checks to ensure that software has all the dependencies required for proper installation. It can also stop a file on which other software is dependant upon from being removed;
- Package creation: Allows the user to create a software package using the source code of a program.
A debian package has the following file naming convention: [package-name]-[ve.rsi.on]-[buildnumber].[architecture].deb
- [package-name]: This is the name of a package;
- [version]: This is the numeric version of a package
- [build-number]: This represents minor changes made to the package
- [architecture]: This is the type of computer a package has been built for. Example, i386, x64, x86, ppc,
- .deb: The extension name for debian packages
Since this is only a convention, package files may be named in a different way but if you're ever building a debian package, please try to adhere to this naming convention.
Fortunately, package management is not difficult at all. We're already seen one method of package management using Synaptic Package Manager. The following are command line tools that can do the same.
dpkg
dpkg is a low level tool that can be used for installing, removing, and getting more information about packages.
We can dive right in by trying to install Audacity using dpkg.
1. Download the debian package file. I found one on getdeb.net. The one that I'm using for this tutorial is audacity_1.3.7-1~getdeb1_i386.deb (Notice that the naming convention used is a bit different but it'll still work). Download the file and save it somewhere you can find it easily, such as the desktop.
2. Open the terminal (Applications > Accessories > Terminal ). If you are using the default install of Ubuntu, then the terminal window will see bash (bourne again shell).

3. The linux shell is fairly straight forward. Basically, you just type in a command, and it executes it if it understands it. First, go to the Desktop directory where we saved the audacity deb file and then view the list of files.
$ cd ~/Desktop
$ ls

4. Next, we'll view more information about the .deb file using 'dpkg --info [filename]' or 'dpkg -i [filename]' command. We can see the package name, version, architecture, dependencies, description, etc.

5. Now we can install it using 'sudo dpkg --install [filename]' or 'sudo dpkg -i [filename]' command. The 'sudo' stands for 'Super User Do'. Since we're going to be doing an administrative task that requires higher privileges, we'll prepend the dpkg command with 'sudo'. It's just like when synaptic package manager asks for you to enter your password before allowing you to install anything. This is mainly for security reasons. Audacity will get installed (provided there are no problems with any dependencies).


6. Finally, if we want to remove audacity using dpkg, we'll use 'sudo dpkg --remove [packagename]' or 'sudo dpkg -r [packagename]'. Once installed, you can remove it by using the package name instead of the filename.

7. As with almost all commands, you can view the manual of dpkg by typing 'man dpkg' and you will be able to see all the options available for using dpkg. You can use the arrow keys, page-up, page-down, or CTRL+V and CTRL+B, to move around the man page. You can type /[searchterm] -> enter-key to search within the manual. You can press 'q' to quit.

Common dpkg commands and options
-i or --install --------------- Installs the package
-i --recursive -------------- Installs all packages inside a directory (or matches wildcard*)
-i -G ---------------------- Doesn't install if a newer version of the same package is already installed
-i -E ---------------------- Doesn't install the package if the same package is already installed
-r or --remove ------------ Removes package
-r -B ---------------------- Disables packages that are dependent on the one being uninstalled
--configure ---------------- Attempts to reconfigure post install options
-P or --purge ------------- Completely removes a package as well as its config files
-I or --info --------------- Prints information about the package
--ignore-depends=package ---- ignores package dependency information
-L or --listfiles ------------ Lists files associated with an installed package
-C or --audit ------------- Searches for partially installed packages
--force-things, ------------ Options such as downgrade, hold, depends, conflicts, overwrite, etc. Check man dpkg for more.
--simulate ----------------- Do everything that a package should do but don't write any changes
apt
APT, or the Advanced Packaging Tool, is a higher level front-end for dpkg. It consists of a few tools such as apt-get and apt-cache. APT can manage dependencies, updates, removals, and downloads from repositories. Once again, we'll go ahead and install Audacity with it.
1. In order to install files, we use the apt-get command. Simply go to the terminal, and type 'sudo apt-get install audacity'.

And that's all there is to it. It took care of all our dependencies, downloaded the package from the Ubuntu repository, and installed the package.
2. Removing packages is just as simple. Just type 'sudo apt-get remove audacity'. You will have to confirm that you want to continue to remove audacity. Simply type Y when asked.

You may have noticed that you did not have to download any packages in order to install audacity. APT automatically checked package repositories for a packaged named 'audacity'. It then downloaded it and installed it. You are able to add or remove extra repositories your self. There are two common ways of doing that.
1. You can use the System -> Administration -> Software Sources command in Ubuntu:

The Third-Party Software and Ubuntu Software tabs have options in order to add more repositories.

2. You can also edit the /etc/apt/sources.list file using a text editor.

Always make certain that you only add repositories from trusted sites.
Other common commands for apt-get are:
- apt-get update : This command will get the latest list of packages from the repositories. You should do this before performing software upgrades so you are sure to get the latest versions
- apt-get upgrade: This is used to upgrade all installed packages to the latest versions in your repositories.
- apt-get dist-upgrade: This intelligently performs package upgrades and will resolve conflicts by installing the most important upgrades at the expense of less important ones if necessary
- apt-get clean: This clears out the local repository of retrieved package files. Run this in order to save disk space
- apt-get check: This checks for broken dependencies
- apt-get autoclean: This is like clean but it will only remove package files that can no longer be downloaded and are largely useless
- apt-get --fix-broken (or -f): This attempts to correct a system with broken dependencies in place.
- apt-get --ignore-missing (or -m): If packages can't be retrieved due to file corruption or network issues, then it will be ignored
- apt-get --quiet (or -q or -qq): This will silently install packages. This is useful when creating a script or batch file.
- apt-get --simulate (or -s): This will go through all the regular installation procedures but will not write any thing to disk
- apt-get --yes (or -y): This can be used with remove or install and it will say Yes to all "Are you sure you want to continue?" questions.
- apt-get --no-upgrade: This will prevent pages from being upgraded if they already are installed.
- man apt-get: View the apt-get manual
apt-cache is another command that comes with APT. This only provides information about packages.
- apt-cache showpkg [packagename]: this shows information about the package such as dependencies, reverse dependencies, descriptions, and versions.
- apt-cache stats: This shows all the stats about the currently installed packages
- apt-cache unmet: This shows the packages with unmet dependencies
- apt-cache depends [packagename]: This shows the dependencies of a specific package
- apt-cache search [search pattern]: This returns a list of packages that meet the search pattern
- man apt-cache: View the apt-cache manual
aptitude
aptitude is a front-end for the APT commands. This is a powerful command line tool that allows users to search, install, remove, and maintain their packages. One way to use it is to simply type 'aptitude' in the terminal. This will launch the program:

Let's install audacity with this again.
1. Search for audacity by typing /audacity. You will notice the list updating as you type.

2. Press enter, then press + to select audacity.

3. Press g to preview changes. Then press g again to apply changes. It will ask you to become root. Do that and then enter in your password when prompted.

And audacity will get installed.
You can use CTRL+T to access the menu.
The most commonly used options are:
- u : This will update the package listings
- shift+u: Marks all upgradable packages for upgrades
- + to mark the selected package for installation
- - to mark the selected package for removal
- /[searchterm] to search for a package
- g to preview changes
- g again to apply changes
- q to quit
You can also use aptitude from the command line by using the following commands:
- aptitude update: Updates the package list from the repositories
- aptitude search [packagename]: searches the repository for package name or search term
- aptitude install [packagename]: Installs package
- aptitude remove [packagename]: Removes package
- aptitude help: Get help for aptitude.
Easter eggs
Try typing:
apt-get moo
Also, try typing:
aptitude -v moo
aptitude -vv moo
aptitude -vvv moo
and so on.
I hope you found this post useful! Please feel free to leave a comment if you have any errors to point out, questions, or concerns.




Comments
Post new comment