如何在 Ubuntu 中处理自动的无人值守升级
Ubuntu 升级

> 
> 本教程教你如何处理无人值守的升级，即 Ubuntu Linux 的自动系统更新。
> 
> 
> 


![](/data/attachment/album/202005/27/234040fxb0nkc53pk0nxvx.jpg)


有时，当你尝试[关闭 Ubuntu 系统](https://itsfoss.com/schedule-shutdown-ubuntu/)时，可能看到这个阻止你关闭的页面：



> 
> 关机过程中正在进行无人值守升级，请不要关闭计算机。
> 
> 
> 


![](/data/attachment/album/202005/27/233432nec2y0m9dj9dmvjr.png)


你可能会问这个“无人值守升级”是什么，怎么会在你不知情的情况下运行呢？


原因是 [Ubuntu](https://ubuntu.com/) 非常重视系统的安全性。默认情况下，它会每天自动检查系统更新，如果发现安全更新，它会下载这些更新并自行安装。对于正常的系统和应用更新，它会通过软件更新程序通知你。


由于所有这些都是在后台发生的，所以在你尝试关闭系统或尝试自行安装应用程序之前，你甚至不会意识到这一点。


在这些无人值守的升级过程中，尝试安装新软件，会导致著名的[无法获得锁定的错误](https://itsfoss.com/could-not-get-lock-error/)。


![](/data/attachment/album/202005/27/233701ql6nwwn7l67068ea.jpg)


如你所见，自动更新带来了一些小麻烦。你可以选择禁用自动更新，但这意味着你必须一直手动检查并[更新你的 Ubuntu 系统](https://itsfoss.com/update-ubuntu/)。



> 
> **你真的需要禁用自动更新吗？**
> 
> 
> 请注意，这是一项安全功能。Linux 实际上允许你禁用系统中的所有功能，甚至禁用这些安全功能。
> 
> 
> 但是我认为，作为普通用户，**你不应该禁用自动更新**。毕竟，它可以确保你的系统安全。
> 
> 
> 为了确保系统的安全性，你可以忍受自动更新所带来的小麻烦。
> 
> 
> 


现在，你已经收到警告，还是觉得承担手动更新系统的额外任务更好，那么让我们看看如何处理自动更新。


与往常一样，有两种方法可以做到：GUI 和命令行。 我将向你展示两种方法。


我在这里使用 Ubuntu 20.04，但是这些步骤对 Ubuntu 18.04 和任何其他 Ubuntu 版本均有效。


### 方法 1：以图形方式禁用 Ubuntu 中的自动更新


进入菜单并查找“软件和更新”工具。


![](/data/attachment/album/202005/27/233712v040x7l0w4o7w07r.jpg)


在此处，进入“更新”选项卡。查找“自动检查更新”。默认情况下，它设置为“每日”。


你可以将其更改为“从不”，你的系统将永远不会检查更新。如果不检查更新，它就不会找到要安装的新的更新。


![](/data/attachment/album/202005/27/233738iq83mb6bjpsq680m.jpg)


如果这样做，那么必须不时手动更新系统。但是，这是额外的工作，你可能不会一直记得。


#### 在 Ubuntu 中处理自动更新的更好方法


就个人而言，我建议让它自己检查更新。如果你不希望它自动安装更新，那么可以更改该行为，以通知有关安全更新的可用性。


保持“自动检查更新”为“每日”，然后将“有安全更新时”选项更改为“立即显示”，而不是“自动下载并安装”。


![](/data/attachment/album/202005/27/233806ibtw5pwpwnvsns5h.jpg)


这样，它会检查是否有更新，而不是在后台自动安装更新，软件更新程序会通知你有可用于系统的更新。而你的系统已经完成正常的系统和软件更新。


![](/data/attachment/album/202005/27/233849t22ab25b5b781110.png)


使用此设置，关闭系统时将不会看到“正在进行的无人值守升级”。但是，由于两个不同的进程无法同时使用 apt 包管理器，因此你仍然可能会遇到“无法锁定”错误。


我相信这是一个更好的解决方案，你不认为是么？


如我承诺的同时有 GUI 和命令行方法一样，让我向你展示如何在终端中禁用无人值守的升级。


### 如何在 Ubuntu 中使用命令行禁用自动更新


你可以在 `/etc/apt/apt.conf.d/20auto-upgrades` 中找到自动升级设置。Ubuntu 终端中的默认文本编辑器是 Nano，因此你可以使用以下命令来编辑此文件：



```
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
```

现在，如果你不希望系统自动检查更新，那么可以将 `APT::Periodic::Update-Package-Lists` 的值更改为 `"0"`。



```
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
```

如果你希望它检查更新但不自动安装无人值守的升级，那么可以选择将其设置为：



```
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
```

### 最后


由于某种原因，启用了自动安全更新，建议你保持这种状态。这个小烦恼实际上并不值得冒险损害系统安全性。你怎么看？




---


via: <https://itsfoss.com/auto-updates-ubuntu/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
**Brief: This tutorial teaches you how to handle the unattended upgrade i.e. the automatic system updates in Ubuntu Linux.**

Sometimes, when you try to [shutdown your Ubuntu system](https://itsfoss.com/schedule-shutdown-ubuntu/), you may come across this screen that stops you from shutting down:

**Unattended-upgrade in progress during shutdown, please don’t turn off the computer.**

![Unattended Upgrade In Progress In Ubuntu](https://itsfoss.com/content/images/wordpress/2020/04/unattended-upgrade-in-progress-in-ubuntu.png)

You might wonder what is this “unattended upgrade” and how come it is running without your knowledge.

The reason is that [Ubuntu](https://ubuntu.com/) takes your system’s security very seriously. By default, it automatically checks for system updates daily and if it finds any security updates, it downloads those updates and install them on its own. For normal system and application updates, it notifies you via the Software Updater tool.

Since all this happens in the background, you don’t even realize it until you try to shutdown your system or try to install applications on your own.

Trying to install a new software when these unattended upgrades are in progress leads to the famous [could not get lock error](https://itsfoss.com/could-not-get-lock-error/).

![Could Not Get Lock](https://itsfoss.com/content/images/wordpress/2019/12/Could_not_get_lock.jpg)

As you can see, the automatic updates present a couple of minor annoyance. You may choose to disable the auto updates but that would mean that you’ll have to check and [update your Ubuntu system](https://itsfoss.com/update-ubuntu/) manually all the time.

Do you really need to disable auto updates?

Please note that this is a security feature. Linux allows you to do practically everything in your system even disabling these security features.

But in my opinion, as a regular user, ** you should not disable the automatic updates**. It keeps your system safe after all.

For the sake of your system’s security, you may tolerate the minor annoyances that come with the automatic updates.

Now that you have been warned and you think it is better to take up the additional task of manually updating your system, let’s see how to handle the auto updates.

As always, there are two ways to do it: GUI and command line. I’ll show you both methods.

I have used Ubuntu 20.04 here but the steps are valid for Ubuntu 18.04 and any other Ubuntu version.

## Method 1: Disable automatic updates in Ubuntu graphically

Go to the menu and look for ‘software & updates’ tool.

![Software & Updates Settings Ubuntu in 20.04](https://itsfoss.com/content/images/wordpress/2020/04/software-updates-settings-ubuntu-20-04.jpg)

In here, go to Updates tab. Now look for the “Automatically check for updates”. By default it is set to Daily.

You can change it to Never and your system will never check for updates on its own again. And if it won’t check for updates, it won’t find new updates to install.

![Disable Auto Updates Ubuntu](https://itsfoss.com/content/images/wordpress/2020/04/disable-auto-updates-ubuntu.jpg)

If you do this, you must manually update your system from time to time. But that’s an additional chore to do and you may not remember it all the time.

### Slightly better way to handle auto updates in Ubuntu

Personally, I would suggest to let it check for updates on its own. If you don’t want it installing the updates automatically, you can change that behavior to get notified about the availability of security updates.

Keep “Automatically check for updates” to Daily and change “When there are security updates” option to “Display immediately” instead of “Download and install automatically”.

![Handle Auto Updates Ubuntu](https://itsfoss.com/content/images/wordpress/2020/04/handle-auto-updates-ubuntu.jpg)

This way, it checks for updates and if there are updates, instead of installing them automatically in the background, the Software Updater tool notifies you that updates are available for your system. Your system already does that for normal system and software updates.

![Updates Available Ubuntu](https://itsfoss.com/content/images/wordpress/2020/04/updates-available-ubuntu.png)

With this setup, you won’t see the “unattended upgrades in progress” when you shutdown your system However, you may still encounter the ‘could not get lock’ error because two separate processes cannot use apt package manager at the same time.

I believe this is a better solution, don’t you you think?

As I promised both GUI and command line methods, let me show you how to disable unattended upgrades in the terminal.

## How to disable automatic updates in Ubuntu using command line

You’ll find the auto-upgrades settings in the **/etc/apt/apt.conf.d/20auto-upgrades** file. The default text editor in Ubuntu terminal is Nano so you can use this command to edit this configuration file:

`sudo nano /etc/apt/apt.conf.d/20auto-upgrades`


Now, if you don’t want your system to check for updates automatically, you can change the value of APT::Periodic::Update-Package-Lists to 0.

```
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
```


If you want it to check for updates but don’t install the unattended-upgrades automatically, you can choose to set it like this:

```
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
```


**In the end…**

The automatic security updates are enabled automatically for a reason and I recommend you keep it like this. A couple of minor annoyances are not really worth risking the security of your system. What do you think?