- Find glibc version in your system
- Method 1: Use ldd
- Method 2: Use libc-version.h in C++ code
- Method 3: gnu_get_libc_version()
- Check libc version
- How to check libc version on major Linux distros
- How to update libc version on major Linux distros
- Closing Thoughts
- Related Linux Tutorials:
- NEWSLETTER
- WRITE FOR US
- TAGS
- FEATURED TUTORIALS
- LATEST TUTORIALS
- Check glibc version for a particular gcc compiler
- 9 Answers 9
Find glibc version in your system
In this guide at OpenGenus, we present 3 different ways to identify compile time and run time version of glibc. The version of glibc has two components: Major version and Minor version. It is as follows:
glibc version glibc MAJOR_VERSION.MINOR_VERSION glibc 2.31 MAJOR_VERSION = 2 MINOR_VERSION = 31
In short, you can find out the glibc version using the following command:
We find the glibc version using the following ways:
- Method 1: Use ldd
- Method 2: Use libc-version.h in C++ code
- Method 3: gnu_get_libc_version()
glibc is GNU C Library which provides the Standard C implementation and also, supports C++. It provides the core libraries in Linux kernel and hence, is used in every operating system that uses Linux as the kernel like RHEL, CentOS, Ubuntu and many others.
For a certain software, the glibc version should be the same in the destination system as in the origin system where the software has been compiled. You may have faced glibc errors and hence, need to find out the glibc version you are using.
Following are the methods:
Method 1: Use ldd
Use the following command in the terminal:
The output will give the version of glibc used:
ldd (Ubuntu GLIBC 2.31-0ubuntu9.2) 2.31 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
Method 2: Use libc-version.h in C++ code
Add the following C++ code in a file named «glibc.cpp»:
// Part of iq.OpenGenus.org #include #include #include int main(int argc, char *argv[]) < // Print glibc version printf("GNU libc version: %s\n", gnu_get_libc_version()); exit(EXIT_SUCCESS); >
Compile the above code using the following command:
Method 3: gnu_get_libc_version()
In this method, we can identify two versions of glibc:
The compile time version of glibc is defined in macros __GLIBC__ and __GLIBC_MINOR__ .
The run time version of glibc is available using the function gnu_get_libc_version().
Note that the run time version of glibc can be greater than the compile time version of glibc but never smaller. The major version is likely to be the same.
Add the following code in a file named «glibc.c»:
// Part of iq.OpenGenus.org #include #ifdef __GLIBC__ #include #endif int main(void)
Compile the above code using the following command:
GNU libc compile-time version: 2.31 GNU libc runtime version: 2.31
With this, you know how to find out the version of glibc. Happy debugging.
Check libc version
The GNU C Library, often abbreviated to libc or glibc, is ordinarily installed out of the box on all major Linux distros. It is an essential library that many software packages will rely on in order to run properly or run at all. In case you need to check what version of libc is installed on your Linux system, we have you covered in this tutorial.
In this tutorial you will learn:
- How to check libc version on all major Linux distros
- How to update libc on all major Linux distros
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | libc |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user |
How to check libc version on major Linux distros
The process for checking your installed version of libc will be the same regardless of your Linux distro. Simply use the ldd command as seen below.
$ ldd --version ldd (Ubuntu GLIBC 2.35-0ubuntu3) 2.35 .
As you can see from the first line of the output and in the previous screenshot, we have version 2.35 installed.
Another way how to check your libc library version is to run its binary. This may require you to add execute permissions to the file first.
$ /lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Ubuntu GLIBC 2.35-0ubuntu3) stable release version 2.35. .
How to update libc version on major Linux distros
In case you find your installed libc to be out of date, it is simple enough to bring it up to date on any Linux system.
You can use the appropriate command below to update libc with your system’s package manager.
$ sudo apt update $ sudo apt install libc-bin
Closing Thoughts
In this tutorial, we saw how to check the installed version of libc on a Linux system. This could be a necessary troubleshooting step in case you have downloaded software that is refusing to run and is blaming an outdated libc version as the culprit. In case you need to update libc, you now have the instructions to download the latest version with your system’s package manager.
Related Linux Tutorials:
Comments and Discussions
NEWSLETTER
Subscribe to Linux Career Newsletter to receive latest news, jobs, career advice and featured configuration tutorials.
WRITE FOR US
LinuxConfig is looking for a technical writer(s) geared towards GNU/Linux and FLOSS technologies. Your articles will feature various GNU/Linux configuration tutorials and FLOSS technologies used in combination with GNU/Linux operating system.
When writing your articles you will be expected to be able to keep up with a technological advancement regarding the above mentioned technical area of expertise. You will work independently and be able to produce at minimum 2 technical articles a month.
TAGS
FEATURED TUTORIALS
- VIM tutorial for beginners
- How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux
- Bash Scripting Tutorial for Beginners
- How to check CentOS version
- How to find my IP address on Ubuntu 20.04 Focal Fossa Linux
- Ubuntu 20.04 Remote Desktop Access from Windows 10
- Howto mount USB drive in Linux
- How to install missing ifconfig command on Debian Linux
- AMD Radeon Ubuntu 20.04 Driver Installation
- Ubuntu Static IP configuration
- How to use bash array in a shell script
- Linux IP forwarding – How to Disable/Enable
- How to install Tweak Tool on Ubuntu 20.04 LTS Focal Fossa Linux
- How to enable/disable firewall on Ubuntu 18.04 Bionic Beaver Linux
- Netplan static IP on Ubuntu configuration
- How to change from default to alternative Python version on Debian Linux
- Set Kali root password and enable root login
- How to Install Adobe Acrobat Reader on Ubuntu 20.04 Focal Fossa Linux
- How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux
- How to check NVIDIA driver version on your Linux system
- Nvidia RTX 3080 Ethereum Hashrate and Mining Overclock settings on HiveOS Linux
LATEST TUTORIALS
- Easy Steps to Update Your Raspberry Pi
- Connecting Your Raspberry Pi to Wi-Fi: A How-To
- How to install RealVNC viewer on Linux
- How to check Raspberry Pi RAM size and usage
- How to check Raspberry Pi model
- Understanding UEFI and BIOS in Relation to Linux Nvidia Driver Installation
- How to orchestrate Borg backups with Borgmatic
- How to monitor filesystem events on files and directories on Linux
- Debian USB Firmware Loader Script
- How to install and self host an Ntfy server on Linux
- How to backup your git repositories with gickup
- How to bind an SSH public key to a specific command
- Creating a Bootable USB for Windows 10 and 11 on Linux
- How to list all displays on Linux
- List of QR code generators on Linux
- How to extract text from image
- Linux EOF explained
- How to use xclip on Linux
- List of window managers on Linux
- What is zombie process on Linux
Check glibc version for a particular gcc compiler
I have two gcc compilers installed on my system, one is gcc 4.1.2 (default) and the other is gcc 4.4.4 . How can I check the libc version used by gcc 4.4.4 , because /lib/libc.so.6 shows the glibc used by gcc 4.1.2 , since it is the default compiler.
If you want to perform the check at compile time, then Zwol’s answer below is probably the best method. If you want to check the version at runtime, then R1tschY’s answer is probably the best method. Note that you may not get the Glibc version or standard C++ library version you expect at runtime due to Linux’s inability to get the paths right on its own. Also see Linking g++ 4.8 to libstdc++
9 Answers 9
This should return the glibc version being used i.e.
$ ldd --version ldd (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO
which is the same result as running my libc library
$ /lib/libc.so.6 GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al. Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions.
Results from above commands are not the same. On my computer : GNU libc version: 2.17, ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2 ??
That shows what ldd was linked with. When linking programs you link with some implementation of libc (there can be more than one), not with ldd .
Write a test program (name it for example glibc-version.c ):
#include #include #include int main(int argc, char *argv[])
and compile it with the gcc-4.4 compiler:
gcc-4.4 glibc-version.c -o glibc-version
When you execute ./glibc-version the used glibc version is shown.
it works for me, but where is this docummented? I’m looking at the glibc 2.7 docs but I can’t find it.
I use OSX and I am getting ==> fatal error: ‘gnu/libc-version.h’ file not found
OSX has never used the GNU C Library; its Unix userspace is all BSD-derived. It did originally use GCC as its system compiler, but Apple as an organization is allergic to the GPLv3; it is not an accident that they started funding LLVM heavily right after GCC’s licensing was changed over.
Use -print-file-name gcc option:
$ gcc -print-file-name=libc.so /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so
That gives the path. Let’s examine the file:
$ file $(gcc -print-file-name=libc.so) /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so: ASCII text $ cat $(gcc -print-file-name=libc.so) /* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )
The file is a linker script, which links the libraries in GROUP list.
On ELF platforms /lib/x86_64-linux-gnu/libc.so.6 is a position-independent executable with a dynamic symbol table (like that of a shared library):
$ file /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6: symbolic link to libc-2.31.so $ file $(readlink -f /lib/x86_64-linux-gnu/libc.so.6) /usr/lib/x86_64-linux-gnu/libc-2.31.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1878e6b475720c7c51969e69ab2d276fae6d1dee, for GNU/Linux 3.2.0, stripped $ /lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.9) stable release version 2.31. Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 9.4.0. libc ABIs: UNIQUE IFUNC ABSOLUTE For bug reporting instructions, please see: .