sudo apt updatesudo apt install build-essential
sudo apt-get install manpages-dev
gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0Copyright (C) 2019 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
编译Hello World示例
nano hello.c
// hello.c#include <stdio.h> int main() { printf("Hello, world!\n"); return 0;}
gcc hello.c -o hello
./hello
Hello World!安装多个GCC版本
sudo apt install gcc-8 g++-8 gcc-9 g++-9 gcc-10 g++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8
sudo update-alternatives --config gccThere are 3 choices for the alternative gcc (providing /usr/bin/gcc). Selection Path Priority Status------------------------------------------------------------* 0 /usr/bin/gcc-10 100 auto mode 1 /usr/bin/gcc-10 100 manual mode 2 /usr/bin/gcc-8 80 manual mode 3 /usr/bin/gcc-9 90 manual modePress <enter> to keep the current choice
- , or type selection number:
系统将为您提供Ubuntu系统上所有已安装的GCC版本的列表。输入您要用作默认版本的版本号,然后按Enter。该命令将创建指向GCC和G ++特定版本的符号链接。