How to Set Up a C/C++ Development Environment on Arch Linux
Categories:
5 minute read
Arch Linux is renowned for its simplicity, customization, and cutting-edge packages. It is a favorite among developers who want full control over their environment, including those working with low-level programming languages like C and C++. Setting up a C/C++ development environment on Arch is straightforward, thanks to the extensive Arch User Repository (AUR) and pacman package manager.
This guide walks you through setting up a complete and productive C/C++ development environment on Arch Linux. We’ll cover installing compilers, setting up a build system, selecting an editor or IDE, and configuring version control and debugging tools.
1. System Preparation
Before diving into package installation, ensure your system is up-to-date:
sudo pacman -Syu
Optionally, install base-devel
if it’s not already present. This meta-package includes essential tools like make
, gcc
, binutils
, and more.
sudo pacman -S base-devel
You’ll also want access to the AUR for certain development tools. While you can manually clone and build AUR packages, a helper like yay
simplifies the process.
To install yay
:
cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
2. Installing the C/C++ Compilers
Arch Linux provides the latest versions of GCC and Clang. You can install either or both depending on your preference.
Install GCC (GNU Compiler Collection)
sudo pacman -S gcc
You can check the installation with:
gcc --version
Install Clang (LLVM Compiler)
sudo pacman -S clang
Verify Clang with:
clang --version
Both compilers support C and C++, with g++
and clang++
handling C++ compilation respectively.
3. Essential Build Tools
To effectively compile larger projects, you’ll need additional build tools and utilities.
Make
Make is a classic tool for managing compilation via Makefiles.
sudo pacman -S make
CMake
CMake is a modern cross-platform build system used in many C/C++ projects.
sudo pacman -S cmake
Ninja (Optional)
Ninja is a fast build system that can be used with CMake for improved performance.
sudo pacman -S ninja
To use Ninja with CMake:
cmake -G Ninja .
ninja
4. Choosing a Text Editor or IDE
The choice of editor or IDE depends on your workflow. Arch offers a wide range of options from lightweight editors to full-featured IDEs.
CLI-Based Editors
Vim/Neovim
sudo pacman -S neovim
For a better C/C++ experience in Neovim, consider plugins like:
coc.nvim
withcoc-clangd
YouCompleteMe
ALE
for linting
Emacs
sudo pacman -S emacs
Install lsp-mode
and ccls
or clangd
for language server support in C/C++.
GUI-Based IDEs
Visual Studio Code
yay -S visual-studio-code-bin
Install the following extensions:
- C/C++ by Microsoft (
ms-vscode.cpptools
) - CMake Tools
- Clangd for LSP
CLion (JetBrains, commercial)
yay -S clion
CLion provides deep CMake integration and powerful refactoring tools.
Qt Creator
Great for C++ development, especially if you’re working with the Qt framework.
sudo pacman -S qtcreator
5. Language Server Protocol (LSP) Support
Using a language server like clangd
can significantly enhance your development environment with features like autocompletion, go-to-definition, and diagnostics.
sudo pacman -S clang clang-tools-extra
Then, run:
clangd --version
Configure your editor to use clangd
. For example, in Neovim with coc.nvim
, install coc-clangd
:
:CocInstall coc-clangd
6. Static Analysis and Formatting Tools
Static analysis tools help catch bugs early, and formatting tools enforce code style.
clang-tidy
sudo pacman -S clang
Example usage:
clang-tidy main.cpp -- -std=c++17
cppcheck
sudo pacman -S cppcheck
This tool performs static analysis of C/C++ code.
Clang-Format
To auto-format your code based on a .clang-format
configuration file:
sudo pacman -S clang
clang-format -i main.cpp
7. Debugging Tools
No development setup is complete without debugging tools.
GDB (GNU Debugger)
sudo pacman -S gdb
To debug:
g++ -g main.cpp -o main
gdb ./main
LLDB (LLVM Debugger)
sudo pacman -S lldb
Useful if you’re using Clang or prefer LLVM tools.
8. Version Control
Most modern development requires version control, typically with Git.
Install Git
sudo pacman -S git
Basic setup:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
You can use Git from the terminal or integrate it with your editor (e.g., GitLens in VS Code).
9. Useful Libraries and Headers
Depending on your projects, you may want to install common libraries:
Boost
sudo pacman -S boost
SDL2 (for multimedia/graphics programming)
sudo pacman -S sdl2
OpenGL and GLUT
sudo pacman -S mesa glu freeglut
Qt
sudo pacman -S qt5-base
Or use qt6-base
for newer projects.
10. Setting Up a Sample Project
Let’s put it all together with a simple example using CMake:
Create a Project Directory
mkdir HelloCpp
cd HelloCpp
main.cpp
#include <iostream>
int main() {
std::cout << "Hello, Arch Linux!" << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloCpp)
set(CMAKE_CXX_STANDARD 17)
add_executable(hello main.cpp)
Build
mkdir build
cd build
cmake ..
make
./hello
You should see:
Hello, Arch Linux!
11. Optional: Dockerized C/C++ Development
For a reproducible environment, you can use Docker. Example Dockerfile:
FROM archlinux:latest
RUN pacman -Syu --noconfirm && \
pacman -S --noconfirm base-devel gcc cmake clang vim git
Build and run:
docker build -t cpp-dev .
docker run -it cpp-dev
Final Thoughts
Arch Linux is a developer’s paradise when it comes to setting up customized environments. Thanks to the rolling release model and a vibrant community, you’ll always have access to the latest compilers, tools, and libraries.
Whether you’re a beginner experimenting with C, or an experienced developer working on complex C++ projects, Arch provides a clean slate and complete flexibility. By setting up your environment as outlined above, you’ll be equipped with powerful tools that streamline your development workflow.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.