Install g++ 13 on Ubuntu 22.04

Install g++ 13 on Ubuntu 22.04

The g++ is a compiler of the GNU Compiler Collection (GCC). The g++ compiler is mainly used to compile C++ programs.

This tutorial explains how to install g++ 13 on Ubuntu 22.04.

Install g++

Add the Toolchain repository:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test

Install g++ 13 by using the following command:

sudo apt install -y g++-13

Now you can verify that the installation finished successfully by checking g++ version:

g++-13 --version

Testing g++

Create a main.cpp file:

nano main.cpp

Add the following lines of code:

#include <iostream>
int main() {
    std::cout << "Hello world" << std::endl;
    return 0;

Compile a code with command:

g++-13 main.cpp -o test

Run a program:


Uninstall g++

If you decided to completely remove g++ and related dependencies, execute the following command:

sudo apt purge --autoremove -y g++-13

Remove GPG key and repository:

sudo rm -rf /etc/apt/trusted.gpg.d/ubuntu-toolchain-r-ubuntu-test.gpg*
sudo rm -rf /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list

Leave a Comment

Cancel reply

Your email address will not be published.