GCC is an essential compiler system created under the GNU Project that supports various programming languages including C, C++, and more. When working with GCC, it‘s often helpful to verify the version installed for compatibility with your codebase. This guide will walk through multiple methods to check your GCC version from the command line.
Prerequisites
Before checking your GCC version, ensure GCC is installed on your Linux system. If not, install it with:
sudo apt update
sudo apt install build-essential
This will install GCC and other essential build tools.
Check GCC Version with –version
The easiest way to check your GCC version is with the –version flag:
gcc --version
This will print out details about your GCC install:
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 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.
Focus on the first line with the version number – in this case, 9.4.0.
Check GCC Version with -v
You can also use the -v flag to print verbose compiler version information:
gcc -v
This outputs gcc configuration info along with the version:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion=‘Ubuntu 9.4.0-1ubuntu1~20.04.1‘ --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
The last line again shows the 9.4.0 GCC version.
Using which to Locate gcc
You can also use the which command to locate where gcc is installed:
which gcc
This prints the full path:
/usr/bin/gcc
If GCC is installed, this will output a path. No output means it is not installed.
Conclusion
Finding your GCC version is easy from the terminal. Use gcc –version or gcc -v to print the installed version number. You can also use which gcc to locate the full install path. Checking your gcc version ensures you can compile code properly and catch any compatibility issues.