How to find systemd version on Linux

I need to set up TimeoutStartSec but it is only needed when systemd version is 236 or lower. So question, how do I find out my systemd version on RHEL 8 server? What command I must type for finding out systemd version?

Try any one of the following command.

Finding systemd version on Linux using the systemctl

systemctl --version

Ubuntu is using version 245

systemd 245 (245.4-4ubuntu3.7)

Getting systemd version using package manger

# Debian/Ubuntu command
sudo apt info systemd
sudo apt-cache show systemd | grep  -i '^version'

# RHEL/CentOS/Rocky Linux command
sudo dnf info systemd
sudo dnf info systemd | grep -i '^Version'

I have 239 version on CentOS 8

Version      : 239
1 Like

My final code:

v=$(systemctl --version | head -1 | awk '{ print $2}')
echo "GNU/Linux Systemd version : $v "
if [ $v -le 236 ]
   echo "TimeoutStartSec setting needed on this server"
   echo "TimeoutStartSec setting NOT needed on this server"

Another option:

/lib/systemd/systemd --version

From my Arch Linux:

systemd 248 (248.3-2-arch)

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki