如何在ubuntu 18.04 Linux上安装GCC C编译器

安装GCC.

$ sudo apt install gcc

安装Build-Essential

安装 gcc编译器的另一种方法是将其安装为 build-essential包的一部分。
build-essential包还将安装另外的库以及 g++编译器。

$ sudo apt install build-essential

检查GCC版本

通过检查GCC版本确认安装:

$ gcc --version
gcc (Ubuntu 7.2.0-18ubuntu2) 7.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编写测试程序

创建一个简单的c语言程序:

hello.c

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

编译并执行:

$ gcc -o hello hello.c 
$ ./hello 
Hello, World!
日期:2020-07-07 20:55:23 来源:oir作者:oir