Installeer Ubuntu 20.04 Compiler-editie

Volledige handleiding voor het instellen van Ubuntu 20.04 als een speciale compilatie- en ontwikkelomgeving. Deze "Compiler Edition" bevat alle benodigde tools voor het bouwen van software vanuit de broncode.

Systeemvereisten

Compileren is een arbeidsintensieve taak! Kies de juiste opstelling op basis van uw behoeften:

Minimale installatie

Goede installatie (aanbevolen voor de meeste gebruikers)

Betere installatie

Beste installatie (professioneel)

Stap 1: Installeer Ubuntu 20.04

Ubuntu 20.04 downloaden

Download Ubuntu 20.04.6 LTS van ubuntu.com

Installatieopties

Voor virtuele machine:

Voor fysieke machine:

Installatietype

Kies Minimale installatie om opgeblazen gevoel te verminderen:

Stap 2: Eerste systeemupdate

Update het systeem na de installatie:

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

Stap 3: Schakel broncodeopslagplaatsen in

Via GUI

  1. Open Software en updates
  2. Ga naar het tabblad Ubuntu-software
  3. Vink ✓ Broncode aan
  4. Ga naar het tabblad Updates
  5. Zorg ervoor dat alle updatetypen zijn ingeschakeld
  6. Klik op Sluiten en Herladen

Via opdrachtregel

sudo sed -i 's/# deb-src/deb-src/g' /etc/apt/sources.list
sudo apt update

Stap 4: Installeer essentiële bouwtools

Bouw Essentials-pakket

Dit omvat GCC, G++, Make en andere kerncompilatietools:

sudo apt install -y build-essential

Installatie verifiëren:

gcc --version
g++ --version
make --version

Aanvullende ontwikkelingstools

sudo apt install -y git curl wget vim nano htop

Stap 5: Installeer Compiler Toolchains

GCC/G++ (meerdere versies)

Installeer verschillende GCC-versies voor compatibiliteit:

sudo apt install -y gcc g++

Standaardversie instellen:

gcc --version
g++ --version

Clang/LLVM

sudo apt install -y clang llvm lld

### Rust
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

### Go
```bash
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install -y golang-go

Node.js en npm

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

Stap 6: Installeer build-afhankelijkheden

CMake en Ninja

Moderne bouwsystemen:

sudo apt install -y cmake ninja-build

Autotools

Voor oudere projecten:

sudo apt install -y autoconf automake libtool

Pakketconfiguratie

sudo apt install -y pkg-config

Stap 7: Installeer gemeenschappelijke bibliotheken

Ontwikkelingsbibliotheken

sudo apt install -y \
  libssl-dev \
  libcurl4-openssl-dev \
  zlib1g-dev \
  libbz2-dev \
  libreadline-dev \
  libsqlite3-dev \
  libncurses5-dev \
  libncursesw5-dev \
  xz-utils \
  tk-dev \
  libffi-dev \
  liblzma-dev \
  libgdbm-dev \
  libnss3-dev \
  libedit-dev

Grafische bibliotheken (voor GUI-toepassingen)

sudo apt install -y \
  libx11-dev \
  libxext-dev \
  libxrender-dev \
  libxrandr-dev \
  libxinerama-dev \
  libxi-dev \
  libxcursor-dev \
  libgl1-mesa-dev \
  libglu1-mesa-dev

Audiobibliotheken

sudo apt install -y libasound2-dev libpulse-dev

Stap 8: Versiebeheer installeren

Git-configuratie

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global init.defaultBranch main

Subversie (SVN)

Voor oudere projecten:

sudo apt install -y subversion

Stap 9: Installeer Python-ontwikkeltools

sudo apt install -y python3-pip python3-dev python3-venv
pip3 install --upgrade pip setuptools wheel

Stap 10: Optimaliseren voor compilatie

Verhoog Swap (voor systemen met weinig geheugen)

sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Pas het parallellisme aan

Voeg toe aan ~/.bashrc:

# Use all CPU cores for compilation
export MAKEFLAGS="-j$(nproc)"

Wijzigingen toepassen:

source ~/.bashrc

Stap 11: Installeer IDE/Tekst-editors (optioneel)

Visual Studio-code

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install -y code

Vim met plug-ins

sudo apt install -y vim-gtk3

Verificatie

Test uw compilerconfiguratie:

C-programmatest

Creëer hallo.c:

#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;
}

Compileren en uitvoeren:

gcc hello.c -o hello
./hello

C++ Programmatest

Maak hello.cpp aan:

#include <iostream>
int main() {
    std::cout << "Hello, C++!" << std::endl;
    return 0;
}

Compileren en uitvoeren:

g++ hello.cpp -o hello_cpp
./hello_cpp

Onderhoud

Houd het systeem bijgewerkt

sudo apt update && sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean

Compilatiebronnen bewaken

htop  # Press F10 to exit

Volgende stappen

Problemen oplossen

Er is onvoldoende schijfruimte

Gebruik controleren:

df -h

Pakketcache opschonen:

sudo apt clean

Onvoldoende geheugen tijdens compilatie

Verminder parallelle banen:

export MAKEFLAGS="-j2"  # Use only 2 cores

Ontbrekende afhankelijkheden

Controleer buildlogboeken en installeer ontbrekende pakketten:

sudo apt install <package-name>-dev

Aanvullende bronnen

User
❤️