Learn to use Apt

Source: Internet
Author: User
Tags gz file
Introduction:
At the beginning, we had to compile the program we wanted to use on the GNU/Linux system. after Debian appeared, he thought that a method must be included in the system to manage the software packages that we have installed on our machines. this system is named dpkg. so the first time the famous package went into the GNU/Linux system, it was a long time before Red Hat decided to develop their own RPM package management system.
However, a new dilemma lies in the face of GNU/Linux developers. they need a fast and effective software package installation method, which can automatically resolve the dependency of the software package and handle their configuration files with caution during the upgrade. debian solves this problem, resulting in apt generation. Advanced Packaging Tool
Chapter 2 basic configuration
2.1/etc/APT/sources. list file
As part of the operation, APT uses a source file listing where the software package can be obtained. This file is/etc/APT/sources. List.
The entire file is usually in the following format:
Deb http: // host/Debian distribution Section1 section2 section3
Deb-Src http: // host/Debian distribution Section1 section2 section3
Of course, the above is just hypothetical and cannot be used. the first word in each line, Deb or Deb-Src, indicates the type of the document, which contains the changes required for the Debian organization program.
We usually see the following settings in Debian's default sources. List:
These lines are the basic requirements for Debian system installation. the first line Deb points out the official documents, the second line refers to the non-US document, and the third line refers to the Security Update of Debian. the last two lines are comments (starting with #), so apt-Get will ignore them. these are the Deb-Src lines, that is, they pointed out the Debian source code package. if we often need to download the program source code package for testing or re-compilation, do not comment them out.
The/etc/APT/sources. list file contains several types of rows. APT knows how to handle HTTP, FTP, file, and SSH files.
After modifying this configuration file, you must remember to run apt-Get update. We must do this so that APT can get the list of packages from the specified source.
2.2 how to use local Apt
Sometimes we have a lot of. Deb software packages, and we want to use apt to install these software packages, because this will automatically solve the dependency problem between software packages.
To do this, we need to create a directory and then put the. Deb software package we want to index into it. For example:
# Mdkir/root/Debs
We can use an override file to modify the definition set of the control file of the software package to use our own software storage. in this file, we may need to define some options to overwrite the information that comes with the software package. it is in the following format:
Package priority section
Package is the package name. Priority can be low, medium, or high, while section is the part to which it belongs. we can leave the file name Unspecified. We will pass the file name as a parameter to the dpkg-scanpackages program later. if we do not want to write the override file when using the dpkg-scanpackages program, we can use/dev/null.
In the/root directory, run the following command:
# Dpkg-scanpackages Debs file | gzip> Debs/packages.gz
In this example, the filepath is an overridefile, which contains a packages.gz file that contains various apt usage information about these software packages. To use these software packages, add the following content to our configuration file:
Deb file:/root Debs/
Examples file. The program we want to use is also different, we want to use dpkg-scansources. The following command form:
# Dpkg-scansources Debs | gizp> Debs/sources.gz
Pay attention to the dpkg-scansources program and the override file. The configuration file is as follows:
Deb-Src file:/root Debs/
2.3 determine which of the following is the best image in the configuration file: netselect, netselect-Apt
A problem that is often difficult for beginners is: Which Debian image is included in the configuration file ?. There are many ways to determine which image. there are many ways to decide which image to use. experienced users may have a script to detect the testing time of different images. but now we can have a program to help us do this: netselect.
To install netselect, we can install it as usual:
# Apt-Get install netselect
If no parameter is specified to run it, you can get a help message. when you run this program by specifying a list of separated hosts (images) as parameters, a host name and its score are returned. in this way, the download speed is estimated. (Of course, the lower the score, the better ). the returned host is the image with the lowest score (the list of all scores can be listed by the-VV option ). example:
# Netselect ftp.debian.org http.us.debian.org ftp.at.debian.org
Download. ss365 ftp.debian.org.br
From this we can see that ftp.debian.org.br is the best among the images we run this program as parameters.
Now we can put the best image found by the netselect program in our/etc/APT/sources. list file. then we can use the apt command to manage our software packages as usual.
Note: The image column can also be found at http://www.debian.org/#/mirrors_full.
From version 0.3.ds1, The netselect source package contains the netselect-apt Binary Package, which can automatically complete the preceding operations. here, we only need to enter the release version tree as the parameter (the default is the stable version), so that sources. the list file can be generated by the best main and non-US images and saved in the current directory. the following example generates a stable release version of sources. list file:
# Netselect-apt stable
Here we should remember that the generated sources. list file is located in the current directory, and then we will move it to the/etc/apt directory.
Then we can run the apt command as usual.
2.4 Add a CD-ROM to the sources. list file
If we want to use apt to automatically use the CD to install the software package or update the system, we can add CD-ROM to our configuration file. to do this, we can run the apt-CDROM program in the following ways:
# Apt-CDROM add
If he is a normal debain CD, APT will mount him and look for the package information. If our CD-ROM configuration is somewhat different, we can use the following options:
-H program help
-D directory CD-ROM mount point
-R rename recognized CD-ROM
-M is not mounted.
-F: fast mode. Do not check the package file.
-A: Scan Mode
For example:
# Apt-CDROM-D/home/Kov/mycdorm add
We can also specify a CD-ROM, but we don't add it to our configuration list:
# Apt-CDROM idnet
Here we should note that only our CD-ROM in the system/etc/fstab correctly configured this program can work normally.
Chapter 3
Manage Software Packages
3.1 update the package list
The package management system uses a private database to record which software is installed, which software packages are not installed, and which software packages can be installed. the apt-Get program uses this database to find out how to install the software requested by the user and what additional software packages should be installed for the normal operation of the selected software package.
To update this list, we can use the apt-Get update command. This command will search for the software list in the/etc/APT/sources. List document.
A better method is to run this command frequently so that our system can obtain the update information of the software package in time, especially for some security updates.
3.2 install the software package
The last step is the waiting process. if we have prepared our sources. list file and the available software list has been updated. All we need to do is run the apt-GET command to install the required software package. for example:
# Apt-Get install xchat
APT will find the database to get the latest software package and retrieve the software package from the corresponding documentation. if the software package depends on other software packages, APT checks the dependencies and automatically installs the required software packages.
Below are some useful apt-Get options:
-H this help document.
-Q: make the output log available-no progress is displayed
-QQ does not output anything except errors
-D only download-[No] install or unbind the package file
-S does not perform the actual operation. Just simulate the execution of commands in turn
-Y answers all the questions with no prompt
-F when the integrity test fails, the program continues to execute
-M when a package file cannot be found, the program continues to execute
-U: displays the list of upgraded software packages.
-B. Compile the corresponding software package after downloading the source code package.
-V: displays the detailed version number.
Multiple software may be selected for installation in one line. files downloaded from the network will be placed in the/var/Cache/APT/archives directory for future installation.
You can also specify the software package to be deleted in the same command. You only need to add '-' to the name of the software package to be deleted. The following command is available:
# Apt-Get install Nautilus gnome-pane-
If we corrupt an installation package or simply re-install the package with the latest available version, we can use the -- reinstall option, as shown in the following command:
# Apt-Get -- reinstall install TPD
3.3 delete a software package
If we no longer need a software package, we can use apt to delete it from our system. To do this, we only need to enter the command apt-Get remove package. The following example is as follows:
# Apt-Get remove gnome-panel
APT will also be very careful to deal with those software packages dependent on which we want to delete. There is no way to delete a software package without deleting those dependent on it.
When we run the above command, we only delete the corresponding software package and their configuration file still exists in the system. to completely delete a software package, we can run the following command:
# Apt-Get -- purge remove gnome-panel
Just like the install method, we can also convert the meaning of a software package in the Remove Method. if a '+' is placed after the package name, the package will be installed instead of deleted.
3.4 update the software package
Updating the software package is a great success of the apt system. this can be achieved through a single command: APT-Get upgrade. we can use this command to update the software package in the same release version or to an updated version. The latter will reference the apt-Get dist-upgrade command.
It is very useful to add the-u option when running this command. in this way, APT will list the software packages to be updated. if we do not add this option, we will not see this information but simply update the software. APT downloads the latest software packages and installs them in the correct order. before running this command, it is very important to run apt-Get update.
The update process is quite simple. but sometimes the first few lines of our update display some packages will kept back. this means there are new versions of these packages, but they are not installed for some reason. the possible cause may be that the dependency is not satisfied. it may be that the software package on which it depends does not have a corresponding version that can be downloaded or has a new dependency. That is to say, there has been a new dependency since the previous version.
There is no good solution for the previous case, And the next case will prompt you to download the corresponding dependency. A better solution is to use dist-upgrade.
3.5 update to new version
One important feature of APT is that we can use the network or install a CD to update the entire system.
This command is also used when the dependency of the software package changes while installing the software package. When apt-Get upgrade is used, these software packages remain unchanged.
For example, if we are using a stable debain release, and we have now purchased a later debain installation CD. we can use the apt installation CD to update our system. to do this, first use the apt-CDROM command to write the CD to the configuration file, and then run the apt-Get dist-upgrade command.
Here, we should pay attention to the important point that APT always looks for the latest version of the software package. so if the documents listed in our configuration file contain software packages that are later than the software packages on our CD, APT will download the corresponding software packages from there.
To understand the software packages to be maintained or deleted, run the following command:
# Apt-get-O Debug: pkgproblemresolver = Yes dist-Upgrade
3.6 delete unused software packages: APT-get clean and autoclean
When we install the software package apt, We will download the required software package from the corresponding host and store it in our local directory (/var/Cache/APT/archives/), and then execute the installation process.
Over time, this local software package will continue to grow and occupy a large number of disk security rooms. Fortunately, APT provides the methods to manage local software packages: APT-get clean and autoclean.
Apt-Get clean deletes all files other than the locked files in the directory/var/Cache/APT/archives/AND/var/Cache/APT/archives/partial. in this way, if we want to reinstall a software package apt, We need to retrieve them again.
Apt-Get autoclean only deletes software packages that will not be downloaded.
3.7 Use apt with dselect
Dselect is a program that helps you select the debain package to be installed. he is considered to be quite complicated and boring, but after practical use, you will be familiar with this basic text interface program.
One feature of dselect is that he knows how to handle the compatibility between debain package recommendations and recommended packages. to use this program, run dselect as root. select apt as our method. this is not necessary, but if we do not use a CD and we want to download the software package we want to install from the network, the best way is to use dselect.
To use dselect, run the following command:
# Apt-get-u dselect-Upgrade
3.8 how to maintain a hybrid system
Sometimes people are interested in using a debain version as the host version of the system, but using software packages of other branches.
To set the main version of debain, We need to edit/etc/APT/apt. CONF file (normally this file does not exist. You can edit this file if it is not saved). The file content is as follows:
APT: default-release "version"
The current version is the default release version. the available versions can be stable, testing, and unstable. if we want to install other release versions, we need to use the following apt command:
# Apt-get-t distribution install package
To make this command take effect, we need to ensure that the source of the release version is used in our configuration file, and the software package must exist on this source.
We can also use the following syntax to request a special software package version:
# Apt-Get install package = version
Example:
# Apt-Get install Nautilus = 2.2.4-1
Here, we should note that unstable is the earliest debain package version uploaded. this release will affect the software packages on our entire system. we recommend that you do not use this version if you are not experienced.
3.9 how to upgrade a software package from a specific debain version
Apt-show-versions provides a safer method for users who use multiple distribution versions to update their systems, so that they can get fewer unstable versions. for example, after we install the apt-show-versions package, we can run the following command to update our system:
# Apt-Get install 'apt-show-versions-u-B | grep unstable | cut-d'-F l'
3.10 how to keep the software package of the specified version unchanged
Sometimes we may have modified some content in a software package, and we don't have time or want to upgrade these modifications to a new version. for example, we may have just upgraded our system to debian3.0, but we still want to use some software packages in debian2.2. we can keep these installed software packages without upgrading them.
This method is quite simple. We need to modify the/etc/APT/preferences file.
The format is as follows:
Package: <package>
Pin: <pin definition>
Pin-priority: <pin's priority>
Each input must be separated by spaces. For example, if we want to keep the modified sylpheed software package "reply-to-list" of version 0.4.99, we can add the following content:
Package: sylpheed
Pin: Version 0.4.99 *
Here we use *, which is a wildcard. in other words, we hope that all versions starting with 0.4.99 will be applicable. this is because Debian names the software packages starting with Debian, and we do not want to avoid installation of these software packages. for example, if 0.4.99-1 and 0.4.99-10 are available, they can be installed immediately. if we do not want to use this method, we can modify this software package.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.