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)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid

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 ]
then
   echo "TimeoutStartSec setting needed on this server"
   update_config
else
   echo "TimeoutStartSec setting NOT needed on this server"
fi

Another option:

/lib/systemd/systemd --version

From my Arch Linux:

systemd 248 (248.3-2-arch)
+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified

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