0% found this document useful (0 votes)
53 views9 pages

How To Install GCC Compiler On Ubuntu (3 Simple Methods)

The document provides three methods for installing the GCC (GNU Compiler Collection) on Ubuntu, which is essential for compiling C and C++ software. The methods include installing from Ubuntu repositories, using Personal Package Archives (PPAs) for multiple versions, and building from source for customization. Each method includes step-by-step instructions and prerequisites for successful installation.

Uploaded by

franck Bihoya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views9 pages

How To Install GCC Compiler On Ubuntu (3 Simple Methods)

The document provides three methods for installing the GCC (GNU Compiler Collection) on Ubuntu, which is essential for compiling C and C++ software. The methods include installing from Ubuntu repositories, using Personal Package Archives (PPAs) for multiple versions, and building from source for customization. Each method includes step-by-step instructions and prerequisites for successful installation.

Uploaded by

franck Bihoya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.

com/kb/install-gcc-ubuntu

PHOENIXNAP HOME PRODUCTS  CONTACT SUPPORT

NETWORK  LEARN  Search

How to Install GCC Compiler on Ubuntu

August 2, 2023
UBUNTU

Home » SysAdmin » How to Install GCC Compiler on Ubuntu

Introduction
The GCC (GNU Compiler Collection) is a free software compiler system capable of compiling several programming
languages, including C, C++, Objective-C, and Fortran.

Developers who want to build C or C++ software on a Linux-based system need a reliable compiler like GCC.

Find out how to install GCC on Ubuntu and start compiling code on your system in no time.

Prerequisites
• Ubuntu 20.04 or Ubuntu 22.04 installed.
• Access to a terminal window/command line.
• A user account with root or sudo privileges.

1 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

How to Install GCC Compiler on Ubuntu?


There are several ways to install GCC on Ubuntu, and the preferred method depends on your customization needs or if a
project requires a speci�c GCC version.

Method 1: Install GCC Compiler from Ubuntu


Repositories
The fastest way to install GCC on Ubuntu is to use the apt package manager. However, installing GCC from Ubuntu
repositories has drawbacks, such as a lack of customization options and potential dependency con�icts.

To install the GCC compiler from Ubuntu repositories:

1. Update the Ubuntu package repository using the following command:

sudo apt update

2. Install the build-essential package:

sudo apt install build-essential

The build-essential package includes the GCC compiler and other utilities required for building software.

3. Use the following command to check the GCC version:

gcc --version

The GCC version in this example is 11.4.0.

Method 2: Install Multiple GCC Versions on Ubuntu


Users can utilize GCC PPAs (Personal Package Archive) to streamline the installation process and install a speci�c GCC
version (or multiple GCC versions).

To do so:

1. Update the Ubuntu package repository:

2 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

sudo apt update

2. Install the software-properties-common package using the following command:

sudo apt install software-properties-common

3. Add the GCC PPA that contains all the versions of the GCC compiler:

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

4. Update the packages list to include the PPA packages:

sudo apt update

5. Use the command below to install a speci�c version or multiple versions of GCC. For example, to install GCC 12 and
GCC 13, enter:

sudo apt install gcc-12 g++-12 gcc-13 g++-13 -y

 Note: There are no restrictions to the number of GCC versions you can install using this installation
method.

6. The update-alternatives tool helps users manage multiple GCC versions:

3 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

Add the GCC 12 alternative to the update-alternatives �lesystem:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 --slave /usr/


bin/g++ g++ /usr/bin/g++-12

Add the GCC 13 alternative to the update-alternatives �lesystem:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 --slave /usr/


bin/g++ g++ /usr/bin/g++-13

 Note: Replace the GCC version in the example commands (GCC 12 and 13) with the GCC versions
installed on your system.

7. Use the update-alternatives tool to switch between installed GCC versions:

sudo update-alternatives --config gcc

The system displays a list of the installed GCC versions and asks to select the default version. Enter the selection number
for the version you want to use.

