UbuntuUbuntu Based

How To Install GCC on Ubuntu 24.04 LTS

Install GCC on Ubuntu 24.04

In this tutorial, we will show you how to install GCC on Ubuntu 24.04 LTS. GCC, the GNU Compiler Collection, is a fundamental tool for software development on Linux systems. It is a powerful and versatile compiler that supports multiple programming languages, including C, C++, Objective-C, Fortran, Ada, and Go. GCC plays a crucial role in compiling source code into executable programs, making it an essential component for developers working on Ubuntu 24.04.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of GCC GNU Compiler Collection on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • At least 2 GB of RAM and 10 GB of free disk space.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install GCC on Ubuntu 24.04 LTS

Step 1. Updating the Package Repository.

To ensure that you have access to the latest versions of packages, it is essential to update the package list before installing GCC. Open the terminal and execute the following command:

sudo apt update
sudo apt upgrade

The apt update command refreshes the package list, while apt upgrade installs the available updates. This step helps resolve any dependency issues and provides access to the latest security patches and bug fixes.

Step 2. Installing GCC.

  • Installing GCC Using APT Package Manager

The easiest and most common method to install GCC on Ubuntu 24.04 is by using the APT (Advanced Package Tool) package manager. APT simplifies the process of installing, upgrading, and removing software packages. To install GCC using APT, run the following command in the terminal:

sudo apt install gcc

APT will handle the installation of GCC and its dependencies automatically. Once the installation is complete, you can verify the installed version of GCC by running:

gcc --version
  • Installing GCC Using the Build-Essential Package

Another convenient way to install GCC on Ubuntu 24.04 is by installing the build-essential package. The build-essential package is a meta-package that includes GCC, along with other essential development tools and libraries. To install build-essential, use the following command:

sudo apt install build-essential

This command will install GCC, g++ (the C++ compiler), and other necessary tools for compiling and building software on Ubuntu 24.04. After the installation is complete, you can verify the GCC version as mentioned in the previous section.

  • Installing GCC from Source Code

In some cases, you may need to install a specific version of GCC that is not available through the package manager. In such situations, you can install GCC from its source code. Follow these steps to compile and install GCC from source:

wget https://ftp.gnu.org/gnu/gcc/gcc-<version>/gcc-<version>.tar.gz

Extract the downloaded file:

tar -xvf gcc-<version>.tar.gz

Navigate to the extracted directory and configure the build:

cd gcc-<version>
./configure --disable-multilib

Compile and install GCC:

make
sudo make install

Verify the installation:

gcc --version
  • Installing GCC Using PPA Repository

Personal Package Archives (PPAs) are repositories maintained by the Ubuntu community that provide additional software packages not included in the official Ubuntu repositories. To install GCC using a PPA, follow these steps:

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

Next, install GCC:

sudo apt install gcc

Verify the installation:

gcc --version

Using a PPA allows you to install newer versions of GCC that may not be available in the official Ubuntu repositories. However, exercise caution when using PPAs, as they are not officially supported by Ubuntu.

Step 3. Compiling and Running a Basic C Program.

Now that you have GCC installed on your Ubuntu 24.04 system, let’s compile and run a basic C program to ensure that everything is set up correctly.

  • Writing a Simple C Program

Open a text editor of your choice and create a new file named hello.c. Copy and paste the following code into the file:

#include 

int main() {
    printf("Hello, World!\n");
    return 0;
}
  • Compiling the C Program

To compile the hello.c program, open the terminal, navigate to the directory where the file is saved, and run the following command:

gcc hello.c -o hello
  • Running the Compiled Program

After successfully compiling the program, you can run it by executing the following command in the terminal:

./hello

This command will execute the compiled program, and you should see the output “Hello, World!” printed in the terminal.

If you no longer need GCC on your Ubuntu 24.04 system or want to remove it for any reason, you can uninstall it using the following command:

sudo apt remove --purge build-essential
sudo apt autoremove

Congratulations! You have successfully installed GCC. Thanks for using this tutorial for installing GCC GNU Compiler Collection on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the GCC website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button