Home » Categories » Multiple Categories |
How To Manage Packages In Ubuntu and Debian With Apt-Get & Apt-Cache |
Article Number: 201 | Rating: Unrated | Last Updated: Fri, Dec 27, 2013 at 1:02 AM
|
What is Apt-Get?Apt is a command line frontend for the dpkg packaging system and is the preferred way of managing software from the command line for many distributions. It is the main package management system in Debian and Debian-based Linux distributions like Ubuntu.While a tool called "dpkg" forms the underlying packaging layer, apt-get and apt-cache provide user-friendly interfaces and implement dependency handling. This allows users to efficiently manage large amounts of software easily. In this guide, we will discuss the basic usage of apt-get and apt-cache and how they can manage your software. We will be practicing on an Ubuntu 12.04 cloud server, but the same steps and techniques should apply on any Debian-based distribution. How To Update the Package Database with Apt-GetApt-get operates on a database of known, available software. It performs installations, package searches, and many other operations by referencing this database.Due to this fact, before beginning any packaging operations with apt-get, we need to ensure that our local copy of the database is up-to-date. Update the database with the following command. Apt-get requires administrative privileges for most operations: sudo apt-get updateYou will see a list of servers we are retrieving information from. After this, your database should be up-to-date. How to Upgrade Installed Packages with Apt-GetWe can upgrade the packages on our system by issuing the following command:sudo apt-get upgradeFor a more complete upgrade, you can use the "dist-upgrade" argument, which attempts intelligent dependency resolution for new packages and will upgrade essential programs at the expense of less important ones: sudo apt-get dist-upgrade How to Install New Packages with Apt-GetIf you know the name of the package you wish to install, you can install it by using this syntax:sudo apt-get install package1 package2 package3 ...You can see that it is possible to install multiple packages at one time, which is useful for acquiring all of the necessary software for a project in one step. It is important to understand that apt-get not only installs the requested software, but also any software needed to install or run it. We can install the full "vim" text editor package by typing: sudo apt-get install vim How to Delete a Package with Apt-GetTo remove a package from your system, you can issue the following command:sudo apt-get remove package_nameThis command removes the package, but keeps the configuration files in case you install the package again later. This way, your settings will remain intact, even though the program is not installed. If this is not the desired outcome, and you would like to clean out the configuration files as well as the program, use the following syntax: sudo apt-get purge package_nameThis uninstalls the package and removes any configuration files associated with the package. To remove any packages that were installed automatically to support another program, that are no longer needed, type the following command: sudo apt-get autoremoveYou can also specify a package name after the "autoremove" command to uninstall a package and its dependencies. Common Apt-Get Option FlagsThere are a number of different options that can be specified by the use of flags. We will go over some common ones.To do a "dry run" of a procedure in order to get an idea of what an action will do, you can pass the "-s" flag for "simulate": sudo apt-get install -s htop Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: strace ltrace The following NEW packages will be installed: htop 0 upgraded, 1 newly installed, 0 to remove and 118 not upgraded. Inst htop (1.0.1-1 Ubuntu:12.04/precise [amd64]) Conf htop (1.0.1-1 Ubuntu:12.04/precise [amd64])In place of actual actions, you can see a "Inst" and "Conf" section specifying that there is where the package would be installed and configured if the "-s" was removed. If you do not want to be prompted to confirm your choices, you can also pass the "-y" flag to automatically assume "yes" to questions. sudo apt-get remove -y htopIf you would like to download a package, but not install it, you can issue the following command: sudo apt-get install -d packagenameThe files will be located in "/var/cache/apt/archives". If you would like to suppress output, you can pass the "-qq" flag to the command: sudo apt-get remove -qq packagename How to Find a Package with Apt-CacheThe apt packaging tool is actually a suite of related, complimentary tools that are used to manage your system software.While "apt-get" is used to upgrade, install, and remove packages, "apt-cache" is used to query the package database for package information. You can use the following command to search for a package that suits your needs. Note that apt-cache doesn't usually require administrative privileges: apt-cache search what_you_are_looking_forFor instance, if we wanted to find "htop", an improved version of the "top" system monitor, we can type the following: apt-cache search htop aha - ANSI color to HTML converter htop - interactive processes viewerWe can search for more generic terms also. In this example, we'll look for mp3 conversion software: apt-cache search mp3 convert abcde - A Better CD Encoder cue2toc - converts CUE files to cdrdao's TOC format dir2ogg - audio file converter into ogg-vorbis format easytag - viewing, editing and writing ID3 tags hpodder - Tool to scan and download podcasts (podcatcher) id3v2 - A command line id3v2 tag editor kid3 - KDE MP3 ID3 tag editor kid3-qt - Audio tag editor . . . How to View Package Information with Apt-CacheTo view information about a package, including an extended description, use the following syntax:apt-cache show package_nameThis will also provide the size of the download and the dependencies needed for the package. To see if a package is installed and to check which repository it belongs to, we can issue: apt-cache policy package_name ConclusionYou should now know enough about apt-get and apt-cache to manage most of the software on your server.While it is sometimes necessary to go beyond these tools and the software available in the repositories, most software operations can be managed by these tools. If you are planning on spending time in a Debian-based environment, it is essential to have a working knowledge of these tools. |
Attachments
There are no attachments for this article.
|
How To Install and Use Memcache on Ubuntu 12.04
Viewed 3528 times since Tue, Dec 24, 2013
How To Import and Export Databases and Reset a Root Password in MySQL
Viewed 2893 times since Thu, Dec 26, 2013
How To Use Dokku Plugins to Access Additional Functionality
Viewed 4615 times since Sun, Dec 29, 2013
How To Use a Simple Bash Script To Restart Server Programs
Viewed 3237 times since Fri, Dec 27, 2013
How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server
Viewed 2815 times since Thu, Dec 26, 2013
Upgrading Debian to Unstable
Viewed 3596 times since Thu, Dec 26, 2013
How To Install Wordpress on Arch Linux
Viewed 2571 times since Sun, Dec 29, 2013
How To Install Git on Ubuntu 12.04
Viewed 6235 times since Mon, Dec 23, 2013
Geddy.JS: A No-Brainer MVC Node.js Framework
Viewed 3236 times since Sun, Dec 29, 2013
Initial Server Setup with Arch Linux
Viewed 3489 times since Fri, Dec 27, 2013
|