How to Completely Disable ‘Needrestart’ Prompts After APT Upgrades in Ubuntu Server

In modern versions of Ubuntu Server, whenever you run a standard sudo apt upgrade, the system evaluates which background services are using the old versions of the libraries you just updated. If it finds running services tied to old code, it triggers a utility called needrestart. This utility completely halts your terminal and presents a massive, pink, interactive dialogue box asking you to manually select which background services you want to restart.

While this ensures your server immediately benefits from security patches without a full reboot, it is an absolute nightmare for automation. If you manage a fleet of Ubuntu servers using Ansible, Bash scripts, or cron jobs, that interactive pink dialogue box will completely freeze your deployment pipeline, waiting indefinitely for a human to press the Enter key. To build truly headless, automated server environments, you must completely disable these interactive needrestart prompts.

Changing the Needrestart Configuration Mode

You can instruct the needrestart utility to operate in a non-interactive mode. You can choose whether it should automatically restart the services for you, or simply list them in the terminal output without stopping the script.

  1. Connect to your Ubuntu server via SSH or open a local Terminal session.
  2. Open the main configuration file in a text editor with root privileges:
    sudo nano /etc/needrestart/needrestart.conf
  3. Use the search function (Ctrl + W in nano) to find the following string:
    $nrconf{restart}
  4. By default, the line will look like this, and it may be commented out with a hash (#):
    #$nrconf{restart} = 'i';
  5. Remove the hash # at the beginning of the line to uncomment it.
  6. Change the 'i' (which stands for interactive) to one of two options depending on your preference:
    • Change to ‘a’ ($nrconf{restart} = 'a';) if you want the system to automatically restart the required services without asking.
    • Change to ‘l’ ($nrconf{restart} = 'l';) if you want the system to simply list the required services in the terminal output, but leave them running on the old code until you manually intervene later.
  7. Save the file (Ctrl + O, then Enter) and exit the editor (Ctrl + X).

Uninstalling Needrestart Entirely (Alternative)

If you prefer the classic Ubuntu behavior (where updating a package simply updates the files on the disk, and you take full responsibility for rebooting the server when you are ready), you can simply purge the utility entirely.

  1. In the terminal, run:
    sudo apt-get remove --purge needrestart
  2. Press Y to confirm.

Whether you change the mode to automatic or uninstall the package entirely, your apt upgrade commands will now run from start to finish completely uninterrupted. Your automated deployment scripts will no longer hang indefinitely waiting for human input.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.