If you try to compile C++ code on a Linux Mint or Ubuntu computer using gcc, the compile will fail. C++ code needs to be compiled using the g++ compiler which must first be installed. This article explains how to install the GCC C++ compiler on Linux Mint and Ubuntu based systems.
Trying to compile a C++ program with gcc gives the following error.
1 |
gcc: error trying to exec 'cc1plus': execvp: No such file or directory |
If g++ is used to compile the C++ program, an error message appears that indicates that g++ is currently not installed:
1 2 |
The program 'g++' is currently not installed. You can install it by typing: sudo apt-get install g++ |
Installing the GCC C++ Compiler
Before installing new software it is best to update the system. Open a terminal window and enter the following.
1 |
sudo apt-get update |
Now install the C++ compiler by entering the following:
1 |
sudo apt-get install g++ |
Compiling a Simple C++ Program
The simple “Hello World” C++ code shown below can be used to test if the C++ compiler is installed and working. Save the code to a text file called hello.cpp.
1 2 3 4 5 6 7 8 |
#include <iostream> int main (void) { std::cout << "Hello, world!\n"; return 0; } |
Compile the above program using the GCC C++ compiler as shown below. Open a terminal window and change directory to the directory containing the hello.cpp file before compiling.
1 |
g++ -o hello hello.cpp |
This will create an executable file called hello which can be run from the terminal window by entering the following command.
1 |
./hello |
The hello.cpp program is shown in the Geany editor here.

This is what the command line looks like after compiling the hello.cpp program using the g++ compiler and then running the hello application.

Hello, world! is printed in the terminal window when the program is run.
Thank you very much
During execution of ” sudo apt-get update” it displays some error like 400 bad request [IP:91.189.91.23 80 many times
Also it shows messages like w: failed to fetch
E: some index files failed to download then it can work to install g++ compiler??
Try to connect to the network Internet.
Thank you very much, this helped me get started!