Ubuntu Server 16.04更新系统软件包

大伟哥 提交于 2017-08-29,周二, 09:20 ,最近更新于2017-08-30,周三, 20:07

新安装Ubuntu Server 16.04以后,在初次登录系统之后,我们看到了系统给出的提示:

  1. Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)
  2.  
  3. * Documentation: https://help.ubuntu.com
  4. * Management: https://landscape.canonical.com
  5. * Support: https://ubuntu.com/advantage
  6.  
  7. 131 packages can be updated.
  8. 62 updates are security updates.

这说明我们的系统的软件包不是最新的,有131个软件包已经有了更新,其中有62个是安全更新。为了系统的稳定和安全,我们需要安装这些更新。以下是Ubuntu安装更新的大体步骤:

1. 确定是否要替换到更快的软件源。

Ubuntu的软件源是在定义在/etc/apt/sources.list文件里面,如果你的服务器是在国外,如美国,可以使用默认的官方软件源。如果你是在国内使用,官方的源可能速度太慢,可以考虑根据实际情况切换到国内大公司或者学校的源,比如网易源、搜狐源、阿里云源、中科大源、清华大学源等。这里我们采用Ubuntu的默认源。

2. 执行sudo apt-get update

  1. daweibro@Web-Ubuntu-Server-1604:~$ sudo apt-get update
  2. [sudo] password for daweibro:
  3. Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
  4. Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
  5. Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
  6. Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
  7. Fetched 306 kB in 7s (42.8 kB/s)
  8. Reading package lists... Done
  9. daweibro@Web-Ubuntu-Server-1604:~$

sudo是以管理员身份执行指令。apt-get update指令是更新同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,获取到最新的软件包。

执行sudo apt-get upgrade

  1. daweibro@Web-Ubuntu-Server-1604:~$ sudo apt-get upgrade
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Calculating upgrade... Done
  6. The following packages have been kept back:
  7. linux-generic linux-headers-generic linux-image-generic
  8. The following packages will be upgraded:
  9. apparmor apport apt apt-transport-https apt-utils base-files bash bind9-host
  10. bsdutils btrfs-tools cloud-initramfs-copymods cloud-initramfs-dyn-netconf
  11. coreutils distro-info-data dnsmasq-base dnsutils dpkg eject git git-man
  12. grub-legacy-ec2 init init-system-helpers iproute2 isc-dhcp-client
  13. isc-dhcp-common kmod less libapparmor-perl libapparmor1 libapt-inst2.0
  14. libapt-pkg5.0 libasn1-8-heimdal libbind9-140 libblkid1 libc-bin libc6
  15. libdns-export162 libdns162 libdrm2 libevent-2.0-5 libexpat1 libfdisk1
  16. libgcrypt20 libgnutls-openssl27 libgnutls30 libgssapi3-heimdal
  17. libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  18. libhx509-5-heimdal libicu55 libisc-export160 libisc160 libisccc140
  19. libisccfg140 libkmod2 libkrb5-26-heimdal libldap-2.4-2 liblwres141 liblxc1
  20. libmount1 libmspack0 libnl-3-200 libnl-genl-3-200 libpam-systemd libpci3
  21. libroken18-heimdal librtmp1 libsmartcols1 libssl1.0.0 libsystemd0 libtasn1-6
  22. libudev1 libuuid1 libwind0-heimdal libxml2 linux-firmware locales login
  23. logrotate lxc-common lxcfs lxd lxd-client makedev mdadm mount
  24. multiarch-support nano open-iscsi openssh-client openssh-server
  25. openssh-sftp-server openssl overlayroot passwd pciutils python3-apport
  26. python3-distupgrade python3-problem-report python3-software-properties
  27. python3-update-manager resolvconf snap-confine snapd
  28. software-properties-common sosreport sudo systemd systemd-sysv tcpdump
  29. ubuntu-core-launcher ubuntu-release-upgrader-core udev uidmap
  30. unattended-upgrades update-manager-core update-notifier-common util-linux
  31. uuid-runtime vlan wget zlib1g
  32. 124 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
  33. Need to get 98.7 MB of archives.
  34. After this operation, 19.5 MB of additional disk space will be used.
  35. Do you want to continue? [Y/n]

