> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# Compile C++ program with g++ compiler on Bash on Ubuntu on Windows 10 & 11
- URL: https://developerinsider.co/compile-cpp-program-with-gplusplus-compiler-on-bash-on-ubuntu-on-windows-10/
- Published: 2016-11-20T10:02:00.000Z
- Updated: 2023-09-04T06:27:06.000Z
- Author: Vineet Choudhary
- Tags: C++, Compiler, Bash, Windows, g++

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. You can compile a C++ program by using the g++ command in Bash on Ubuntu on Windows 10.

## 1.Enable Bash on Ubuntu on Windows 10

If you don't have a enable Ubuntu on Windows check out [Stepwise Guide to Enable Windows 10’s Ubuntu Bash Shell (Windows Subsystem for Linux).](https://developerinsider.co/stepwise-guide-to-enable-windows-10-subsystem-for-linux/)

## 2\. Install g++ compiler in Windows 10 Bash

To install `g++` compiler in Windows 10 Bash, Open bash and run this command

```sh
apt-get install g++

```

![](https://github.com/developerinsider/developer-insider-content/blob/master/POST/Tools/GPPRun/installgpp.png?raw=true)

Make sure compiler is installed on your Windows 10 Bash. Type the following command to verify that g++ is installed:

```sh
which g++

```

**Sample outputs:**

```
/usr/bin/g++

```

Find out version of g++, run:

```sh
g++ --version

```

![](https://github.com/developerinsider/developer-insider-content/blob/master/POST/Tools/GPPRun/whichgpp.png?raw=true)

## 3\. Write your first program on bash

Use a text editor such as nano or vi to create a C++ program called hello.cpp:

```sh
nano hello.cpp

```

![](https://github.com/developerinsider/developer-insider-content/blob/master/POST/Tools/GPPRun/nanocpp.png?raw=true)

Type the following lines (program):

```cpp
#include <iostream>

using namespace std;

int main()
{
  cout<<"hello world!!\n";
  return 0;
}

```

![](https://github.com/developerinsider/developer-insider-content/blob/master/POST/Tools/GPPRun/nano.png?raw=true)

After writing your program, press `Ctrl + O` and hit `Enter` key to save your program. To exit nano press `Ctrl + X`.

## 4\. Compile and Run Program

To compile C++ program `hello.cpp`, and create an executable file called hello, enter:

```sh
g++ hello.cpp -o hello

```

To execute program first, enter:

```sh
./hello

```

**Output:**

```
hello world!!

```

![](https://github.com/developerinsider/developer-insider-content/blob/master/POST/Tools/GPPRun/compileandrun.png?raw=true)