APT Packaging Management Tool In Detail; Linux

Sandy1
  9 years ago
  5

Linux As always very easy and confortable to use. With the efforts of developers we've GUI applications for our daily use. But for the linuxers moving toward an advanced stage they are more likely to use CLI than GUI. The following article is for such linuxers who are now seeking the way of doing things with commands.
 
A package is a 'Software'. Examples of the package can be the browsers (Google chrome, Mozilla, Safari etc.), utilities package (ccleaner, ASC, BleachBit etc.), designing program (Photoshop, Gimp etc.) and Games (Need for Speed, Call of Duty etc.). The packages/software are compiled and set altogether so that when someone executes them, all the files or scripts start and install the programs on the system. Sometimes the compiled code is provided in which everything is setup, all the files and scripts, only thing user do is execute them. Mostly programs are packaged so that user can easily install it. 

 
That packaged code need to be unpackaged or execute through 'Package Management Tools'. That's where newbies have problem/confusion in Linux.

While turning from Windows/Mac to Linux, one of the biggest problems is to understand the packaging management tools in Linux. The first confusion understanding software installation is different types of packaging tools for different Linux distributions and second is in Windows we've simply a setup.exe file clicking on which starts the installation. In Linux also we've such files to install programs but they get changed in other Linux Distributions.
Although Windows packaging setup.exe has also some problems, like, they are larger in size and some others but I am discussing here about packaging In Linux, APT. So let's get started.

In this Article I am only heading to APT. To see other packaging Management tools, just see my article How To Install Software In Linux : An Introduction
 
 

 

Introduction to APT


As I mentioned above for different distributions we've different packaging management tools and so APT is for the Linux Debian based distributions. APT stands for Advanced Package Tool. In the beginning the .tar.gz (source code) was given that users had to compile them before they install on their GNU/Linux system. When the debian was created then they thought to make change and they designed a packaging management/system called dpkg. Then Red Hat after a while created rpm system. Then there was another challenge to install those packages easily and efficiently on systems with configuring perfectly and manage dependencies automatically. Then Debian created APT, Advanced Packaging Tool, since then has been being used in several other Linux distributions.

It was all needed to know for understanding the basics of the packaging and packaging management tools. Keep in mind the packaging management tools are the tools to execute programs in different ways. Here I'm going to tell you that how you can install/Unpack/configure any software (i.e package) through a widely used tool APT. It's all done in terminal, don't get scared it is super easy!  And yeh! It can also remove/uninstall, update and upgrade any packages from the system as well. So It's very featured.
 
 

 

How to use APT to install software : Commands


Each command needs user to be in root or using sudo. Read here more about sudo.
 

APT Installations commands

apt-get install {package_name}
It will install a new package
apt-get build-dep {package_name}
This command searches the repositories and installs the build dependencies for . If the package is not in the repositories it will return an error.
aptitude install {package_name}

Aptitude is an Ncurses viewer of packages installed or available. Aptitude can be used from the command line in a similar way to apt-get. See man aptitude for more information.


APT and aptitude will accept multiple package names as a space delimited list. For example:
 
apt-get install {package1_name} {package2_name} {package3_name}
Use the -s flag to simulate an action."sudo apt-get -s install " will simulate installing the package showing you what packages will be installed and configured
 

 

How to maintain linux: Commands

apt-get update
Run this command periodically to make sure your source list is up-to-date. This is the equivalent of "Reload" in Synaptic or "Fetch updates" in Adept.
apt-get upgrade
This command upgrades all installed packages. This is the equivalent of "Mark all upgrades" in Synaptic.
apt-get dist-upgrade
It tells APT to use "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.
apt-get check
This command is a diagnostic tool. It does an update of the package lists and checks for broken dependencies.
apt-get -f install
This command does the same thing as Edit->Fix Broken Packages in Synaptic. Do this if you get complaints about packages with "unmet dependencies".
apt-get autoclean
The command removes .deb files for packages that are no longer installed on your system. Depending on your installation habits, removing these files from /var/cache/apt/archives may regain a significant amount of diskspace.
apt-get clean
The same as above, except it removes all packages from the package cache. This may not be desirable if you have a slow Internet connection, since it will cause you to redownload any packages you need to install a program.
The package cache is in /var/cache/apt/archives . The command
du -sh /var/cache/apt/archives
will tell you how much space cached packages are consuming.

dpkg-reconfigure {package_name}
Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.
echo " hold" | dpkg --set-selections
 This command may have the unintended side effect of preventing upgrades to packages that depend on updated versions of the pinned package. apt-get dist-upgrade will override this, but will warn you first. If you want to use this command with sudo, you need to use echo " hold" | sudo dpkg --set-selections not sudo echo " hold" | dpkg --set-selections.
