If you want to develop software in C or C++ on Ubuntu 26.04 Resolute Raccoon, you will need GCC (GNU Compiler Collection) and a set of essential build tools. This guide walks you through installing GCC and the complete C/C++ development toolchain, compiling your first programs, working with Makefiles, and managing multiple GCC versions. Whether you are a beginner writing your first “Hello from LinuxConfig.org” program or an experienced developer setting up a fresh Ubuntu 26.04 system, this tutorial covers everything you need to get started with gcc install compile ubuntu 26.04.
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
System
Ubuntu 26.04 Resolute Raccoon
Software
GCC 15, g++ 15, GNU Make, build-essential
Other
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Install GCC and compile C/C++ programs on Ubuntu 26.04 using the build-essential meta-package, which pulls in gcc, g++, make, and essential libraries.
Quick Steps to Install GCC and Compile on Ubuntu 26.04
Step
Command/Action
1. Update package index
$ sudo apt update
2. Install the toolchain
$ sudo apt install build-essential
3. Compile a C program
$ gcc -o linuxconfig_app main.c
4. Compile a C++ program
$ g++ -o linuxconfig_app main.cpp
Understanding the GCC Toolchain on Ubuntu 26.04
Before diving into the installation, it is helpful to understand what the GCC toolchain consists of and how Ubuntu 26.04 packages it. GCC, the GNU Compiler Collection, is a free and open-source compiler system that supports C, C++, and several other programming languages. On Ubuntu 26.04, GCC 15 is the default compiler version shipped in the official repositories.
Rather than installing individual components separately, Ubuntu provides the build-essential meta-package. This single package pulls in everything you need for C/C++ development:
gcc and gcc-15 – the GNU C compiler
g++ and g++-15 – the GNU C++ compiler
make – the GNU build automation tool
dpkg-dev – Debian package development tools
libc6-dev – GNU C Library development headers and static libraries
Consequently, installing build-essential is the recommended approach, as it ensures all core dependencies are present and correctly configured. This is also a prerequisite for compiling many software packages from source on Ubuntu 26.04.
Installing GCC and C/C++ Development Tools on Ubuntu 26.04
Installing the full C/C++ development toolchain on Ubuntu 26.04 takes just two commands. First, update your package index to ensure you are pulling from the latest repository data, then install the build-essential package.
Update the package index: Refresh the APT package cache to make sure all package metadata is current:
$ sudo apt update
Install build-essential: This meta-package installs GCC, g++, make, and all required development libraries:
$ sudo apt install build-essential
Verify the installation: Confirm that all tools are properly installed by checking their versions:
$ gcc --version
$ g++ --version
$ make --version
You should see GCC 15 and GNU Make reported in the output.
At this point, your Ubuntu 26.04 system is fully equipped for C and C++ development. Additionally, many other development tools and source-based installations depend on build-essential, so installing it early benefits your workflow beyond just C/C++ programming.
Compiling Your First C Program on Ubuntu 26.04
Now that GCC is installed, let us write and compile a simple C program to verify everything works correctly. Therefore, open your preferred text editor and create a new file.
Create a C source file: Use nano or any text editor to create hello.c:
$ nano hello.c
Add the following content:
#include <stdio.h>
int main() {
printf("Hello from LinuxConfig.org\n");
return 0;
}
Save and exit the editor.
Compile the program: Use gcc to compile the source file into an executable binary:
$ gcc -o linuxconfig_app hello.c
The -o flag specifies the output binary name. Without it, GCC defaults to naming the output a.out.
-g – includes debugging information in the binary for use with gdb
-O2 – applies optimization level 2 for better runtime performance
-std=c17 – compiles using the C17 standard
For example, to compile with warnings and debugging information enabled:
$ gcc -Wall -Wextra -g -o linuxconfig_app hello.c
It is good practice to always compile with -Wall during development, as it catches many common mistakes before they become runtime bugs.
Compiling a C++ Program with g++ on Ubuntu 26.04
Compiling C++ programs follows a similar process, but you use g++ instead of gcc. The g++ compiler automatically links the C++ standard library and enables C++ language features.
Create a C++ source file: Create a file named hello.cpp:
IMPORTANT
While gcc can technically compile C++ files if you pass the correct flags and link the standard library manually, using g++ is the correct and recommended approach for C++ code. It handles all C++ defaults automatically.
Using Make to Build Multi-File Projects on Ubuntu 26.04
As your projects grow beyond a single source file, manually running gcc or g++ commands for each file becomes tedious and error-prone. GNU Make solves this problem by automating the build process through a Makefile. Therefore, learning to use Make is an essential part of the gcc install compile ubuntu 26.04 workflow.
Let us create a simple multi-file C project to demonstrate.
Create the project directory and source files:
$ mkdir linuxconfig_project && cd linuxconfig_project
IMPORTANT
Makefile rules require a tab character for indentation, not spaces. If you copy and paste the above content, make sure the indented lines under each rule begin with an actual tab. Using spaces will result in a *** missing separator error.
Build the project:
$ make
Make reads the Makefile, compiles each source file into an object file, and then links them into the final binary.
Clean up build artifacts: To remove compiled object files and the binary:
$ make clean
The advantage of using Make is that it only recompiles files that have changed since the last build, which significantly speeds up development on larger projects. Moreover, Makefiles serve as documentation of how a project should be built.
Installing Alternative GCC Versions on Ubuntu 26.04
In some cases, you may need a different GCC version than the default GCC 15 shipped with Ubuntu 26.04. For instance, certain projects may require an older compiler for compatibility, or you may want to test with a newer release. Ubuntu makes it straightforward to install multiple GCC versions side by side and switch between them using update-alternatives.
Check available GCC and g++ versions: Before installing an alternative version, list all GCC and g++ packages available in the Ubuntu 26.04 repositories:
IMPORTANT
Remember to configure g++ alternatives separately with sudo update-alternatives --config g++ to keep both compilers in sync.
Troubleshooting Common Compilation Errors
When compiling C/C++ programs on Ubuntu 26.04, you may encounter several common errors. Below are the most frequent issues and their solutions.
Missing Header Files
If you see an error like fatal error: someheader.h: No such file or directory, it means a required development library is not installed. For example, if your program includes <curl/curl.h>, you need to install the corresponding development package:
$ sudo apt install libcurl4-openssl-dev
As a general rule, development headers for a library named libfoo are typically found in the libfoo-dev package. You can search for the correct package using:
$ apt search libcurl | grep dev
Undefined Reference Errors
An undefined reference to 'function_name' error during linking usually means you forgot to link a required library. For instance, if your program uses math functions from <math.h>, you must explicitly link the math library:
$ gcc -o linuxconfig_app main.c -lm
The -l flag tells the linker to search for the specified library. Common examples include -lm for math, -lpthread for POSIX threads, and -lssl for OpenSSL.
Permission Denied When Running Binary
If you get bash: ./linuxconfig_app: Permission denied, the executable bit may not be set. While gcc normally sets this automatically, you can fix it manually:
The error Makefile:X: *** missing separator. Stop. almost always means you used spaces instead of a tab character for indentation. Open the Makefile in your editor and replace the leading spaces with a tab on the affected line.
Conclusion
You have successfully set up a complete C/C++ development environment on Ubuntu 26.04 Resolute Raccoon. Starting with the build-essential meta-package, you installed GCC 15, g++, and GNU Make. You then compiled both C and C++ programs from the command line, built a multi-file project with a Makefile, and learned how to manage multiple GCC versions using update-alternatives. With these tools in place, you are ready to compile software from source, develop your own applications, or contribute to open-source projects. For more advanced workflows, consider using version control with Git on Ubuntu 26.04 to track your source code changes. For further details on GCC features and options, consult the official GCC documentation.
Frequently Asked Questions
What is the difference between gcc and g++? The gcc command is the GNU C Compiler, primarily used for compiling C source code. The g++ command is the GNU C++ Compiler, which automatically links the C++ standard library and enables C++ language features. While gcc can technically compile C++ files with additional flags, g++ is the correct tool for C++ development.
How do I check which version of GCC is installed on Ubuntu 26.04? Run gcc --version in your terminal. Ubuntu 26.04 ships with GCC 15 as the default version in the build-essential package. If you have installed multiple versions, you can see which one is currently active with update-alternatives --display gcc.
How do I compile with a specific C or C++ standard? Use the -std flag followed by the standard version. For C, use gcc -std=c17 source.c for the C17 standard. For C++, use g++ -std=c++23 source.cpp for C++23. You can check which standards your GCC version supports in the GCC online documentation.
Why do I get “fatal error: no such file or directory” for a header? This error means the required development library is missing. Install the corresponding -dev package using APT. For example, sudo apt install libssl-dev provides the OpenSSL headers. Use apt search to find the right package name if you are unsure.
Do I need build-essential to compile software from source on Ubuntu 26.04? While not always strictly required, build-essential is the recommended starting point. It ensures you have the C/C++ compilers, make, and core development libraries that the vast majority of source-based builds expect. Many ./configure and cmake scripts will fail without these tools present.