Linux apt command

On Linux operating systems that use the APT package management system, the apt command installs, removes, upgrades, and manages software packages. It automatically manages package dependencies, installing required software as needed, and removing it when no longer required.

Description

The apt command performs a similar function to apt-get, but with some additional functions, conveniences, and features. For instance, it provides colorization and fancier formatting of text output, and an animated progress bar when installing software. However, these formatting changes make apt unsuitable for capturing output to a file, or processing it with another tool such as grep. If you need to save or process the output of apt, it's a good idea to use apt-get instead.

Apt is available on several modern Linux distributions, primarily Debian and Ubuntu. It is also available on Windows 10 systems that use the default Ubuntu Windows Subsystem for Linux.

Syntax

apt [-h] [-o=config_string] [-c=config_file] [-t=target_release]
    [-a=architecture] {list | search | show | update |
    install pkg [{=pkg_version_number | /target_release}]... |
    remove pkg... | upgrade | full-upgrade | edit-sources | 
    {-v | --version} | {-h | --help}}

Commands

Tip

Any commands listed below that make changes to your system must be run by the superuser, or with the sudo command.

updateThe update command downloads up-to-date information about available software packages. This information is used by apt to perform most of its other operations, including installation, upgrading, dependency management, and listing package information.

An update should always be run before an upgrade or a full-upgrade.
upgrade pkgInstall the upgraded versions of package pkg. If no package is specified, all currently-installed packages are upgraded.
full-upgradePerform an upgrade, but also remove outdated or incompatible packages, if necessary, to fully upgrade the system. This is the equivalent of apt-get dist-upgrade.
install pkgInstalls the package named pkg. The name pkg can be the exact name of a package, a regular expression, or use wildcards.

In this command, and with remove and purge, you can specify multiple package names with a plus sign ("+") or a minus sign ("-") at the end of the name to mark it for installation or removal. You can also append an equals sign ("=") at the end of the name, followed by a specific version number, to apply the command only to that version of the software. If you add a slash ("/") followed by a release codename of your Linux distribution, apt will use the software package from that release. See examples, below.
remove pkgUninstall the software package named pkg, but do not remove any configuration files that might have been modified on your system. Similar to install, regular expressions or wildcards can be used to specify pkg; the +, - symbols can be appended to the package name to specify installation or removal; = and / symbols can be appended to specify software version or release codename.
purge pkgUninstall pkg, and purge any associated configuration files. Similar to install, regular expressions or wildcards can be used to specify pkg; the +, - symbols can be appended to the package name to specify installation or removal; = and / symbols can be appended to specify software version or release codename.
autoremoveThe autoremove command will remove any packages that were previously required as dependencies of other software, which are no longer required. Running this command periodically will conserve disk space. If packages are eligible for autoremoval, they will be reported when you perform other operations such as apt update.

If a software package is marked for autoremoval because it is no longer required, but you'd like to keep it, you can mark it as manually installed using the command apt-mark.
search textSearch for available packages whose names or descriptions contain the text text, which can include regular expressions and wildcards. This is the equivalent of apt-cache search. If you're looking for a package which contains a certain file, you can use the command apt-file.
show pkgDisplay information about pkg, including a brief description, what its dependencies are, and how much disk space the package requires. Regular expressions and wildcards may be used in the package name. This command is equivalent to apt-cache show.
listList packages that meet a certain set of criteria. With no other options, lists all available package names. With the option --all-versions, lists all available versions of all packages. With --installed, lists all currently-installed packages, similar to dpkg --list. With --upgradable, lists all installed packages that can be upgraded.
edit-sourcesOpens your list of package sources in a text editor, and checks the file for errors after you save and close it. Editing your sources list will change the Internet location where apt gets information about, and downloads, software packages.

Options

-v, --versionDisplay information about what version of apt you are using.
-h, --helpDisplay a brief listing of available commands and options.
-yAssume the answer "yes" to any prompts, proceeding with all operations if they are possible.
--assume-noAssume the answer "no" to all prompts.
-d,
--download-only
For any operation that would download packages, download them, but do nothing else.
-f,
--fix-broken
When used with install or remove, this option will attempt to fix any broken dependencies.
--no-downloadDo not download any packages. This forces apt to use only packages it has already downloaded.
-s,
--simulate
Simulate operations, reporting what they would do, but make no changes to the system.

Examples

sudo apt update && sudo apt upgrade

Update information about available packages, and then upgrade all installed packages on your system. You will be prompted before installation begins.

sudo apt update && sudo apt -y upgrade

Same as above, but automatically answer yes to the prompt.

sudo apt install vim

Install the vim software package and its dependencies.

sudo apt install "vim*"

Install any packages whose name starts with "vim". The package name is enclosed in quotes to make sure the wildcard ("*", meaning match anything) is passed to apt rather than interpreted by the shell.

apt show fortune

Display information about the package named fortune.

sudo apt install lolcat vim-gnome-

Install the package lolcat, and remove the package vim-gnome.

sudo apt remove lolcat+ vim-gnome

Remove the package vim-gnome, and install the package lolcat.

apt list --all-versions zypper

List all available versions of the software package zypper.

sudo apt install zypper=1.12.4-1

Install version 1.12.4-1 of zypper.

sudo apt install zypper/xenial

On Ubuntu, install the default version of zypper provided by Ubuntu 16.04, whose codename is xenial.

apt-cache — Get information about software packages available through APT.
apt-file — Search for individual files in all available APT packages.
apt-get — Command line tool for managing APT software packages.
apt-mark — Change or view the settings of individual APT packages.
aptitude — Text-based front end for the APT package management system.
dpkg — Install, remove, and maintain Debian software packages.

 

https://www.computerhope.com/unix/apt.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值