echo " install" | dpkg --set-selections
This command removes the "hold" or "locked package" state set by the above command. The note above about sudo usage applies to this command.
 

 

How to remove packages: Commands

apt-get remove {package_name}
This command removes an installed package, leaving configuration files intact.
apt-get purge {package_name}
This command completely removes a package and the associated configuration files. Configuration files residing in ~ are not usually affected by this command.
+ operator
  •  If you want to remove package1 and install package2 in one step:
     
apt-get remove {package1} {package2}+
 

 
apt-get remove {package1} {package2}+
This command removes packages that were installed by other packages and are no longer needed.
apt-get autoremove {package_name}
This command removes an installed package and dependencies.

While there is no built in way to remove all of your configuration information from your removed packages you can remove all configuration data from every removed package with the following command.
dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge
 

 

How to search package in Linux: Commands

apt-cache search {search_term)
This command will find packages that include {search_term}.
dpkg -l *{search_term}*
This will find packages whose names contain {search_term}. Similar to apt-cache search, but also shows whether a package is installed on your system by marking it with ii (installed) and un (not installed).
apt-cache show {package_name}
This command shows the description of package and other relevant information including version, size, dependencies and conflicts.
dpkg --print-avail {package_name}
This command is similar to "apt-cache show".
dpkg -L {package_name}
This command will list files in package {package_name}.
dpkg -c foo.deb
This command lists files in the package "foo.deb". Note that foo.deb is a pathname. Use this command on .deb packages that you have manually downloaded.
dlocate {package_name}
This command determines which installed package owns . It shows files from installed packages that match , with the name of the package they came from. Consider this to be a "reverse lookup" utility.

 In order to use this command, the package dlocate must be installed on your system.
dpkg -S {package_name}
This command does the same as dlocate, but does not require the installation of any additional packages. It is slower than dlocate but has the advantage of being installed by default on all Debian and Ubuntu systems.
apt-file search {package_name}
This command acts like dlocate and dpkg -S, but searches all available packages. It answers the question, "what package provides this file?".
apt-file needs to be updated regularly like apt-get. Use the command:
apt-file update
 In order to use this command, the package apt-file must be installed on your system.
apt-cache pkgnames
This command provides a listing of every package in the system.
A general note on searching: If searching for a generates a list that is too long, you can filter your results by piping them through the command grep. Examples:
 
apt-cache search filename | grep -w filename
  • will show only the files that contain filename as a whole word.
dpkg -L package | grep /usr/bin
  • will list files located in the directory /usr/bin, useful if you're looking for a particular executable.


For more information on apt-get, apt-cache and dpkg consult their manual pages by using the man command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program.

 
man apt-get


For more Linux Packagement tools go to:
How To Install Software In Linux : An Introduction
Comments
Hammer459 9 years ago

Much better.
Good tutorial and the coorct target audience :-)


Sandy1 9 years ago

Yeah! It does not. What you mean then? I said if there are tarballs, can they be installed by software manager. I said need to use terminal (did not mean apt) to install tarballs.


Hammer459 9 years ago

Dude!
apt does not handle tarballs! apt handles deb install files.
I know that terminal is more powerful as when I started using Unix there was hardly nothing else. Setting up X was a half days worth of work.
But I insist for every day install and uninstall you pretty much _never_have to use CLI apt. For every day update you _litterally_ never have to use anything but Update manager.

But when you are feeling a little more advanced and want to know how it works behind the scene, your tutorial introducing APT is good, quite good. But please do not make newbies belive they have to use CLI, because they don't, and this only makes many of them confused and hesitant of Linux.


Sandy1 9 years ago

No not at all. I am not saying neither I said or shown in article that linux is tough. It's easy. And we don't have always .deb files, we do have .tar.gz and many more. well I got what you mean that the above article is not for beginner but thoughts are conflicting here. It may seems like oh! there are too many commands but read it first it's all very easy. Linux makes everything easy including that powerful terminal. Linux will also be so easy if we use terminal and so we do. I am respecting your opinion and will see even more healthy discussion on this (may be here or on future articles).


Hammer459 9 years ago

If you download a deb file from the net your favourite browser _will_ prompt automatic install.
I insist that most user will _never_ need to install from comamnd line.
Semi-advaced users and up may have use for this.
By targetting this good tutorial at the "newbies" you are not only aiming at the wrong crowd, you also help perpetuating the incorrect notion that Linux is hard because you need to know all this difficult command line mumbo jumbo.

Change the target audience to semi-advanced and discourage newbies and I will say your tutorial is recommended read. Now it is not.


