If you’re new to programming or working with Linux, you might have heard of GCC (GNU Compiler Collection)—an essential tool for compiling C, C++, and other programming languages. Installing GCC on Ubuntu is a straightforward process, but if you’re unfamiliar with the steps or running into issues, this guide will help you install GCC on Ubuntu system easily.
Whether you’re a budding developer looking to compile your code or a seasoned programmer trying to ensure your setup is up-to-date, this article provides detailed, beginner-friendly instructions on installing GCC. We’ll walk you through everything from installing the basic version to setting up the latest version, ensuring you get the best experience on your Ubuntu machine.
Why You Need GCC on Ubuntu?
GCC is a critical tool for anyone who needs to work with compiled programming languages like C, C++, Fortran, and Ada. It acts as a compiler, converting your high-level programming code into machine-readable code that the operating system can execute. This is why it’s one of the most important components of a Linux-based development environment, especially for software developers and systems programmers.
Installing GCC on Ubuntu will allow you to:
- Compile C/C++ programs
- Develop and build software from source code
- Improve your programming environment with the latest compiler tools
Now that you know why it is crucial, let’s dive into how to install GCC on Ubuntu.
Prerequisites: What You Need Before Installing GCC
Before you start installing GCC on your Ubuntu system, there are a few things you need to have or know:
- Ubuntu Linux System: Make sure you have an active Ubuntu machine or a virtual machine set up. This guide is applicable to Ubuntu 18.04, 20.04, 22.04, and later.
- Root or Sudo Access: Installation of GCC requires administrative privileges on your system.
- Active Internet Connection: You’ll need an internet connection to download the required packages from the Ubuntu repositories.
Once these prerequisites are met, you’re good to go!

Step 1: Update Your System
Before installing any new software, it’s a good idea to update your system. This ensures you have the latest security patches, bug fixes, and software updates. To update your Ubuntu system, follow these steps:
- Open a terminal on your Ubuntu system.
- Run the following commands to update your package list and upgrade your system:
sudo apt update
sudo apt upgrade
The apt update
command fetches the latest package list, and apt upgrade
installs any updates for existing packages.
Step 2: Install GCC on Ubuntu Using APT
Once your system is up-to-date, you can proceed with installing GCC. Ubuntu uses the APT (Advanced Package Tool) package manager to install and manage software. Fortunately, GCC is available in the official Ubuntu repositories, so you can easily install it using APT.
Installing GCC 9 or GCC 10 (Stable Versions)
- Open the terminal and run the following command to install GCC:
sudo apt install gcc
This command will install the default GCC version available for your Ubuntu release. For example, Ubuntu 20.04 may install GCC 9, while Ubuntu 22.04 could install GCC 10 or later.
- Once the installation is complete, you can verify that GCC was installed correctly by checking its version:
gcc --version
This will display the installed version of GCC. For example, you might see something like:
gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
Step 3: Install Additional Packages (Optional but Recommended)
While GCC itself is the main tool for compiling code, there are a few other essential development tools and libraries that are often used in conjunction with GCC. These include G++ (the C++ compiler), make (a build automation tool), and others.
To install these tools, run the following command:
sudo apt install build-essential
The build-essential
package includes:
- GCC and G++
- Make tool
- Libraries and headers necessary for compiling code
Checking Installation of Additional Tools
To verify the installation of the additional tools, run the following commands:
- For G++:
g++ --version
- For Make:
make --version
Step 4: Installing the Latest GCC Version
If you need the latest version of GCC, not just the one available in the default Ubuntu repository, you can use the Ubuntu Toolchain PPA (Personal Package Archive). The PPA contains the most recent versions of GCC.
How to Install the Latest GCC Version
- Add the PPA repository to your system by running the following command:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
- After adding the PPA, update your package list:
sudo apt update
- Install the latest GCC version (e.g., GCC 11):
sudo apt install gcc-11
- To check if GCC 11 is installed:
gcc-11 --version
Switching Between GCC Versions
If you have multiple GCC versions installed (e.g., GCC 9 and GCC 11), you can switch between them using the update-alternatives tool.
- Run the following command to configure the default GCC version:
sudo update-alternatives --config gcc
- You’ll be prompted to choose the version you want to use. Select the corresponding number and press Enter.
Step 5: Verifying Your GCC Installation
Once GCC is installed, it’s essential to verify that everything works as expected. Open your terminal and create a simple C program to test the installation.
- Open your preferred text editor and create a new file called
hello.c
:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
- Compile the program using GCC:
gcc hello.c -o hello
- Run the compiled program:
./hello
If everything is set up correctly, you should see the following output:
Hello, World!
Congratulations! You’ve successfully installed GCC on Ubuntu and compiled your first program.
Troubleshooting Common GCC Installation Issues
While install GCC on Ubuntu is generally smooth, you may encounter some issues. Here are a few common problems and their solutions:
Issue 1: Command Not Found Error
If you run the gcc --version
command and get an error like command not found
, it means GCC isn’t properly installed or not in your system’s PATH.
- Solution: Reinstall GCC using the
sudo apt install gcc
command, and ensure the installation was successful.
Issue 2: Missing Development Tools
If you encounter errors related to missing development libraries, make sure you’ve installed the build-essential
package, as it includes all the necessary libraries and tools for compiling software.
sudo apt install build-essential
Issue 3: Multiple GCC Versions Conflict
If you have multiple versions of GCC installed and there are conflicts, use the update-alternatives
tool to set the default version, as described in Step 4.
Conclusion
GCC is an essential tool for compiling C, C++, and other programming languages on Ubuntu. In this guide, we covered the entire process—from installing the default version of GCC to installing the latest version and switching between multiple versions. Whether you’re working on a simple “Hello, World!” program or developing complex software, installing GCC is the first step in setting up a solid development environment.
Now that you have GCC installed on your Ubuntu system, you can start building and compiling your own software, contributing to open-source projects, or exploring more advanced programming techniques. Remember to keep your development tools updated, as new versions of GCC are released regularly.
Did you find this guide helpful? If you have any questions or encounter issues while installing GCC, feel free to leave a comment below. Don’t forget to share this article with fellow programmers who may find it useful. Happy coding!
This guide provided a complete walkthrough for install GCC on Ubuntu. By following these steps, even a beginner can install and start using GCC for their software development needs. Keep exploring, and don’t hesitate to check out related tutorials for more advanced topics!
Read Also : How to Install XAPK?