系统列出了124个需要更新的软件,要安装这些更新需要下载98.7M,安装后额外占用19.5M的硬盘空间。询问我们是否要继续,要继续则键入Y确认,取消键入n.

  1. Setting up overlayroot (0.27ubuntu1.4) ...
  2. Setting up vlan (1.9-3.2ubuntu1.16.04.3) ...
  3. Installing new version of config file /etc/network/if-pre-up.d/vlan ...
  4. Setting up python3-update-manager (1:16.04.9) ...
  5. Setting up liblxc1 (2.0.8-0ubuntu1~16.04.2) ...
  6. Setting up lxc-common (2.0.8-0ubuntu1~16.04.2) ...
  7. Setting up lxd (2.0.10-0ubuntu1~16.04.1) ...
  8. Setting up python3-distupgrade (1:16.04.22) ...
  9. Setting up ubuntu-release-upgrader-core (1:16.04.22) ...
  10. Setting up update-manager-core (1:16.04.9) ...
  11. Setting up update-notifier-common (3.168.5) ...
  12. Processing triggers for shared-mime-info (1.5-2ubuntu0.1) ...
  13. Processing triggers for dbus (1.10.6-1ubuntu3.3) ...
  14. Processing triggers for libc-bin (2.23-0ubuntu9) ...
  15. Processing triggers for initramfs-tools (0.122ubuntu8.8) ...
  16. update-initramfs: Generating /boot/initrd.img-4.4.0-62-generic
  17. W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
  18. Processing triggers for systemd (229-4ubuntu19) ...
  19. Processing triggers for ureadahead (0.100.0-19) ...
  20. Processing triggers for resolvconf (1.78ubuntu4) ...
  21. daweibro@Web-Ubuntu-Server-1604:~$

键入Y后按Enter确认之后,系统就会开始下载软件包、解压并安装,界面会一直不停地滚动。作为使用者我们不需要看清楚并明白所有这些信息。最后再次出现提示符就算更新完成了。如果系统安装出错,在最后面会给出警报提示。如果没有fatal errer等提示,一般不会有什么大问题。万一出现出错提示,我们可以通过提示信息在搜索引擎里找到可能的原因和解决方法。

apt-get upgrade可能出现的问题

退出登录然后再次登录系统,大伟哥发现有些信息变化了:

  1. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-62-generic x86_64)
  2.  
  3. * Documentation: https://help.ubuntu.com
  4. * Management: https://landscape.canonical.com
  5. * Support: https://ubuntu.com/advantage
  6.  
  7. 7 packages can be updated.
  8. 7 updates are security updates.
  9.  
  10.  
  11. *** System restart required ***
  12. Last login: Tue Aug 29 00:14:25 2017 from 192.168.1.2

我们发现版本号已经从Ubuntu 16.04.2 LTS升级到了Ubuntu 16.04.3 LTS,内核GNU/Linux 4.4.0-62-generic x86_64却没有变化,还有7个软件包没有更新,而且都是安全更新。

我们再次运行sudo apt-get update和sudo apt-get upgrade,看看有什么提示:

  1. daweibro@Web-Ubuntu-Server-1604:~$ sudo apt-get update
  2. [sudo] password for daweibro:
  3. Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
  4. Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
  5. Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
  6. Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
  7. Fetched 306 kB in 14s (21.0 kB/s)
  8. Reading package lists... Done
  9. david@Web-Ubuntu-Server-1604:~$ sudo apt-get upgrade
  10. Reading package lists... Done
  11. Building dependency tree
  12. Reading state information... Done
  13. Calculating upgrade... Done
  14. The following packages have been kept back:
  15. linux-generic linux-headers-generic linux-image-generic
  16. 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

