How to install C++ compiler on Ubuntu 20.04

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

G++, the GNU C++ Compiler is a compiler in Linux which was developed to compile C++ programs. The file extensions that can be compiled with G++ are .c and .cpp. The aim of this tutorial is to install G++ the C++ compiler on Ubuntu 20.04 LTS Focal Fossa Linux. This will be achieved by installing the build-essential package.

Installing C++ compiler on Ubuntu 20.04 step by step instructions

Although you can install the C++ compiler separately by installation of the gcc package, the recommended way to install the C++ compiler on Ubuntu 20.04 is by installation of the entire development package build-essential.

Step 1: Install C++ compiler by installation of the development package build-essential using following command

sudo apt install build-essential

Step 2: Check C compiler version using following command

g++ --version
gcc (Ubuntu 9.2.1-17ubuntu1) 9.2.1 20191102

Step 3: Create a basic C++ code source. For example let's create hello world C++ program. Save the following code as hello.cc text file

#include <iostream> 
using namespace std; 
int main()  
{     
cout << "Hello, World!";     
return 0; 
}

Save the above code within hello.cc file, compile and execute it:

Step 4: To execute code use the following commands

$ g++ -o hello hello.cc 
$ ./hello 
Hello, World!

Thanks for reading

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook