Set Up C++ Environment on Ubuntu: Step-by-Step
To set up a C++ environment, you can follow the steps below:
- Install C++ compiler: To install the GNU C++ compiler, run the following command in the terminal.
sudo apt-get install g++
- Install the C++ development tool kit: Run the following command to install the C++ development tool kit:
sudo apt-get install build-essential
- Create a C++ source code file: Use a text editor to create a C++ source code file, such as hello.cpp.
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
- Compile C++ source code: To compile a C++ source code file, run the following command in the terminal:
g++ hello.cpp -o hello
- Run the executable file: Use the following command to execute the compiled executable file:
./hello
By following the above steps, you can set up and run a C++ environment in Ubuntu.