How to Check Installed APR Version Programmatically on Linux/Unix Servers


10 views

When working with Apache-related projects or system administration tasks, verifying the installed APR (Apache Portable Runtime) version becomes essential. Here are reliable methods to accomplish this without relying on log files:

The most straightforward approach is using the Apache extension tool:

apxs -q APR_VERSION

Sample output might look like:

1.7.0

If you have httpd or apache2 binary available:

httpd -V | grep -i "apr"

Or for systems using apache2:

apache2 -V | grep -i "apr"

On Linux systems, you can inspect the shared library directly:

strings /usr/lib/libapr-1.so | grep "APR_"

Look for lines containing version information like:

APR_1.7.0

For systems with package management:

# RPM-based (RedHat/CentOS)
rpm -q apr

# DEB-based (Ubuntu/Debian)
dpkg -l libapr1

For developers needing to check programmatically:

#include <apr_version.h>
#include <stdio.h>

int main() {
    printf("APR Version: %s\n", APR_VERSION_STRING);
    printf("APR Version Major: %d\n", APR_MAJOR_VERSION);
    printf("APR Version Minor: %d\n", APR_MINOR_VERSION);
    printf("APR Version Patch: %d\n", APR_PATCH_VERSION);
    return 0;
}

If the standard methods fail, consider:

  • Checking multiple library paths (/usr/local/lib, /opt/local/lib)
  • Using find command to locate apr libraries: find / -name "libapr*" 2>/dev/null
  • Building APR from source with --with-apr flag if compiling Apache

Remember that different Apache versions require specific APR versions:

Apache Version Minimum APR Version
2.4.x 1.4.0
2.2.x 1.2.0
2.0.x 1.0.0

The most straightforward method is using the apr-1-config utility that comes with APR installation. Run:

apr-1-config --version

Example output would display something like:

1.7.0

Using Package Managers

For systems using package management:

# On Debian/Ubuntu
apt list --installed | grep apr

# On RHEL/CentOS
rpm -qa | grep apr

Checking Shared Library Version

Locate and query the APR library directly:

# Find library location
ldconfig -p | grep libapr

# Check version symbols
nm -D /usr/lib64/libapr-1.so | grep apr_version

For developers needing to check version within code:

#include <apr_version.h>
#include <stdio.h>

int main() {
    printf("APR Version: %s\n", APR_VERSION_STRING);
    return 0;
}

If the above methods fail:

  • Check PATH environment variable includes APR binaries
  • Verify APR is actually installed (some systems may bundle it with Apache)
  • Consider compiling APR from source if you need specific version