原来是linux的内核没有更新,有什么办法吗?可以执行sudo apt-get dist-upgrade

  1. daweibro@Web-Ubuntu-Server-1604:~$ sudo apt-get dist-upgrade
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Calculating upgrade... Done
  6. The following NEW packages will be installed:
  7. linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic
  8. linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic
  9. The following packages will be upgraded:
  10. linux-generic linux-headers-generic linux-image-generic
  11. 3 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
  12. Need to get 68.6 MB of archives.
  13. After this operation, 297 MB of additional disk space will be used.
  14. Do you want to continue? [Y/n] Y
  15. Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-93-generic amd64 4.4.0-93.116 [21.9 MB]
  16. Get:2 http://101.44.1.117/files/B095000006D1261F/us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-93-generic amd64 4.4.0-93.116 [35.9 MB]
  17. Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-generic amd64 4.4.0.93.98 [1,790 B]
  18. Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-generic amd64 4.4.0.93.98 [2,286 B]
  19. Get:5 http://101.44.1.3/files/5060000006D1260B/us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-93 all 4.4.0-93.116 [9,981 kB]
  20. Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-93-generic amd64 4.4.0-93.116 [812 kB]
  21. Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-generic amd64 4.4.0.93.98 [2,268 B]
  22. Fetched 68.6 MB in 3min 44s (306 kB/s)
  23. Selecting previously unselected package linux-image-4.4.0-93-generic.
  24. (Reading database ... 59717 files and directories currently installed.)
  25. Preparing to unpack .../linux-image-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
  26. Done.
  27. Unpacking linux-image-4.4.0-93-generic (4.4.0-93.116) ...
  28. Selecting previously unselected package linux-image-extra-4.4.0-93-generic.
  29. Preparing to unpack .../linux-image-extra-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
  30. Unpacking linux-image-extra-4.4.0-93-generic (4.4.0-93.116) ...
  31. Preparing to unpack .../linux-generic_4.4.0.93.98_amd64.deb ...
  32. Unpacking linux-generic (4.4.0.93.98) over (4.4.0.62.65) ...
  33. Preparing to unpack .../linux-image-generic_4.4.0.93.98_amd64.deb ...
  34. Unpacking linux-image-generic (4.4.0.93.98) over (4.4.0.62.65) ...
  35. Selecting previously unselected package linux-headers-4.4.0-93.
  36. Preparing to unpack .../linux-headers-4.4.0-93_4.4.0-93.116_all.deb ...
  37. Unpacking linux-headers-4.4.0-93 (4.4.0-93.116) ...
  38. Selecting previously unselected package linux-headers-4.4.0-93-generic.
  39. Preparing to unpack .../linux-headers-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
  40. Unpacking linux-headers-4.4.0-93-generic (4.4.0-93.116) ...
  41. Preparing to unpack .../linux-headers-generic_4.4.0.93.98_amd64.deb ...
  42. Unpacking linux-headers-generic (4.4.0.93.98) over (4.4.0.62.65) ...
  43. Setting up linux-image-4.4.0-93-generic (4.4.0-93.116) ...
  44. Running depmod.
  45. update-initramfs: deferring update (hook will be called later)
  46. Examining /etc/kernel/postinst.d.
  47. run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  48. run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  49. update-initramfs: Generating /boot/initrd.img-4.4.0-93-generic
  50. W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
  51. run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  52. run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  53. run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  54. Generating grub configuration file ...
  55. Found linux image: /boot/vmlinuz-4.4.0-93-generic
  56. Found initrd image: /boot/initrd.img-4.4.0-93-generic
  57. Found linux image: /boot/vmlinuz-4.4.0-62-generic
  58. Found initrd image: /boot/initrd.img-4.4.0-62-generic
  59. done
  60. Setting up linux-image-extra-4.4.0-93-generic (4.4.0-93.116) ...
  61. run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  62. run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  63. update-initramfs: Generating /boot/initrd.img-4.4.0-93-generic
  64. W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
  65. run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  66. run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  67. run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
  68. Generating grub configuration file ...
  69. Found linux image: /boot/vmlinuz-4.4.0-93-generic
  70. Found initrd image: /boot/initrd.img-4.4.0-93-generic
  71. Found linux image: /boot/vmlinuz-4.4.0-62-generic
  72. Found initrd image: /boot/initrd.img-4.4.0-62-generic
  73. done
  74. Setting up linux-image-generic (4.4.0.93.98) ...
  75. Setting up linux-headers-4.4.0-93 (4.4.0-93.116) ...
  76. Setting up linux-headers-4.4.0-93-generic (4.4.0-93.116) ...
  77. Setting up linux-headers-generic (4.4.0.93.98) ...
  78. Setting up linux-generic (4.4.0.93.98) ...
  79. daweibro@Web-Ubuntu-Server-1604:~$

执行sudo reboot命令重启系统再登录以后,提示发现内核版本由GNU/Linux 4.4.0-62-generic x86_64更新到GNU/Linux 4.4.0-93-generic x86_64了,至此所有的软件包都成功升级到最新版本了:

  1. daweibro@Web-Ubuntu-Server-1604:~$ sudo reboot
  2. [sudo] password for david:
  3. Connection to 192.168.1.109 closed by remote host.
  4. Connection to 192.168.1.109 closed.
  5. david@Workstation:~$ ssh 192.168.1.109
  6. daweibro@192.168.1.109's password:
  7. Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)
  8.  
  9. * Documentation: https://help.ubuntu.com
  10. * Management: https://landscape.canonical.com
  11. * Support: https://ubuntu.com/advantage
  12.  
  13. 0 packages can be updated.
  14. 0 updates are security updates.
  15.  
  16.  
  17. Last login: Wed Aug 30 19:11:21 2017 from 192.168.1.2
  18. daweibro@Web-Ubuntu-Server-1604:~$

总结:Debian系(包含Ubuntu)系统的一般更新方法是使用sudo以系统管理员权限运行apt-get update更新软件列表,然后执行apt-get upgrade进行更新升级,如果Linux内核或者有些软件包无法升级,可以尝试使用apt-get dist-upgrade更新升级。

文章分类

标签

添加新评论

此字段内容将保密,不会被其他人看见。

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
发布评论前,请通过下面的验证,以免被当作垃圾评论机器人屏蔽。
8 + 7 =
计算出这道简单的算术题并键入答案。例如、1+3,就输入 4。