(How to Find C++ Version in Linux) C++ is another programming language used in creating systems and software, games, and situations where performance matters. In a Linux environment, a version of the C++ compiler is installed most of the time developers want to know what version is available to avoid incompatibility issues with the code base. This article offers a detailed procedure for identifying the type of C++ on a Linux machine.
Step 1: Open a Terminal
C++ versioning is best executed in Linux since Linux is a command-line interface operating system, which means that most of the activities associated with programming are done via a terminal.
To open a terminal:
In Ubuntu or Debian: Press Ctrl + Alt + T.
In Fedora: Open a terminal by going Help -> System -> Terminal or pressing Alt + F2 and typing gnome-terminal.
In other distributions: The procedure is normally similar. If it isn’t in the Dock yet, you can find Terminal by looking for it in Applications or under System Tools.
Step 2: Identify the C++ Compiler
If you are using Linux, you should know that most distributions include, among their package, the GNU Compiler Collection (GCC) which contains both the compiler for C and C++ languages. The C++ compiler is primarily called G++.
You can check if G++ is installed by typing the following command in the terminal:
Next, if G++ is installed, it should dump the information on the version of the GNU C++ compiler, including the version number. For example:
For instance, in the output above, numbers written as 9.3.0 are the version of g++ installed in the system.
Step 3: Check for Multiple C++ Versions
In some circumstances the Linux environments, there might be several installations of the g ++. For instance, you may be using g++-7 and g++-9 on the same host even if you are not fully aware of it.
To list all versions of G++ available, use the following command:
The following command will display all the available versions of g++ in the /usr/bin directory. The output may look something like this:
It is possible to transition from one to the others using the versions shown below: For example, to check the version of g++-7, type:
Step 4: Install a Specific C++ Version (if not installed)
If the C++ compiler is not set up for some reason or you require a particular version of it then you can get it from your distribution. For example:
In Ubuntu/Debian, use apt :
In Fedora, use dnf:
In Arch Linux, use pacman:
After installation, check the version again using g++ –version.
Step 5: Use the c++
Command
Sometimes the command C++ may point to the C++ compiler on your system and there may also be a cusp on your system as well. To check the version of C++:
This is usually a symbolic link to g++, so the result should be similar to what you get if you type g++ –version.
Step 6: Using CMake to Check the C++ Compiler Version
When in a project with CMake as the build system, CMake also provides a way of checking the version of the C++ compiler. Create a simple CMakeLists.txt file:
Run the following commands to get the compiler version:
The output will include the C++ compiler version being used by CMake:
Conclusion
It is very easy to find out the version of the C++ compiler on Linux through the command line. Typically, the check you’ll use on g++ is the g++ –version to get the version of the C++ compiler. Often you require a certain version and package managers like apt, dnf, or pacman can help to achieve the goal. Anyone who writes software or assembles open-source projects will benefit from the correct classification of the C++ version, which guarantees compatible and meaningful work.