How to install GCC 11 on Ubuntu

How to install GCC 11 on Ubuntu

GCC can be used to compile C, C++, Objective C, and Objective C++ language .

GCC 11 is the current Development Tools Module complier in SUSE Linux Enterprise 15 SP3.

It aims on the essential optimization levels and options LTO and PGO.

In this guide, you’ll learn how to install GCC 11 on Ubuntu, test it, and uninstall it.

How to install GCC 11 on Ubuntu

To install GCC 11 on Ubuntu, you need to add the Toolchain repository and install GCC 11 by running this command, “sudo apt install -y gcc-11”.

Step 1: Add the Toolchain repository

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

Step 2: Install GCC 11 on Ubuntu

sudo apt install -y gcc-11

Step 3: Verify the GCC 11 version

gcc-11 --version
How to test GCC 11 on Ubuntu

To test GCC 11 on Ubuntu, you need to make a main.c file, copy and paste an example code, and compile the code, and run the program.

1. Make a main.c file

nano main.c

2. Copy and paste this code

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

    return 0;
}

3. Compile a code

gcc-11 main.c -o test

4. Run the program

./test
How to uninstall GCC 11 on Ubuntu

To uninstall GCC 11 on Ubuntu, you need to remove remove GCC 11 and related dependencies and remove the GCC repository and key by running some commands.

1. Remove GCC 11/related dependencies

sudo apt purge --autoremove -y gcc-11

2. Remove the GCC repository + key

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
Further reading

How to install jq on Ubuntu

What is LD_LIBRARY_PATH?

How to Fix “python: can’t open file ‘manage.py’: [Errno 2] No such file or directory”

The post How to install GCC 11 on Ubuntu appeared first on Followchain.



* This article was originally published here

Comments