Ubuntu安装GCC编译器

文章目录

  • GCC简介
  • 安装步骤
  • 常见问题

GCC简介

通常所说的GCC是GUN Compiler Collection的简称,是由GNU开发的编程语言编译器。GNU编译器套件包括C、C++、 Objective-C、 Fortran、Java、Ada和Go语言前端,也包括了这些语言的库。GCC的初衷是为GNU操作系统专门编写的一款编译器。GNU系统是彻底的自由软件。大家可以进入GCC官网查看相关信息。

Ubuntu中安装软件一般有两种方式:

  1. 源码包,安装源码包更适合系统,源码包一般为C语言编写,需要在系统中先安装GCC编译器,然后才能编译安装源码包。
  2. 二进制包,在Ubuntu中为.deb包,安装过程简单。

安装步骤

  1. 在终端输入
sudo apt install build-essential

build-essential是一整套工具,执行完后,就完成了gcc,g++,make的安装。

  1. 检查是否安装成功
gcc -v

若出现gcc版本号,则证明安装成功

常见问题

这里列举一个我在安装过程中遇到的问题,在执行完sudo apt install build-essential后,出现了:

hemu@ubuntu:~$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 build-essential : Depends: libc6-dev but it is not going to be installed or
                            libc-dev
                   Depends: g++ (>= 4:4.4.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

出现这个问题一般是因为软件源不匹配的问题,建议更改下载的源:

cd /etc/apt
sudo cp sources.list sources.list.bak
sudo vim sources.list

将sources.list的内容更换为阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

然后更新一下软件:

sudo apt-get update
sudo apt-get upgrade

然后在安装gcc。

你可能感兴趣的:(Ubuntu安装GCC编译器)