Sandy1 9 years ago

@MagicMint: We can not cover everything at once. And as I have said software manager (Software center in Ubuntu) are nice and easy to install and remove packages but that's not just an issue that I talked about in my article. The same commands can solve many problems that we don't have to install third party software to solve them. The article is basic and can be used easily to solve problems and install packages as well.


Sandy1 9 years ago

@MintMarple You did not understand the way that commands are written in tutorial and that is no problem (it happens). You can ask anything that is unclear to you.

Simply parenthesis shows here that this is an input that user needs to put, for example, to install vlc, we'll not right {vlc} but vlc. apt-get install vlc

Even if there are problems defining the things then you can comment and it will be accepted.


Sandy1 9 years ago

@Hammer459: Yes I agree that Software Manager is good and easier. But arguably we do use these commands (Terminal) alot. Apart from Software Manager we do install software from websites sometimes they are from sourceforge or others, there are many. Terminal is not tough though, once we are familiar with it then it's easiest. But here the articles talks basics of APT and so to learn many more things just keep learning. Finally there are three points that I admit,one Software manager is good, second Terminal is always useful (It takes a bit more time to understand), and third installing software is not just an issue that Software manager alone can solve so we need terminal. The above apt commands instead of installing software can solve many problems.


MagicMint 9 years ago

@Hammer459: Me too, I prefer the Software Manager by large, but sometimes I fall back into the command line wit apt, mainly by lack of patience ;-) — admittedly, it takes its time to load a package database with 71000+ packages…

@MintMarple: You see yourself, at the very same moment you quit Mint’s easy way, things get horribly complicated :-) The notation {something} is a so-called meta or syntactic notation that indicates where you have to put in something — that in the real world has no braces or parentheses or whatsoever around it. By the way, in Debian and its derivatives, you ’update’ the package list, i.e. the database, and you ’upgrade’ a package or the whole system.

@Sandy1: As you can see, even the best description still assumes a lot from newbies. At the very first place, confusion rules in ’package management’ itself, not that much in its tools. Even with the Mint utilities, it gets baffling when you have to use the Update Manager which latterly exposes package dependencies… Think of this: even Debian has aptitude as a graphical interface to deal with the underlying command-line complexity of apt :-(


Hammer459 9 years ago

@MintMarple you are right that Synaptic is complicated, that is why Mint developed Software Manager. This is simple and powerful at the same time. I am very experienced and I hardly ever use apt because of SM . So teaching apt and dpkg to newbies is unnecessary and possibly confusing.
This is why I say that this is a good tutorial for the somewhat experienced but not useful for a newbie.


Hammer459 9 years ago

You are right. And at the same note, just because you and I know more than most about installing software does not mean that most people even have to know. Synaptic makes the knowing apt and dpkg redundant and Mints Software Manager make Synaptic pretty much redundant.
Had the Tutorial been aimed at "those who need to now how stuff works under the hood" it would be a pretty good tutorial. Bot not for a newbie.


Sandy1 9 years ago

See if you know everything that does not mean everyone knows. Those who need to know this, will read this definately. I tried to write the things that seem tough to newbie. This is how I think the community develop. I had some problems when i figured out I gave explanation here to basic learners. I respect what you are saying but listen to me too, we believe in sharing. Whatever you know share it will others, those who need it will go for it.


Hammer459 9 years ago

This is like an introduction to driving a car including changing sparkplugs, timing belt and transmission fluid.... All you need is "How do I turn on the ignition" and "Who do I call to service the engine".
Class 98... "How do I change sparkplugs"
Class 492... "How do I change timing belt"


Sandy1 9 years ago

It's an introduction to the commands that I usually used/came across on linux mint like so many others. I had some confusions when I knew about packaging management tools and concept of packages. I even saw many on the internet asking about the difference between packages and software. The main reason of the article is to remove confusions about package management tools. No doubt linux mint is easy and even I started with it and still use Linux mint and Ubuntu.


MagicMint 9 years ago

All the people at Debian, Ubuntu and Mint are working hard to hide all this complexity from Average Joe, who shouldn’t have to deal with these unnecessary details, really ;-)


remoulder 9 years ago

It is not necessary to copy content from another site here, you just need to provide the link.


michelsaey 9 years ago

In Linux Mint, you never use this because we have a 'Software Manager' and Synaptic. However, this is a good introduction so I promote this tutorial ;)


Hammer459 9 years ago

This is a rather good description but it does not discuss the fact that for the average user you _never_ have to use apt. Synaptic on Ubuntu is way easier to use and Mints Software Manager makes it so simple even my daughter installed software when she was 7