“I just want to run a Go program, but I found out I need to set up a C compiler first?!”Don’t worry, I’ll guide you through this journey easily.
๐ Prerequisites: You need the following
โ A computer that can run Ubuntu (like 18.04, 20.04, 22.04)โ Administrator privileges (you should be able to use <span>sudo</span>)โ Most importantly: you want to run a Go program, but the system says “you need to install GCC first!”
๐ง Why does Go need GCC?
Go is inherently a “standalone” language, and you can compile it using the official <span>go</span> toolchain, but sometimes it willcall the C compiler (GCC) to handle underlying dependencies, for example:
- โข Using CGO (Go calling C language libraries)
- โข Compiling Go libraries that contain C code
- โข Using the GCCGo compiler (another version of Go from the GCC family)
- โข The system lacks
<span>build-essential</span>, causing errors in the Go build process
๐ง So even if you are a pure Go developer, it’s best to have some tools in your system’s “toolbox”,install GCC, so your Go code won’t “fail” halfway through.
๐ ๏ธ Installation Steps:
1๏ธโฃ Update the system: Don’t treat an old system like a new computer
sudo apt update
sudo apt upgrade -y
โ๏ธ This step is like washing your face and brushing your teeth, don’t skip it, the system will be revitalized.
STEP 01:

STEP 02:

2๏ธโฃ Install GCC and friends: The building blocks of the world
sudo apt install build-essential -y
๐ <span>build-essential</span> not only installs <span>gcc</span>, but also brings along these:
- โข
<span>g++</span>: C++ compiler - โข
<span>make</span>: The building tool - โข Header files & library files: Without them, the Go build process might directly fail

3๏ธโฃ Check the installation:
gcc --version
g++ --version
You should see something like this (don’t worry too much about the version):
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

4๏ธโฃ Compile test code:
nano hello.c
Paste this little snippet in:
#include <stdio.h>
int main() {
printf("Hello, GCC!\n");
return 0;
}
Then press:
- โข
<span>Ctrl+O</span>โ Save - โข
<span>Enter</span>โ Confirm - โข
<span>Ctrl+X</span>โ Exit the editor
Next:
gcc hello.c -o hello
./hello
โ
If you see <span>Hello, GCC!</span>, it means it really works, not just a decoration.
๐ฆ Installing a specific version of GCC (like if you really want version 12)
sudo apt install gcc-12 g++-12
Then tell the system “use this version by default from now on”:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
โ๏ธ If you want to switch versions, you can run:
sudo update-alternatives --config gcc
๐งน Uninstall GCC:
sudo apt remove build-essential gcc g++
With this set of instructions, installing GCC on Ubuntu is a breeze, now everyone can start practicing…