Needrestart scans your Fedora system after package updates to identify services, user sessions, and kernel components that need restarting. Instead of guessing which daemons are running outdated libraries or rebooting unnecessarily, needrestart tells you exactly what requires attention. This guide covers how to install needrestart on Fedora Linux, configure its behavior, understand the output modes, and optionally automate service restarts after updates. The needrestart GitHub project provides additional documentation and release notes.
Server administrators commonly use needrestart to maintain uptime while ensuring security patches take effect. Similarly, desktop users benefit from knowing when a browser or service needs restarting after an update. Whether you run a production web server or a development workstation, needrestart removes the uncertainty from post-update maintenance.
Install Needrestart on Fedora Linux
Needrestart is available in the official Fedora repositories. Before installing new packages, refresh your package cache and apply any pending updates:
sudo dnf upgrade --refresh
This command downloads the latest package metadata and upgrades all installed packages to their current versions. Once the upgrade completes, install needrestart:
sudo dnf install needrestart
DNF automatically resolves and installs all required Perl dependencies. The installation typically pulls in around 120 packages, primarily Perl modules that needrestart uses for process scanning and user interface handling.
After installation completes, verify that needrestart is available:
needrestart --version
Expected output:
needrestart 3.8 - Restart daemons after library updates. Authors: Thomas Liske <thomas@fiasko-nw.net> Copyright Holder: 2013 - 2022 (C) Thomas Liske [http://fiasko-nw.net/~thomas/] Upstream: https://github.com/liske/needrestart
Use Needrestart on Fedora Linux
Needrestart provides several operation modes depending on whether you want to view, interact with, or automatically act on its findings. The following sections explain each mode and when to use it.
Check for Services Needing Restart
Run needrestart with the -l flag to list services and sessions that need attention without taking any action:
sudo needrestart -l
On a freshly updated system with no pending restarts, the output looks like this:
No services need to be restarted. No containers need to be restarted. User sessions running outdated binaries: root @ /dev/pts/0: bash[1] No VM guests are running outdated hypervisor (qemu) binaries on this host.
This output tells you that no system services require restarting, but the current shell session is running an outdated bash binary. After heavy package updates, you might see a longer list of services and user sessions.
Interactive Mode
Running needrestart without flags opens interactive mode, which prompts you to restart each affected service:
sudo needrestart
In interactive mode, needrestart presents a dialog for each service that needs restarting. You can choose to restart services individually, skip them, or restart all. This mode is useful when you want to review each service before restarting, particularly on production systems where certain services require careful handling.
Batch Mode for Scripts and Automation
For automated environments or when you need machine-readable output, use batch mode with the -b flag:
sudo needrestart -b
Batch mode outputs structured data that scripts can parse:
NEEDRESTART-VER: 3.8 NEEDRESTART-KCUR: 6.x.x-xxx.fc43.x86_64 NEEDRESTART-KSTA: 1 NEEDRESTART-UCSTA: 1 NEEDRESTART-UCCUR: 0x0a000705 NEEDRESTART-UCEXP: 0x0a000705 NEEDRESTART-SESS: root @ /dev/pts/0
The NEEDRESTART-KSTA value indicates kernel status: 0 means the running kernel is current, 1 means a newer kernel is available (reboot needed), and 2 means the kernel version cannot be determined. The NEEDRESTART-SESS lines list user sessions running outdated binaries.
Automatic Restart Mode
To restart all affected services without prompts, use automatic mode:
sudo needrestart -r a
Automatic mode restarts services immediately without confirmation. Use this only when you understand which services will restart and have verified that automatic restarts are acceptable for your environment. Critical services like databases or web servers may cause brief outages during restart.
Check Specific Components
Needrestart can check specific components individually instead of running a full scan:
Check kernel only:
sudo needrestart -k
This reports whether the running kernel matches the latest installed kernel, helping you decide if a reboot is necessary.
Check libraries only:
sudo needrestart -l
The -l flag limits the scan to outdated shared libraries, skipping kernel and microcode checks. This is faster when you only need to identify services affected by library updates.
Check CPU microcode only:
sudo needrestart -w
This checks whether the running CPU microcode matches the latest available version. Microcode updates often require a reboot to take effect.
Configure Needrestart on Fedora Linux
Needrestart stores its configuration in /etc/needrestart/needrestart.conf. The file uses Perl syntax, and all settings are documented with inline comments. You can also add custom configuration snippets in /etc/needrestart/conf.d/, which override settings from the main configuration file.
Open the configuration file to review available options:
sudo nano /etc/needrestart/needrestart.conf
The following sections explain the most commonly modified settings.
Set Default Restart Mode
The restart setting controls how needrestart behaves by default. Uncomment and modify this line to change the default mode:
# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
$nrconf{restart} = 'i';
Available modes:
l– List only: reports what needs restarting without taking actioni– Interactive: prompts for each service (default)a– Automatic: restarts all affected services without prompts
For production servers, l (list only) is the safest default because it prevents automatic restarts during unattended updates.
Adjust Verbosity Level
You can also control how much output needrestart produces:
# Verbosity:
# 0 => quiet
# 1 => normal (default)
# 2 => verbose
$nrconf{verbosity} = 1;
Setting verbosity to 0 suppresses all output except errors, which is useful for quiet cron jobs. Alternatively, setting it to 2 provides detailed information about which processes are being scanned, helpful for debugging.
Override Service Restart Behavior
The override_rc hash controls which services needrestart offers to restart. By default, needrestart excludes display managers, networking services, and other critical system components that could cause session disconnection or network loss.
To prevent needrestart from offering to restart a specific service, add it to the override hash with a value of 0. For example, to exclude the PostgreSQL service:
$nrconf{override_rc} = {
# Existing entries...
# Never offer to restart PostgreSQL
qr(^postgresql) => 0,
};
The pattern uses Perl regular expressions. The qr(^postgresql) pattern matches any service name starting with “postgresql”.
Exclude Binaries from Scanning
The $nrconf{blacklist} array (named “blacklist” in the configuration file) prevents needrestart from flagging specific binaries. This is useful for processes that are not daemons and do not benefit from restart detection:
$nrconf{blacklist} = [
# Default entries
qr(^/usr/bin/sudo$),
# Add custom entries
qr(^/opt/myapp/worker$),
];
Each entry is a Perl regular expression matching the full path to the binary.
Disable Kernel or Microcode Hints
If you handle kernel updates separately or want to suppress kernel-related notifications:
# Disable kernel update hints
$nrconf{kernelhints} = 0;
# Disable CPU microcode update hints
$nrconf{ucodehints} = 0;
Setting these to -1 prints hints to stderr only, allowing you to capture them in logs while keeping the interactive output clean.
Configure User Session Notifications
Needrestart can notify users when their sessions are running outdated binaries. To disable these notifications:
# Disable user session notifications
$nrconf{sendnotify} = 0;
This is useful on headless servers where user notifications serve no purpose.
Use Configuration Drop-ins
Instead of modifying the main configuration file, you can add custom settings in /etc/needrestart/conf.d/. This approach preserves your customizations when the package updates the main configuration file.
Create a custom configuration file:
sudo nano /etc/needrestart/conf.d/custom.conf
Example content that sets list-only mode and disables kernel hints:
# Custom needrestart configuration
$nrconf{restart} = 'l';
$nrconf{kernelhints} = 0;
Save and close the file. Needrestart automatically loads all .conf files from this directory in alphabetical order.
Automate Needrestart with systemd
You can create a systemd timer to run needrestart periodically and log which services need attention. This is useful for monitoring systems without automatically restarting services.
Create the Service Unit
First, create a systemd service unit that runs needrestart in list mode:
sudo nano /etc/systemd/system/needrestart-check.service
Add the following content:
[Unit]
Description=Check for services needing restart
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/needrestart -r l
[Install]
WantedBy=multi-user.target
Save and close the file. The -r l flag ensures needrestart only lists affected services without restarting them.
Create the Timer Unit
Next, create a timer that triggers the service on a schedule:
sudo nano /etc/systemd/system/needrestart-check.timer
Add the following content:
[Unit]
Description=Run needrestart check periodically
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
The OnCalendar=daily setting runs the check once per day at midnight. You can adjust this to other values like hourly, weekly, or a specific time such as *-*-* 06:00:00 for 6:00 AM daily.
Enable and Start the Timer
Reload systemd to recognize the new units, then enable and start the timer:
sudo systemctl daemon-reload
sudo systemctl enable --now needrestart-check.timer
Verify the timer is active:
systemctl status needrestart-check.timer
To manually trigger a check immediately:
sudo systemctl start needrestart-check.service
View the output from the last run:
journalctl -u needrestart-check.service --no-pager
Troubleshooting Needrestart
Failed to Retrieve Kernel Versions
If you see Failed to retrieve available kernel versions when running needrestart, this typically occurs in containers or virtualized environments where kernel information is not accessible. The message is informational rather than an error. Needrestart can still check services and libraries; only the kernel check fails.
To suppress this message, disable kernel hints in your configuration:
echo '$nrconf{kernelhints} = 0;' | sudo tee /etc/needrestart/conf.d/no-kernel.conf
User Sessions Always Show Outdated Binaries
After package updates, needrestart often reports user sessions running outdated binaries. This is expected behavior. The simplest resolution is to log out and log back in, which starts a fresh session with updated binaries. For remote SSH sessions, disconnect and reconnect.
If you want needrestart to stop sending desktop notifications to users about their outdated sessions, disable the notification scripts:
echo '$nrconf{sendnotify} = 0;' | sudo tee /etc/needrestart/conf.d/no-notify.conf
This setting prevents needrestart from running user notification scripts, but sessions still appear in the output. Needrestart distinguishes between reporting (which you see) and notification (which users receive as alerts).
Service Shows as Needing Restart but Already Restarted
If a service continues to appear in needrestart output after being restarted, the service may have spawned child processes before the restart that are still running. Check the service status and ensure all related processes have been restarted:
sudo systemctl status servicename
sudo systemctl restart servicename
sudo needrestart -l
For services with persistent workers or forked processes, you may need to fully stop the service, wait a moment, and start it again rather than using restart.
Remove Needrestart from Fedora Linux
If you no longer need needrestart, remove the package and its dependencies:
sudo dnf remove needrestart
DNF automatically removes needrestart and any dependencies that are no longer required by other packages. On a system where needrestart was the only package using the Perl modules, this removes a significant number of packages.
If you want to also remove the configuration files:
The following command permanently deletes all needrestart configuration files. Only run this if you want a completely clean removal.
sudo rm -rf /etc/needrestart/
If you created systemd timer units for automated checks, remove them as well:
sudo systemctl disable --now needrestart-check.timer
sudo rm /etc/systemd/system/needrestart-check.service
sudo rm /etc/systemd/system/needrestart-check.timer
sudo systemctl daemon-reload
Conclusion
Needrestart identifies services and sessions that require attention after library updates, eliminating guesswork from post-update maintenance. You can run it interactively after updates, integrate it into automated monitoring, or configure it to restart services automatically. For more information on package management, see our DNF5 install examples guide. For automatic update handling, explore dnf-automatic on Fedora.