8. Check the current GCC version using the following command:

gcc --version

The current default GCC version in this example is 13.1.0.

Method 3: Install GCC Compiler on Ubuntu from


Source
Building GCC from source is an advanced installation method that allows users to customize the GCC con�guration.
Moreover, you can change install locations or optimize GCC for speci�c hardware.

To retrieve the GCC source code from o�cial repositories and install the GCC compiler:

4 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

1. Install the necessary dependencies using the following command:

sudo apt install build-essential

2. Install the libgmp3-dev, libmpfr-dev, and libmpc-dev packages to facilitate compiling GCC from source:

sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y

3. Use the wget command to download the GCC source code from the GCC website. In this example, the �le
gcc-13.2.0.tar.gz contains the source code for GCC version 13.2.0:

wget http://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz

Adjust the URL in the command to re�ect the GCC version you want to install.

4. Extract the GCC build �les using the following command:

tar -xf gcc-13.2.0.tar.gz

5. Access the GCC directory:

cd gcc-13.2.0

5 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

6. Con�gure the GCC build:

./configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linu


x-gnu --prefix=/usr/local/gcc-13.2.0 --enable-checking=release --enable-languages=
c,c++ --disable-multilib --program-suffix=-13.2.0

Visit the o�cial GNU GCC con�guration page to review available options and recommended con�guration procedures.

7. Use the make command to initiate the GCC build process:

make -j3

The build process can consume a lot of resources and take a while to complete. The j3 command tells the system to use
three cores for the operation. Change the number of cores to re�ect your system's capabilities and setup.

8. After the build process is complete, install GCC using the following command:

sudo make install

9. Enter the following command to verify the GCC version:

/usr/local/gcc-13.2.0/bin/gcc-13.2.0 --version

The system con�rms GCC version 13.2.0 is installed.

Conclusion
You now know how to install the GCC compiler on Ubuntu using three different methods. Regardless of the method,
installing GCC on an Ubuntu machine allows you to compile and run C and C++ code and complete many programming,
debugging, and system administration tasks.

Check out these �ve different test automation frameworks that make automated testing faster and more reliable.

6 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

Was this article helpful? Yes No

Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce
and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative
technologies in others by providing practical advice and using an engaging writing style.

Next you should read

DevOps and
Development,
SysAdmin
22 Best Linux Text
Editors for
Programming &
Coding
August 8, 2024

A text editor is an
application that lets
you type text. All Linux
distributions come
with built-in editors, but
there are also other
options. In this article,
we review the 22 best
text editors.
READ MORE

Security, SysAdmin
How to Build
Linux Kernel From
Scratch
November 12, 2020

All Linux distributions


come with a prede�ned
kernel. However, they
are usually outdated.
Follow this step-by-
step guide to learn how
to build a Linux kernel
from scratch.

7 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

RE

RE

SysAdmin
How To Install and
Use Linux Screen
April 7, 2022

Screen is a powerful
tool for working in the
command line. It lets
you create, monitor,
and switch between
several different
windows.
READ MORE

DevOps and
Development,
SysAdmin
15 Best DevOps
Tools IT Experts
Use
August 2, 2023

This article reviews the


best DevOps tools
currently on the market
and helps make an
informed decision on
what tools are worth
adding to your stack.
READ MORE

8 of 9 1/17/25, 1�08 AM
How to Install GCC Compiler on Ubuntu {3 Simple Methods} https://phoenixnap.com/kb/install-gcc-ubuntu

 Live Chat  Get a Quote  Support | 1-855-330-1509  Sales | 1-877-588-5918

Privacy Center Do not sell or share my personal information


Contact Us
Legal
Privacy Policy
Terms of Use
DMCA
GDPR
Sitemap
©2025 Copyright phoenixNAP | Global IT Services. All Rights Reserved.

9 of 9 1/17/25, 1�08 AM

You might also like