跳转到主要内容
首页

用户帐户菜单

  • 登录

主导航

  • 首页
  • 小公司运营
  • 网站建设
  • 创业杂谈
  • 兼职赚钱
  • 小微企业信息化
  • 手册教程
    • 《大伟哥的Drupal 8建站指南》
    • 《通过JohnChow.Com在网上赚钱》
  • 关于

面包屑

  • 首页
  • Ubuntu Server 16.04更新系统软件包

Ubuntu Server 16.04更新系统软件包

By 大伟哥 | 2017-08-29,周二, 09:20

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


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

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

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

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

2. 执行sudo apt-get update


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

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

执行sudo apt-get upgrade


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

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

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

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

apt-get upgrade可能出现的问题

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

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-62-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

7 packages can be updated.
7 updates are security updates.


*** System restart required ***
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,看看有什么提示:

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

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

daweibro@Web-Ubuntu-Server-1604:~$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic
  linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic
The following packages will be upgraded:
  linux-generic linux-headers-generic linux-image-generic
3 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.6 MB of archives.
After this operation, 297 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
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]
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]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-generic amd64 4.4.0.93.98 [1,790 B]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-generic amd64 4.4.0.93.98 [2,286 B]
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]
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]
Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-generic amd64 4.4.0.93.98 [2,268 B]
Fetched 68.6 MB in 3min 44s (306 kB/s)                                         
Selecting previously unselected package linux-image-4.4.0-93-generic.
(Reading database ... 59717 files and directories currently installed.)
Preparing to unpack .../linux-image-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
Done.
Unpacking linux-image-4.4.0-93-generic (4.4.0-93.116) ...
Selecting previously unselected package linux-image-extra-4.4.0-93-generic.
Preparing to unpack .../linux-image-extra-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
Unpacking linux-image-extra-4.4.0-93-generic (4.4.0-93.116) ...
Preparing to unpack .../linux-generic_4.4.0.93.98_amd64.deb ...
Unpacking linux-generic (4.4.0.93.98) over (4.4.0.62.65) ...
Preparing to unpack .../linux-image-generic_4.4.0.93.98_amd64.deb ...
Unpacking linux-image-generic (4.4.0.93.98) over (4.4.0.62.65) ...
Selecting previously unselected package linux-headers-4.4.0-93.
Preparing to unpack .../linux-headers-4.4.0-93_4.4.0-93.116_all.deb ...
Unpacking linux-headers-4.4.0-93 (4.4.0-93.116) ...
Selecting previously unselected package linux-headers-4.4.0-93-generic.
Preparing to unpack .../linux-headers-4.4.0-93-generic_4.4.0-93.116_amd64.deb ...
Unpacking linux-headers-4.4.0-93-generic (4.4.0-93.116) ...
Preparing to unpack .../linux-headers-generic_4.4.0.93.98_amd64.deb ...
Unpacking linux-headers-generic (4.4.0.93.98) over (4.4.0.62.65) ...
Setting up linux-image-4.4.0-93-generic (4.4.0-93.116) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-93-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-93-generic
Found initrd image: /boot/initrd.img-4.4.0-93-generic
Found linux image: /boot/vmlinuz-4.4.0-62-generic
Found initrd image: /boot/initrd.img-4.4.0-62-generic
done
Setting up linux-image-extra-4.4.0-93-generic (4.4.0-93.116) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-93-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-93-generic /boot/vmlinuz-4.4.0-93-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-93-generic
Found initrd image: /boot/initrd.img-4.4.0-93-generic
Found linux image: /boot/vmlinuz-4.4.0-62-generic
Found initrd image: /boot/initrd.img-4.4.0-62-generic
done
Setting up linux-image-generic (4.4.0.93.98) ...
Setting up linux-headers-4.4.0-93 (4.4.0-93.116) ...
Setting up linux-headers-4.4.0-93-generic (4.4.0-93.116) ...
Setting up linux-headers-generic (4.4.0.93.98) ...
Setting up linux-generic (4.4.0.93.98) ...
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了,至此所有的软件包都成功升级到最新版本了:


daweibro@Web-Ubuntu-Server-1604:~$ sudo reboot
[sudo] password for david: 
Connection to 192.168.1.109 closed by remote host.
Connection to 192.168.1.109 closed.
david@Workstation:~$ ssh 192.168.1.109
daweibro@192.168.1.109's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.


Last login: Wed Aug 30 19:11:21 2017 from 192.168.1.2
daweibro@Web-Ubuntu-Server-1604:~$ 

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

小微企业信息化
网站建设
  • 5658 阅读
VPS
Ubuntu

添加新评论

此字段内容将保密,不会被其他人看见。
关于文本格式
  • 不允许使用HTML标签。
CAPTCHA
12 + 2 =
计算出这道简单的算术题并键入答案。例如、1+3,就输入 4。
发布评论前,请通过下面的验证,以免被当作垃圾评论机器人屏蔽。

搜索

沪ICP备17000093号-1

公安备案沪公网安备 31011402008254号

© 2016-2022 大伟哥博客版权所有