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.
gcc-8 on Ubuntu 18.04, you need to update your system, install
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
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
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
--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-8 are the alternatives being introduced for the master link. The numbers
800 are the priorities of the alternatives. Higher numbers have higher priority.
--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++-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:
This command displays the version of gcc that is currently being used by your system. If the installation was successful, it should display
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
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.
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.
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.
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.
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.