Ubuntu: apt command

apt command is a powerful command-line tool that not only can update the package list index, the installation of new software packages, upgrade of existing software packages, but also to upgrade the entire system Ubuntu (Debian-based operating system is apt package management tool) .
Tool apt-get and apt-cache compared with more professional APT (Advanced Packaging Tool), apt to have some more options for interactive scenarios, it is more inclined to become a tool for End Users (not just the system administrator ). In other words, apt easier than apt-get with it, a better user experience.
This article describes the basic usage of the command apt demonstration environment for Ubuntu 18.04.

The basic syntax

Syntax:
APT [Options] the Command

Profile:
Early apt default profile for /etc/apt/apt.conf, but the current system default Ubuntu does not have this file.
If /etc/apt/apt.conf file exists, apt will still read it. But now the idea is to design the configuration files are placed in the rear partition /etc/apt/apt.conf.d directory, it is easier to manage.

Common subcommands:
Update
Update command packet from the source download configuration information. update command should always be executed before the installation or upgrade package.

upgrade
upgrade command to upgrade the current system can be used to install all of the packets from the source configuration. If you need to satisfy dependencies to install new packages, but does not delete existing packages. If you need to remove the upgrade package installed package, this package upgrade is not performed.

upgrade-Full
Full-upgrade command to perform the upgrade function, if you need to upgrade to the new version will remove the current installed packages.

the install, Remove, purge
the install command to install one or more designated packets. remove command to remove the package, but preserves the configuration files package. purge command removes its configuration file in the removal of the package at the same time.

autoremove
autoremove command deletes automatically install the packages that are automatically installed to satisfy dependencies to other packages, with the change of dependency or need their packages have been removed, these packages are now no longer needed.

Search
Search command for searching the list of available packages given item and to display the matching content. For example, if you are looking package with a specific function, which will be very useful.

Show
Show command to display information about a given packet, including its dependencies, installation and download size, packet source, packet contents description of the like. For example, see this information before deleting a package or a new package search to install is helpful.

List
List command to display a list of packages that meet specific criteria, listing all of the default package. You can list the installed package by --installed option, - upgrade options listed can be upgraded package.

Sources-Edit
Edit Edit /etc/apt/source.list-Sources command file:
$ sudo APT-Edit Sources

Common usage

Update package index files

$ sudo apt update

Installation package

$ sudo apt install nginx

Install the specified version of the package

$ sudo apt install vim=2:8.0.1453-1ubuntu1

Install local deb package files

$ sudo apt install name.deb

This method will automatically download and install the dependent packages.

Install the system in a newer package
upgrade command to upgrade the installed packages, with but does not remove any package. Its goal is to ensure that possible to minimize the invasive upgrade:

$ sudo apt update
$ sudo apt upgrade

Delete packages
by the following two commands can be deleted using the apt install installation packages:

$ sudo apt remove nmap
$ sudo apt purge nmap

Which remove command will retain the configuration file, and purge command will delete the profiles together.

View packet

$ apt show vim
Package: vim
Version: 2:8.0.1453-1ubuntu1.1
Priority: optional
Section: editors
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian Vim Maintainers <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 2,852 kB
Provides: editor
Depends: vim-common (= 2:8.0.1453-1ubuntu1.1), vim-runtime (= 2:8.0.1453-1ubuntu1.1), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.7), libpython3.6 (>= 3.6.5), libselinux1 (>= 1.32), libtinfo5 (>= 6)
Suggests: ctags, vim-doc, vim-scripts
Homepage: https://vim.sourceforge.io/
Task: cloud-image, server
Supported: 5y
Download-Size: 1,152 kB
APT-Manual-Installed: yes
APT-Sources: http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
Description: Vi IMproved - enhanced vi editor
 Vim is an almost compatible version of the UNIX editor Vi.
...

输出指定条件的包列表
可以指定某个包的名称,否则会输出大量的信息 :

$ apt list vim

$ apt list docker

还可以使用统配符:

可以通过 --installed 选项列出所有已安装的包,而 --upgradable 选项则列出所有可以升级的包:

搜索包
search 命令用于在可用包列表中搜索给定的项并显示匹配到的内容。比如下面的命令,我们搜索 docker,与之相关的 cadvisor 也被搜索出来了:

$ apt search docker

apt 与 apt-get 的区别
简单来说 apt 命令就是 apt-get、apt-cache 和 apt-config 中最常用命令选项的集合。下面是几个常见命令的对照关系:
list:与 dpkg --list 相似
search:与 apt-cache search 相似
show:与 apt-cache show 相似
update:与 apt-get update 相同
install/remove:与 apt-get install/remove 相似,但是多了进度条提示
upgrade:与 apt-get upgrade --with-new-pkgs 相同
full-upgrade:与 apt-get dist-upgrade 相似

在我们使用的过程中,比较明显的区别是可以看到 apt 命令的进度条,个人感觉并不是太有用。

执行 apt update 命令,会提示可以升级的包的个数,而 apt-get update 命令则没有这样的提升:

$ sudo apt update
...
Fetched 8,932 kB in 31s (288 kB/s)                                                   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
28 packages can be upgraded. Run 'apt list --upgradable' to see them.

 

参考:
apt man page
维护和更新:APT 工具
What is the difference between apt and apt-get?

Guess you like

Origin www.cnblogs.com/sparkdev/p/11357343.html