e

Apt-Get

Apt-get is a very powerful command-line utility for downloading, installing, and uninstalling packages. It is very easy to use (though perhaps not as friendly as Synaptic Package Manager) and very convenient for scripting.

Updating the Repositories

Before you install anything using apt-get, it's a good idea to run:

$ sudo apt-get update

This tells apt-get to talk to the online software repositories and make sure that its package information is up-to-date. This is important when you're running apt-get on a fresh install, or when you want to upgrade packages installed on your system. Otherwise, there will probably be no harm if you skip this step, but it's better to be safe than sorry.

Installation using Apt-Get

Installation through apt-get is very easy. Open a terminal, and run:

$ sudo apt-get install <package-name-here>

Enter your password. The output will look something like this:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  dkms libqt4-dbus libqt4-network libqt4-opengl libqt4-xml
The following NEW packages will be installed:
  dkms libqt4-dbus libqt4-network libqt4-opengl libqt4-xml virtualbox-4.1
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.8MB of archives.
After this operation, 130MB of additional disk space will be used.
Do you want to continue [Y/n]?

Apt-get lets you know how what packages the selected packages depends on, how much it needs to download, and how much disk space the installed programs are going to take up. It then asks you to confirm or deny the changes it's going to make. The capitalized Y in [Y/n] means that it is the default choice, so you can hit enter to tell apt-get to go ahead. In a few minutes, your packages should be installed.

You can install more than one package with a single apt-get command. All you have to do is list the package names, separated by a space, after the 'install' flag. Example:

$ sudo apt-get install <package-name-1> <package-name-2> <package-name-3>

Uninstallation using Apt-Get

Using the 'Remove' Flag

Uninstalling packages with apt-get is almost as easy as installation; it sometimes requires one extra step. At a terminal, run:

$ sudo apt-get remove <package-name-here>

The output should look similar to this:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libqt4-opengl libqt4-dbus dkms libqt4-xml libqt4-network
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  virtualbox-4.1
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 126MB disk space will be freed.
Do you want to continue [Y/n]?

Hit enter if you're sure you want the package removed, and wait for apt-get to automatically take care of it for you. In many cases, including the example above, apt-get will not automatically remove the dependencies it installed with the program. Usually, having these installed does no harm and leaving them will quicken reinstallation of the package they came with. If you're trying to free up disk space, though, you can remove them by running:

$ sudo apt-get autoremove

The output will look like this:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  dkms libqt4-dbus libqt4-network libqt4-opengl libqt4-xml
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation, 4,432kB disk space will be freed.
Do you want to continue [Y/n]?

If you're certain you want them removed, hit enter and let apt-get do its thing.

Using the 'Purge' Flag

If you want to remove not just a package but also all associated configuration files (which can be especially useful if you've got a broken program that you want to reinstall), run:

$ sudo apt-get purge <package-name-here>

The rest of uninstallation is identical to the 'remove' command described above.

Upgrading Packages using Apt-Get

Before you upgrade packages through apt-get, it is important to make sure that your repositories are up-to-date, as described above.

Using the 'Dist-Upgrade' flag

This differs somewhat from the 'upgrade' flag, in that 'dist-upgrade' will upgrade more important packages at the expense of less important ones. An upgrade with the 'dist-upgrade' flag will sometimes remove packages, too. Don't worry, it shouldn't remove any packages that represent end-user programs, and if it does, you'll see them when it asks you to confirm the changes. Using this flag as opposed to the 'upgrade' flag is recommended by Bodhi, and it is required to update some Enlightenment-related packages. To upgrade your system this way, run:

$ sudo apt-get dist-upgrade

Using the 'Upgrade' Flag

If you want apt-get to upgrade all packages for which newer versions are available, just run:

$ sudo apt-get upgrade

Apt-get will check for updates for all installed packages, and display the changes to be made. If you want to make the suggested changes, just hit enter, as before.

Clean and Autoclean

If you want to free up some disk space on your system, these flags are invaluable. Apt-get downloads and installs package files in the course of normal operation. After the software in the package file is installed, the package file is no longer necessary. 'Autoclean' searches through your downloaded package files and removes any that are obsolete. To use it, just run:

$ sudo apt-get autoclean

'Clean' works similarly, except that it removes all downloaded package files. To use it, run:

$ sudo apt-get clean

Searching for Packages

If you want to search through package names from the command line (though doing it through Synaptic Package Manager is much more user-friendly), you can run:

$ apt-cache search <part-of-a-package-name>

For example, if you wanted to see a list of fonts available to install, you could run:

$ apt-cache search ttf

Which gives several pages of output:

libfont-ttf-perl - Perl module for TrueType font hacking
texlive-font-utils - TeX Live: TeX and Outline font utilities
ttf-alee - A Lee's free Hangul truetype fonts
ttf-arabeyes - Arabeyes GPL TrueType Arabic fonts
ttf-arphic-bkai00mp - "AR PL KaitiM Big5" Chinese TrueType font by Arphic Technology
ttf-arphic-bsmi00lp - "AR PL Mingti2L Big5" Chinese TrueType font by Arphic Technology
...

If you want to search through a large list of packages for a keyword, you can pipe the output through the 'grep' command, like so:

$ apt-cache search <part-of-a-package-name> | grep -i <keyword>

In the above example, if we wanted to see what packages we can install to get Japanese fonts, we could run:

$ apt-cache search ttf | grep -i japanese

Which gives us a list of all font packages with “japanese” in their names or descriptions.

User Feedback

apt-get
Did you find this article helpful?
Yes, right on the money!
 
100%(25)
Somewhat. Needs work.
0%(0)
Not really
0%(0)
Not at all.
0%(0)

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

 
apt-get.txt · Last modified: 2011/11/20 19:11 by jvellos · [Old revisions]


© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks