How to Downgrade GCC Version on Ubuntu

How to Downgrade GCC Version on Ubuntu

The GNU Compiler Collection (GCC) is a set of compilers produced for various programming languages. It’s a crucial component for developers and system administrators.

Sometimes, after upgrading GCC, you might encounter compatibility issues with certain applications or libraries. In such cases, downgrading GCC to a previous version can be a solution.

This guide will walk you through the steps to downgrade GCC on an Ubuntu system.

Step 1: Check the Current GCC Version

Before proceeding with the downgrade, it’s essential to know the current version of GCC installed on your system. Use the following command:

gcc --version

This command will display the current GCC version. Make a note of it, as you might need to refer back to it later.

Step 2: List Available GCC Versions

To determine which versions of GCC are available for installation, use the following command:

apt-cache show gcc | grep Version

This will provide a list of GCC versions available in the repositories. Identify the version you wish to downgrade to.

See also  How to Uninstall OpenResty on Ubuntu

Step 3: Install the Desired GCC Version

Once you’ve identified the version you want, install it using the following command, replacing [version_number] with your desired version:

sudo apt-get install gcc-[version_number]

For instance, to install GCC version 7:

sudo apt-get install gcc-7

Step 4: Update Alternatives

Ubuntu uses the update-alternatives system to maintain multiple versions of a program. To set the newly installed GCC version as the default, use:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-[version_number] [priority]

Replace [version_number] with your desired version and [priority] with a number (higher numbers take precedence).

Step 5: Configure the Default GCC Version

Now, configure the system to use the desired GCC version by default:

sudo update-alternatives --config gcc

You’ll be presented with a list of installed GCC versions. Select the one you want to set as default.

Commands Mentioned

  • gcc –version – Displays the current GCC version
  • apt-cache show gcc | grep Version – Lists available GCC versions
  • sudo apt-get install gcc-[version_number] – Installs a specific GCC version
  • sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-[version_number] [priority] – Updates alternatives for GCC
  • sudo update-alternatives –config gcc – Configures the default GCC version
See also  How to Uninstall MongoDB on Ubuntu


  1. Why might I need to downgrade GCC?

    Downgrading GCC might be necessary due to compatibility issues with certain applications, libraries, or development environments that are not yet adapted to the newer GCC versions.

  2. Is it safe to have multiple GCC versions on Ubuntu?

    Yes, Ubuntu allows for multiple GCC versions to coexist. However, only one version can be set as the default at a time.

  3. How do I revert to the original GCC version?

    To revert, use the “sudo update-alternatives –config gcc” command and select the original version from the list presented.

  4. Can downgrading GCC affect system stability?

    While GCC itself is stable, downgrading might affect applications that rely on features or fixes introduced in newer versions. Always test in a controlled environment before making changes to a production system.

  5. Where can I find documentation for different GCC versions?

    The official GCC website provides comprehensive documentation for all its versions. It’s advisable to refer to it when switching between versions to understand any changes or deprecations.

See also  How to Install nslookup on Ubuntu


Downgrading GCC on Ubuntu is a straightforward process, but it’s essential to understand the reasons and implications of doing so. Whether you’re working on a dedicated server or a VPS hosting, ensuring that you have the right GCC version can be crucial for your applications and development environment.

Always remember to backup your system and test any changes in a controlled environment before applying them to a live system.

By following the steps outlined in this guide, you can successfully downgrade GCC and ensure compatibility with your required applications and libraries.


Leave a Reply

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