In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How do I use the apt-get command in Ubuntu? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Basic grammar
Syntax format:
Apt-get [options] command
Configuration file:
The default configuration file for earlier apt-get is / etc/apt/apt.conf, but it is not available on current Ubuntu systems by default.
If the / etc/apt/apt.conf file exists, apt-get still reads it. But the current design idea is to separate the configuration files and place them in the / etc/apt/apt.conf.d directory, which makes it easier to manage.
Common options:
-h,-- help / / View help documentation-v,-- version / / View the version of apt-get-y / / respond to yes-s in scenarios that need to be confirmed,-- dry-run / / simulate execution and output results-d -- download-only / / download the package to the cache without installing-- only-upgrade / / update the current version of the package instead of installing the new version-- no-upgrade / / when executing the install command Do not install updates to installed packages-Q,-quiet / / reduce output-purge / / cooperate with remove command to delete package configuration files-reinstall / / reinstall installed packages or their new versions
Common subcommands:
Update
The update command is used to resynchronize the package index file, and the configuration in the / etc/apt/sources.list file specifies the source of the package index file. After updating the package index file, you can get the available package update information and new package information. In this way, we have local information about which versions of the software can be installed from where (source).
The update command should always be executed before installing or upgrading the package.
Install
The install command is used to install or upgrade packages. Each package has a package name instead of a fully qualified file name (for example, in a Debian system, the parameter provided is apt-utils, not apt-utils_1.6.1_amd64.deb). Packages that depend on the installed package will also be installed. The configuration file / etc/apt/sources.list contains the source (server) used to get the package. The install command can also be used to update specified packages.
Upgrade
The upgrade command installs the latest version of all packages currently installed on the system from the source listed in / etc/apt/sources.list. In any case, currently installed packages will not be removed, and packages that have not yet been installed will not be retrieved and installed. If the new version of the currently installed package cannot be upgraded without changing the installation status of another package, the current version is retained. The update command must be executed in advance so that apt-get knows if a new version of the installed package is available.
Note the difference between update and upgrade:
Update is the list of updated software, and upgrade is the updated software.
Dist-upgrade
In addition to performing upgrade functions, dist-upgrade intelligently handles changes in dependencies with new versions of the package. Apt-get has a "smart" conflict resolution system that, if necessary, will try to upgrade the most important packages at the expense of less important packages. Therefore, the distr-upgrade command may delete some packages. Therefore, when updating packages in the system, it is recommended that you execute the following commands in order:
$apt-get update$ apt-get upgrade-y $apt-get dis-upgrade-y
Remove
Remove is similar to install, except that you delete the package instead of installing it. Note that deleting a package using the remove command leaves its configuration file on the system.
Purge
The purge command is similar to the remove command, where the purge command deletes the configuration file of the package as well as the package.
Autoremove
The autoremove command is used to remove automatically installed packages that were originally installed to satisfy the dependencies of other packages but are no longer needed.
Download
The download command downloads the binaries of the specified package to the current directory. Note that it is a package file like * .deb.
Clean
The clean command clears the packages retrieved in the local library. It removes everything except the lock file from the / var/cache/apt/archives/ and / var/cache/apt/archives/partial/ directories.
Autoclean
Similar to the clean command, the autoclean command clears the local repository of retrieved package files. The difference is that it only deletes package files that can no longer be downloaded, and these files are largely useless. This allows the cache to be maintained for a long time without getting out of control.
Source
The source command downloads the source code of the package. The latest available version of the source code is downloaded to the current directory by default.
Changelog
The changelog command attempts to download and display the update log for the package.
Common usage
View help documentation
$apt-get-h
Update package index file
$sudo apt-get update
Installation package
$sudo apt-get install nginx
Respond to yes in scenarios that need confirmation
Most packages need to interact with the user before installation and continue the installation after the user confirms it. There is no way to interact with users in automated tasks. The-y option can work in such scenarios as if the user had confirmed the installation:
$sudo apt-get install-y nginx
There are updated packages in the installation system
$sudo apt-get update$ sudo apt-get upgrade-y $sudo apt-get dis-upgrade-y
Reinstall the installed package
If we think a package is not working properly, we can try to reinstall it and add the-- reinstall option to the install command. In addition, if the installed package has an updated or new version, you can also use this method to upgrade the package to the latest version:
$sudo apt-get install-reinstall curl
Update the specified package
It is strange that updating the specified package is not done through the upgrade command, but using the intall command. Note: it is the install command:
$sudo apt-get install vim
Simulate the execution of commands and output the results
The command is not actually executed when the-s option is applied, but the execution is simulated and the result is output, such as the following example:
$sudo apt-get update$ sudo apt-get-s upgrade
When the-s option is added, the upgrade command outputs the software to be updated but does not actually perform the upgrade.
Check the version of a package
You can view the version of the installed package or the package to be installed with the following command:
$sudo apt-get-s install vim
Here is an example of an installed package:
Here is an example of an uninstalled package:
Install the specified version of the package
Note that this refers to the version number of the package:
$sudo apt-get install tree=1.7.0-5
Download the package to the cache without installing it
The option-d,-- download-only tells the command to only download packages to the cache without installing them, mainly in scenarios that separate the download package from the installation package, such as the system's default automatic updates:
$sudo apt-get install-d nginx$ sudo apt-get upgrade-d $sudo apt-get dist-upgrade-d
Delete package
The remove command is characterized by deleting only the program files and retaining the relevant configuration files:
$sudo apt-get remove vim
If you want to clear the package completely, you can use the purge command, which deletes both the program file and its configuration file:
$sudo apt-get purge vim
The autoremove command is used to remove automatically installed packages that were originally installed to satisfy the dependencies of other packages but are no longer needed. So it's a good choice to perform an autoremove after deleting the package:
$sudo apt-get autoremvoe
Clear the cached package installation files in the system
The process of installing the package is actually downloading the package installation file to the cache directory, and then performing the installation. Over time, there will be a large number of useless package installation files in the system, and the clean command can clear these cached package installation files:
$sudo apt-get clean
The clean command removes everything except the lock file from the / var/cache/apt/archives/ and / var/cache/apt/archives/partial/ directories.
The autoclean command is similar to clean command. The difference is that it only deletes package files that can no longer be downloaded, and these files are largely useless. This allows the cache to be maintained for a long time without getting out of control:
$sudo apt-get autoclean
Using the-- purge option when executing the remove command has the same effect as executing the purge command:
$sudo apt-get remove-purge vim
Use the-- autoremove option when executing the install/remove command to delete useless dependent packages at the same time, similar to executing the autoremove command again after the install/remove command:
$sudo apt-get remove-autoremove vim
Display more detailed version information when executing the install/upgrade command
With the-V option, you can have the install/upgrade command output a specific version of the package. Here is the default output:
$sudo apt-get upgrade-s
The following is the output after adding the-V option:
$sudo apt-get upgrade-V-s
Reduce output
Now that you can add detailed output information, you can also flexibly use the-Q option to reduce the output information:
$sudo apt-get install-Q curl$ sudo apt-get install-Qip2 curl
View the change log of the installed package
You can view the update record of the package through the changelog command:
$apt-get changelog tree
Download the source code of the package (source code)
The apt-get source command is used to download the source code of the package. For the apt-get source command to work, you need to update the / etc/apt/sources.list file and add the deb-src configuration, which is actually canceling the lines that have been commented out that start with deb-src. In the desktop version of the system, you can also do the same thing with the "Software & Updates" UI, by selecting the "Source code" item in the "Ubuntu Software" tab:
Now execute the apt-get source command and specify the name of the package, and you can download the source code of the package:
$apt-get source tree
View the version of apt-get
$apt-get-v
It's so weird that what is shown here is apt. Go on to see:
It turns out that the functions of apt-get, apt-cache, and apt-config are provided by the apt command.
View the update record of the system
The log file / var/log/apt/history.log records the update history of the system. It allows you to view all installation, upgrade, and delete records performed through the apt command:
Less / var/log/apt/history.log after reading the above, have you mastered how to use the apt-get command in Ubuntu? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.