Software & AppsOperating SystemLinux

How To Install gcc-8 Only on Ubuntu 18.04

Ubuntu 2

In this article, we will guide you through the process of installing gcc-8 on Ubuntu 18.04. The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project that supports various programming languages. gcc-8 is a version of this compiler system.

Quick Answer

To install gcc-8 on Ubuntu 18.04, you need to update your system, install gcc-8 and g++-8, configure gcc-8 as the default compiler using update-alternatives, and verify the installation by checking the version.


Before starting, ensure that you have a functioning Ubuntu 18.04 system. You should also have superuser (sudo) privileges.

Step 1: Update Your System

Before installing any new software, it’s a good practice to update your system’s package list. Run the following command in your terminal:

sudo apt-get update

This command fetches the latest list of packages from the repositories.

Step 2: Install gcc-8 and g++-8

The next step is to install gcc-8 and its companion g++-8. Run the following command:

sudo apt-get install gcc-8 g++-8

This command installs both gcc-8 and g++-8 on your system. gcc is the GNU Compiler Collection, and g++ is the compiler for the C++ programming language.

Step 3: Configure gcc-8 as the Default Compiler

After installing gcc-8, you need to configure it as the default compiler. This is where update-alternatives comes in. The update-alternatives command creates, removes, maintains, and displays information about the symbolic links comprising the Debian alternatives system.

Use the following commands:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8

The --install option is used to add alternatives to the system. /usr/bin/gcc is the master link. gcc is the name of its symlink. /usr/bin/gcc-7 and /usr/bin/gcc-8 are the alternatives being introduced for the master link. The numbers 700 and 800 are the priorities of the alternatives. Higher numbers have higher priority.

The --slave option is used to link a group of related alternatives such that when the master is changed, the slave is also changed. /usr/bin/g++ is the slave link, and /usr/bin/g++-7 and /usr/bin/g++-8 are the alternatives for the slave link.

Step 4: Verify the Installation

To verify that gcc-8 is the default version, use the following command:

gcc --version

This command displays the version of gcc that is currently being used by your system. If the installation was successful, it should display gcc-8.

Step 5: Change the Default gcc Version (Optional)

If you want to switch to a different gcc version in the future, use the following command:

sudo update-alternatives --config gcc

This command will display a prompt where you can select the gcc version you want to use.


By following these steps, you can successfully install and configure gcc-8 as the default gcc version on Ubuntu 18.04. This will enable you to compile and run your programs using gcc-8.

Can I install `gcc-8` alongside other versions of gcc?

Yes, you can have multiple versions of gcc installed on your system. The update-alternatives command allows you to switch between different versions of gcc.

How do I switch to a different version of gcc?

To switch to a different version of gcc, use the sudo update-alternatives --config gcc command. This will display a prompt where you can select the gcc version you want to use.

Can I uninstall gcc-8 after installing it?

Yes, you can uninstall gcc-8 by running the command sudo apt-get remove gcc-8 g++-8. However, be cautious as removing gcc-8 may affect programs that rely on it.

Will installing gcc-8 affect my existing programs?

Installing gcc-8 should not affect your existing programs. However, be aware that using a different version of gcc may introduce compatibility issues with certain programs. It is always a good idea to thoroughly test your programs after switching to a different gcc version.

Can I install gcc-8 on a different version of Ubuntu?

The steps outlined in this article are specifically for Ubuntu 18.04. While it may be possible to install gcc-8 on a different version of Ubuntu, the process may vary. It is recommended to consult the official documentation or community resources for the specific version of Ubuntu you are using.

Leave a Comment

Your email address will not be published. Required fields are marked *