apt-get update和apt-get upgrade的区别

​apt-get update​​​这个命令是用来更新软件列表,会访问软件源列表里的每个网址,并读取软件列表信息,然后保存在本地主机。在软件包管理器里看到的软件列表,都是通过​​update​​命令更新的。

root@a9c755ae3d9f ~# apt-get update                                                                                                                                                                          100
Hit:1 http://mirrors.163.com/ubuntu xenial InRelease
Get:2 http://mirrors.163.com/ubuntu xenial-security InRelease [109 kB]
Get:3 http://mirrors.163.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://mirrors.163.com/ubuntu xenial-proposed InRelease [260 kB]
Get:5 http://mirrors.163.com/ubuntu xenial-backports InRelease [107 kB]
Get:6 http://mirrors.163.com/ubuntu xenial-security/main Sources [300 kB]
Get:7 http://mirrors.163.com/ubuntu xenial-security/restricted Sources [3239 B]
Get:8 http://mirrors.163.com/ubuntu xenial-security/universe Sources [251 kB]
Get:9 http://mirrors.163.com/ubuntu xenial-security/multiverse Sources [4946 B]
Get:10 http://mirrors.163.com/ubuntu xenial-security/main amd64 Packages [1874 kB]
Get:11 http://mirrors.163.com/ubuntu xenial-security/restricted amd64 Packages [15.9 kB]
Get:12 http://mirrors.163.com/ubuntu xenial-security/universe amd64 Packages [978 kB]
Get:13 http://mirrors.163.com/ubuntu xenial-security/multiverse amd64 Packages [9252 B]
Get:14 http://mirrors.163.com/ubuntu xenial-updates/main Sources [656 kB]
Get:15 http://mirrors.163.com/ubuntu xenial-updates/restricted Sources [3941 B]
Get:16 http://mirrors.163.com/ubuntu xenial-updates/universe Sources [542 kB]
Get:17 http://mirrors.163.com/ubuntu xenial-updates/multiverse Sources [13.5 kB]
Get:18 http://mirrors.163.com/ubuntu xenial-updates/main amd64 Packages [2386 kB]
Get:19 http://mirrors.163.com/ubuntu xenial-updates/restricted amd64 Packages [16.4 kB]
Get:20 http://mirrors.163.com/ubuntu xenial-updates/universe amd64 Packages [1530 kB]
Get:21 http://mirrors.163.com/ubuntu xenial-updates/multiverse amd64 Packages [26.8 kB]
Get:22 http://mirrors.163.com/ubuntu xenial-proposed/main Sources [22.3 kB]
Get:23 http://mirrors.163.com/ubuntu xenial-proposed/universe Sources [7390 B]
Get:24 http://mirrors.163.com/ubuntu xenial-proposed/main amd64 Packages [75.7 kB]
Get:25 http://mirrors.163.com/ubuntu xenial-proposed/universe amd64 Packages [19.2 kB]
Get:26 http://mirrors.163.com/ubuntu xenial-backports/main Sources [7276 B]
Get:27 http://mirrors.163.com/ubuntu xenial-backports/universe Sources [12.3 kB]
Get:28 http://mirrors.163.com/ubuntu xenial-backports/main amd64 Packages [10.9 kB]
Get:29 http://mirrors.163.com/ubuntu xenial-backports/universe amd64 Packages [12.6 kB]
Fetched 9365 kB in 2s (3357 kB/s)
Reading package lists... Done

软件源列表:

root@a9c755ae3d9f ~# vim /etc/apt/sources.list

deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse

而更新已经安装的软件包可以使用​​apt-get upgrade​​命令:

root@a9c755ae3d9f ~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
apt apt-transport-https base-files bash bind9-host bsdutils bzip2 ca-certificates cpio cpp-5 curl debconf dh-python distro-info-data dnsutils dpkg dpkg-dev e2fslibs e2fsprogs file g++-5 gcc-5 gcc-5-base
gfortran-5 git git-man icu-devtools iproute2 libapparmor1 libapt-inst2.0 libapt-pkg5.0 libarchive13 libasan2 libatomic1 libbind9-140 libblkid1 libbsd0 libbz2-1.0 libbz2-dev libc-bin libc-dev-bin libc6
libc6-dev libcc1-0 libcilkrts5 libcomerr2 libcurl3 libcurl3-gnutls libdb5.3 libdbus-1-3 libdns162 libdpkg-perl libelf1 libexpat1 libexpat1-dev libfdisk1 libfreetype6 libfreetype6-dev libgcc-5-dev
libgcrypt20 libgcrypt20-dev libgd3 libgfortran-5-dev libgfortran3 libglib2.0-0 libgnutls-dev libgnutls-openssl27 libgnutls30 libgnutlsxx28 libgomp1 libgssapi-krb5-2 libicu-dev libicu55 libisc160
libisccc140 libisccfg140 libitm1 libjpeg-turbo8 libk5crypto3 libkrb5-3 libkrb5support0 libldap-2.4-2 liblsan0 liblwres141 libmagic1 libmount1 libmpx0 libnss3 libnss3-dev libnss3-nssdb libpam-modules
libpam-modules-bin libpam-runtime libpam0g libpcap0.8 libperl5.22 libprocps4 libpython3.5 libpython3.5-minimal libpython3.5-stdlib libquadmath0 libsasl2-2 libsasl2-modules-db libseccomp2 libsmartcols1
libsqlite3-0 libsqlite3-dev libss2 libssl-dev libssl1.0.0 libstdc++-5-dev libstdc++6 libsystemd0 libtiff5 libtsan0 libubsan0 libudev1 libuuid1 libvpx3 libx11-6 libx11-data libx11-dev libxml2 libxml2-dev
libxslt1-dev libxslt1.1 linux-libc-dev locales login lshw mount multiarch-support openssh-client openssh-server openssh-sftp-server openssl passwd patch perl perl-base perl-modules-5.22 procps
python-apt-common python3-apt python3-software-properties python3.5 python3.5-minimal rsync software-properties-common sudo systemd systemd-sysv tcpdump tzdata ubuntu-keyring util-linux vim vim-common
vim-runtime zlib1g zlib1g-dev
161 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 124 MB of archives.
After this operation, 246 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...
Updating certificates in /etc/ssl/certs...
30 added, 40 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
  • ​apt-get update​​​:是同步​​/etc/apt/sources.list​​​和​​/etc/apt/sources.list.d​​中列出的软件源的软件包版本,这样才能获取到最新的软件包。
  • ​apt-get upgrade​​​:是更新已安装的所有或者指定软件包,升级之后的版本就是本地索引里的,因此,在执行 ​​upgrade​​​ 之前一般要执行​​update​​,这样安装的才是最新的版本。

​apt-get upgrade​​可将软件进行更新,但是不建议一次性全部更新,因为最新的不一定是最好的,有可能出现版本不兼容的情况。

指定需要更新的软件:

apt-get upgrade apt gcc
root@a9c755ae3d9f /# apt-get upgrade apt gcc                                                                                                                                                                 100
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc is already the newest version (4:5.3.1-1ubuntu1).
gcc set to manually installed.
apt is already the newest version (1.2.32ubuntu0.1).
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
aufs-tools cgroupfs-mount
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.