How to Quickly Set Up a Full Linux C/C++ Development Environment
This step‑by‑step guide shows how to choose a Linux distribution, install GCC, configure Vim/VS Code/CLion, compile and run C/C++ programs, set up debugging with GDB and Valgrind, automate builds with Makefile or CMake, beautify the terminal, and manage code with Git, all with concrete commands and examples.
Prerequisites
Select a Debian‑based distribution such as Ubuntu (desktop or server) or Debian. Allocate at least 50 GB disk space, 4 GB RAM (8 GB recommended), and 4 CPU cores. For virtual machines use bridged networking.
1. Install the compiler toolchain
sudo apt update
sudo apt install build-essential
gcc --version
g++ --version
make --versionThe build-essential package provides gcc, g++, and make.
2. Install a code editor
2.1 Vim (terminal)
sudo apt install vimBasic Vim shortcuts: i (insert), Esc (normal mode), :wq (save & quit).
2.2 Visual Studio Code (GUI)
Download the .deb package from https://code.visualstudio.com/ and install:
sudo dpkg -i code_*.deb
sudo apt-get -f install # fix missing dependenciesRecommended extensions: C/C++ , Code Runner , CMake Tools . Open a project with
code .2.3 CLion (optional IDE)
Download the .deb installer from https://www.jetbrains.com/clion/ and follow the installer prompts. A free student license is available.
3. Compile and run programs
3.1 Simple C program
#include <stdio.h>
int main() {
printf("Hello, World!
");
return 0;
} gcc hello.c -o hello
./hello3.2 Simple C++ program
#include <iostream>
using namespace std;
int main() {
cout << "Hello, C++!" << endl;
return 0;
} g++ hello.cpp -o hello
./hello3.3 Common troubleshooting
gcc: command not found– reinstall the toolchain with sudo apt install build-essential.
Missing headers ( stdio.h, iostream) – reinstall with sudo apt reinstall build-essential.
4. Debugging tools
4.1 GDB
sudo apt install gdb
g++ -g hello.cpp -o hello # compile with debug symbols
gdb ./hello run– start the program. break main – set a breakpoint at main(). next – step over the current line. print var – display the value of var.
4.2 Valgrind (memory checking)
sudo apt install valgrind -y
valgrind ./your_programLook for “All heap blocks were freed” (no leaks) or “definitely lost” / “indirectly lost” messages indicating memory leaks.
5. Build automation
5.1 Makefile (small projects)
# Define compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -g
all: main
main: main.o func.o
$(CC) $(CFLAGS) -o main main.o func.o
%.o: %.c
$(CC) $(CFLAGS) -c $<
clean:
rm -rf *.o mainRun make to build and make clean to remove generated files.
5.2 CMake (larger or cross‑platform projects)
sudo apt install cmake -y # CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_executable(main main.cpp func.cpp) mkdir build && cd build
cmake ..
makeCMake generates appropriate Makefiles for the target platform.
6. Terminal enhancement
6.1 Install Zsh and Oh‑My‑Zsh
sudo apt install zsh
chsh -s $(which zsh)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"6.2 Powerlevel10k theme and useful plugins
# Powerlevel10k theme
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k
echo 'ZSH_THEME="powerlevel10k/powerlevel10k"' >> ~/.zshrc
source ~/.zshrc
# Autosuggestions plugin
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
# Syntax highlighting plugin
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
# Enable plugins
sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' ~/.zshrc
source ~/.zshrc7. Git version control
7.1 Install Git
sudo apt install git -y
git --version7.2 Repository initialization and configuration
# Initialize repository
git init
# Set global identity
git config --global user.name "Your Name"
git config --global user.email "[email protected]"7.3 Basic workflow
# Stage changes
git add .
# Commit
git commit -m "Initial commit"
# Check status
git status
# View history
git log7.4 Remote operations
# Add remote (replace with your repository URL)
git remote add origin [email protected]:yourname/yourrepo.git
# Push initial branch
git push -u origin master
# Clone a repository
git clone [email protected]:yourname/yourrepo.gitThese commands cover the essential Git operations for solo or collaborative C/C++ development.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
