Linux apt 简单使用教程
apt是一个Linux的软件包管理工具。通过apt您可以很方便的 安装、更新、卸载软件。
apt和yum差不多,都可以算是Linux 上的一个应用商店。不过apt主要是在Debian和Ubuntu这一类 Debian系的Linux上使用,而yum主要是在CentOS和Fedora这一类RedHat系的Linux上使用。
安装软件
安装软件可以使用:
apt install 软件名称下面安装vim:
apt install -y vim其中的-y就是无需手动确认安装,如果不加-y的话,安装每一个依赖程序都需要手动输入y确认。
如果要一次安装多个软件可以这样写:
apt install zip rar上面的zip和rar都是软件名称。
在默认情况下,apt安装的软件都是最新版本的。如果需要安装老版本的软件可以在软件名称后面加 =版本 ,如下:
apt install php=5.6更新软件
如果要查看可更新的软件可以使用:
apt list --upgradeable列表如下:
apt/oldstable,oldstable 1.4.9 amd64 [可从该版本升级:1.4.6]
apt-utils/oldstable,oldstable 1.4.9 amd64 [可从该版本升级:1.4.6]
base-files/oldstable 9.9+deb9u11 amd64 [可从该版本升级:9.9]
bind9-host/oldstable,oldstable 1:9.10.3.dfsg.P4-12.3+deb9u5 amd64 [可从该版本升级:1:9.10.3.dfsg.P4-12.3]
bsdutils/oldstable,oldstable 1:2.29.2-1+deb9u1 amd64 [可从该版本升级:1:2.29.2-1]
cron/oldstable 3.0pl1-128+deb9u1 amd64 [可从该版本升级:3.0pl1-128+b1]
dbus/oldstable,oldstable 1.10.28-0+deb9u1 amd64 [可从该版本升级:1.10.18-1]
debian-archive-keyring/oldstable,oldstable-updates 2017.5+deb9u1 all [可从该版本升级:2017.5]
discover/oldstable 2.1.2-7.1+deb9u1 amd64 [可从该版本升级:2.1.2-7.1]
dpkg/oldstable 1.18.25 amd64 [可从该版本升级:1.18.24]
e2fslibs/oldstable 1.43.4-2+deb9u1 amd64 [可从该版本升级:1.43.4-2]
e2fsprogs/oldstable 1.43.4-2+deb9u1 amd64 [可从该版本升级:1.43.4-2]
file/oldstable 1:5.30-1+deb9u3 amd64 [可从该版本升级:1:5.30-1]
gcc-6-base/oldstable,oldstable 6.3.0-18+deb9u1 amd64 [可从该版本升级:6.3.0-18]
gettext-base/oldstable 0.19.8.1-2+deb9u1 amd64 [可从该版本升级:0.19.8.1-2]
gnupg/oldstable 2.1.18-8~deb9u4 amd64 [可从该版本升级:2.1.18-6]
gnupg-agent/oldstable 2.1.18-8~deb9u4 amd64 [可从该版本升级:2.1.18-6]
gpgv/oldstable 2.1.18-8~deb9u4 amd64 [可从该版本升级:2.1.18-6]如果需要更新所有已安装的软件可以使用:
apt upgradable如果需要更新apt的软件数据库可以使用:
apt update如果要更新单个软件可以直接使用安装命令,当apt检测到软件已安装时就会更新软件。
卸载软件
删除软件可以使用:
apt remove 软件名称如果要彻底卸载软件可以使用:
apt purge 软件名称apt remove只会删除软件本体,对于软件的配置文件之类的是不会删除的。apt purge可以直接删除软件和相关的配置文件。
查找软件
搜索软件可以使用:
apt search 软件名称apt search会列出所有和搜索词相关的软件。
下面搜索vsftpd:
root@localhost:~# apt search vsftpd
正在排序... 完成
全文搜索... 完成
ccze/oldstable 0.2.1-3 amd64
robust, modular log coloriser
ftpd/oldstable 0.17-36 amd64
File Transfer Protocol (FTP) server
resource-agents/oldstable 1:4.0.0~rc1-4 amd64
Cluster Resource Agents
vsftpd/oldstable 3.0.3-8+b1 amd64
lightweight, efficient FTP server written for security
vsftpd-dbg/oldstable 3.0.3-8+b1 amd64
lightweight, efficient FTP server written for security (debug)
yasat/oldstable 848-1 all
simple stupid audit tool要查看一个软件的详细信息可以使用:
apt show 软件名称下面查看 vim 的详细信息:
pi@raspberrypi:/ $ apt show vim
Package: vim
Version: 2:8.0.0197-4+deb9u3
Priority: optional
Section: editors
Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
Installed-Size: 1,925 kB
Provides: editor
Depends: vim-common (= 2:8.0.0197-4+deb9u3), vim-runtime (= 2:8.0.0197-4+deb9u3), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.4), libselinux1 (>= 1.32), libtinfo5 (>= 6)
Suggests: ctags, vim-doc, vim-scripts
Homepage: http://www.vim.org/
Download-Size: 791 kB
APT-Manual-Installed: yes
APT-Sources: http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages
Description: Vi IMproved - enhanced vi editor
Vim is an almost compatible version of the UNIX editor Vi.
.
Many new features have been added: multi level undo, syntax
highlighting, command line history, on-line help, filename
completion, block operations, folding, Unicode support, etc.
.
This package contains a version of vim compiled with a rather
standard set of features. This package does not provide a GUI
version of Vim. See the other vim-* packages if you need more
(or less).如果要查看已安装的软件可以使用:
apt list --installed更改 Debian apt 镜像源
Debian官方的apt镜像源在国内使用速度可能会比较慢。国内的阿里、网易、清华大学 等 都提供Debian的apt镜像源。
下面以网易为例,简单写一下Debian更改apt为国内镜像源的方法。
首先需要查看 Debian 的版本,可以使用:
cat /etc/debian_version查询结果如下:
pi@raspberrypi:/ $ cat /etc/debian_version
9.13
pi@raspberrypi:/ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"注意其中的stretch,这是版本代号。
Debian的镜像源配置文件在/etc/apt/sources.list,为防止出现意外可以先备份一下默认的配置文件:
cp /etc/apt/sources.list /etc/apt/sources.list-backup删除默认的配置文件:
rm /etc/apt/sources.list进入网易的Debian镜像下载页面,下载和系统版本代号对应的配置文件。
这里以stretch版为例,把stretch版的配置文件下载到 /etc/apt目录:
wget -P /etc/apt https://mirrors.163.com/.help/sources.list.stretch下载完成后去除多余的后缀:
mv /etc/apt/sources.list.stretch /etc/apt/sources.list上面只是以网易的镜像源为例,不一定适用于其它镜像源。有的镜像源需要复制配置信息到默认配置文件中粘贴。
无论是网易还是其它的镜像源,主要都是更改配置文件,只是更改的方式不一样。
















