C Programming

How to Check the Version of Your GCC Compiler

GCC is a compiler system which is created under the GNU Project. It supports the different programming languages including C and C++. When working with the GCC compiler, you may want to check its version for different reasons to guide how to best compile the files based on your project’s needs.

This post focuses on the GCC compiler. We will understand how to check your GCC compiler version and locate where it is installed on your computer.

Working with the GCC Compiler

The GCC compiler is a collection of different compilers. With the newer Linux and UNIX versions, you should get GCC installed by default. It gets installed as a part of the build-essential package. If you don’t have it on your system, you can install it as follows.

Start by updating your system’s cache to fix any dependencies or broken packages.

sudo apt update

 

After the update, install the GCC compiler collection with the following command:

sudo apt install build-essential

 

That’s it. You now have GCC installed in your system. The previous image confirms that GCC already resides on our system, which is true with most Linux distros. You can ascertain that GCC is installed on your system by checking its version.

How to Check the Version of Your GCC Compiler

When you want to verify that GCC is working or whether it blends in with your program, you can check its version with a simple command. Linux systems come with installed GCC, but you can use the earlier steps to install it.

You can check the GCC version using the version flag or the -v. Alternatively, you can attempt to locate its installation path. If it is installed, it displays the installation location.

Here’s how you can check the GCC version:

gcc --version

 

You will get a similar output to the one in the following image. You can note that, in this case, our installed GCC version is 11.3.0.

Alternatively, you can execute the following command to check your GCC version. You will get a similar output. However, this option has more output information, and the GCC version is displayed as your terminal’s last line.

gcc -v

 

We can still verify that we have the same installed GCC version.

Aside from checking the version of the installed GCC on your system, you can check the location where it is installed. With the “which” command, if you get an output that shows the GCC location, it confirms that it resides on your system.

Here’s how you can check where GCC resides on your system:

which gcc

 

You will get an output like the one in the following image. GCC is installed in the /usr/bin/gcc.

That’s how you work with GCC. You can start compiling your programs and get the binary file to execute to run the program.

Conclusion

GCC is a collection of different compilers that help in compiling different languages. You can use the GCC –version or the GCC -v commands when you want to check your GCC version. You will get an output that shows the version of the GCC. We explained everything in detail. Hopefully, with the given examples in this post, you will be comfortable in checking your GCC version.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.