How to install C++ compiler on Ubuntu 20.04

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 text file

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

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

Step 4: To execute code use the following commands

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

Thanks for reading

Unix/Linux Guru and FOSS supporter


Please enter your comment!
Please enter your name here

Latest articles

You might also likeRELATED

How to Install and Configure VNC on Ubuntu Server 20.04

This article will show you how to set up a VNC on Ubuntu Server 20.04. Virtual Network Computing (VNC) is a graphical desktop sharing technology...

How to Export Your Servers Logs with Rsyslog in Centos 8

In this post, you will learn how to Export Your Servers Logs with Rsyslog in Centos 8 In this article, we'll walk through setting up...

How To Setup a Counter Strike: Global Offensive Server on CentOS 8

Counter-Strikes first option is a feature called "Official Matchmaking." This selects a Steam-owned server near you where you can play against players from all...