Install gcc 11 on Ubuntu 20.04

Install gcc 11 on Ubuntu 20.04

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

This tutorial demonstrates how to install gcc 11 on Ubuntu 20.04.

Install gcc

Run the following command to add the Toolchain repository:

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

Install gcc 11:

sudo apt install -y gcc-11

Check gcc version to verify that the installation completed successfully:

gcc-11 --version

Testing gcc

Create a main.c file:

nano main.c

Add the following code:

#include <stdio.h>

int main() {
    printf("Hello world\n");

    return 0;
}

Compile a code:

gcc-11 main.c -o test

Run a program:

./test

Uninstall gcc

If you want to completely remove gcc and related dependencies, run the following command:

sudo apt purge --autoremove -y gcc-11

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-focal.list

Leave a Comment

Cancel reply

Your email address will not be published.