Software & AppsOperating SystemLinux

How To Use an Older Version of GCC on Ubuntu 18.04.4 LTS

Ubuntu 10

In this article, we will guide you through the process of using an older version of GCC on Ubuntu 18.04.4 LTS. This can be necessary in situations where certain software requires a specific version of GCC for compilation.

Quick Answer

To use an older version of GCC on Ubuntu 18.04.4 LTS, you have two options. The first option is to install an older Ubuntu release that includes the required GCC version. The second option is to compile GCC from source. Both methods have their own considerations and requirements, so choose the one that best suits your needs and level of expertise.

Understanding GCC

GCC, or the GNU Compiler Collection, is a free and open-source compiler system produced by the GNU Project. It supports various programming languages, including C, C++, and Fortran. Different versions of GCC can have different features and support for language standards, which is why you might need to use an older version.

Option 1: Installing an Older Ubuntu Release

One way to use an older version of GCC is to install an older Ubuntu release that includes the required GCC version. For example, if you need GCC 6.3.x, you can install Ubuntu 17.04, which includes this version.

However, keep in mind that older Ubuntu releases may no longer be supported with updates and security patches.

Here are the steps to install GCC 6.3 from the Ubuntu 17.04 repository:

  1. Add the repository of Ubuntu 17.04 and disable the Universe repository of Ubuntu 18.04.4 LTS:
echo "deb http://old-releases.ubuntu.com/ubuntu zesty main" | sudo tee /etc/apt/sources.list.d/zesty.list
sudo apt-add-repository -r universe

In the command above, echo is used to print the string that follows. The | symbol is a pipe that passes the output of the previous command as input to the next command. sudo tee writes the input it receives to the file /etc/apt/sources.list.d/zesty.list. The -r option in sudo apt-add-repository is used to remove the specified repository.

  1. Update the available package information and install GCC 6.3:
sudo apt update
sudo apt install gcc-6

sudo apt update updates the package lists for upgrades and new package installations. sudo apt install gcc-6 installs the gcc-6 package.

  1. Add GCC 6 as an alternative for GCC:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 1

sudo update-alternatives is a tool for managing different software versions installed on your system. --install is used to add alternatives for a program. /usr/bin/gcc is the master link. gcc is the name of the link group. /usr/bin/gcc-6 is the slave link. 1 is the priority of the slave link.

  1. Verify the installation:
gcc -v

gcc -v prints the version of GCC that is currently in use.

Option 2: Compiling GCC from Source

If the required version of GCC is not available in the Ubuntu repositories, you can compile it from source. This method requires more advanced knowledge and may take longer.

Here are the general steps:

  1. Download the source code for the desired version of GCC from the official GCC website.
  2. Extract the source code and navigate to the extracted directory.
  3. Configure the build:
./configure
make

./configure checks your system to make sure all the dependencies required to compile and install GCC are available. make compiles the source code.

  1. Install GCC:
sudo make install

sudo make install installs the compiled code on your system.

  1. Verify the installation:
gcc -v

Please note that compiling GCC from source can be complex and may have dependencies that need to be resolved. Make sure to carefully follow the instructions provided by the GCC documentation.

Conclusion

In this article, we’ve covered two methods to use an older version of GCC on Ubuntu 18.04.4 LTS. Depending on your specific needs and level of expertise, you can choose the method that is most suitable for you. Always remember to verify your installation by checking the GCC version using gcc -v.

Can I use an older version of GCC on Ubuntu 18.04.4 LTS?

Yes, you can use an older version of GCC on Ubuntu 18.04.4 LTS by either installing an older Ubuntu release that includes the required GCC version or by compiling GCC from source.

Why would I need to use an older version of GCC?

You might need to use an older version of GCC if certain software you are working with requires a specific version of GCC for compilation. Different versions of GCC can have different features and support for language standards.

How can I install an older version of GCC from an older Ubuntu release?

To install an older version of GCC from an older Ubuntu release, you can add the repository of the older release and disable the Universe repository of Ubuntu 18.04.4 LTS. Then, update the package information and install the desired GCC version using the apt package manager.

What if the required version of GCC is not available in the Ubuntu repositories?

If the required version of GCC is not available in the Ubuntu repositories, you can compile it from source. This method requires downloading the source code from the official GCC website, configuring the build, and installing GCC on your system.

Is compiling GCC from source a complex process?

Compiling GCC from source can be complex and may have dependencies that need to be resolved. It requires more advanced knowledge and may take longer compared to installing from the Ubuntu repositories. Make sure to carefully follow the instructions provided by the GCC documentation.

Leave a Comment

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