在RHEL 8/CentOS 8上安装GCC和开发工具

时间:2020-02-23 14:31:10  来源:igfitidea点击:

如何在RHEL 8/CentOS 8上安装开发工具?
基于RHEL的分布式专为企业和运行关键任务应用而设计。
它是最稳定和最安全的服务器操作系统。
出于安全原因和性能,他们经常预先安装的包装较少。

如果要在RHEL/CONTOS 8上进行开发或者构建开源应用程序,则需要安装包含以下工具的开发工具.AutoConfautomakeGccgcc-C ++ BisonBinutilsgdblibc-devellibtoolmakepkgconfpkgconf-m4pkgconf-pkg-configredhat-rpm-pkg-configredhat-rpm-configrpm-buildrpm- signstrace.

列出CentOS/RHEL 8上的包组

执行以下dnf命令以列出CentOS/RHEL 8上可用的包组。

$dnf group list 
 Updating Subscription Management repositories.
 Updating Subscription Management repositories.
 Last metadata expiration check: 0:02:38 ago on Sun 17 Mar 2019 09:28:36 AM EAT.
 Available Environment Groups:
    Minimal Install
    Workstation
    Custom Operating System
 Installed Environment Groups:
    Server
 Installed Groups:
    Container Management
    Development Tools
 Available Groups:
    .NET Core Development
    RPM Development Tools
    Smart Card Support
    Scientific Support
    Security Tools
    System Tools
    Headless Management
    Network Servers
    Legacy UNIX Compatibility
    Graphical Administration Tools

你可以通过 summary选项要查看已安装的组,可用组,可用环境组和安装和可用语言组的次数:

$sudo dnf groups summary
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 0:06:33 ago on Sun 17 Mar 2019 09:28:36 AM EAT.
Installed Groups: 2
Available Groups: 10

在CentOS/RHEL 8服务器上安装GCC和开发工具

以下命令用于在CentOS/RHEL 8服务器上安装GCC和开发工具。

sudo dnf group install "Development Tools"

或者

sudo dnf groupinstall "Development Tools"

我们可以查看有关的信息 Development Tools包组。

sudo dnf group info "Development Tools"

通过检查工具二进制位置来验证安装。

$whereis bison gcc flex
bison: /usr/bin/bison /usr/share/bison /usr/share/man/man1/bison.1.gz /usr/share/info/bison.info.gz
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz /usr/share/info/gcc.info.gz
flex: /usr/bin/flex /usr/share/man/man1/flex.1.gz /usr/share/info/flex.info-1.gz /usr/share/info/flex.info-2.gz /usr/share/info/flex.info.gz

检查安装的GCC版本。

$gcc --version
gcc (GCC) 8.2.1 20160905 (Red Hat 8.2.1-3)
Copyright (C) 2016 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.
$make --version
GNU Make 4.2.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

在CentOS/RHEL 8服务器上卸载GCC和开发工具

下面是用于删除CentOS/RHEL 8上的包组的命令。

sudo dnf group remove "Development Tools"

始终依赖依赖树,以避免打破其他系统包。

测试GCC编译器

让我们创造一个 Hello World程序查看它是否正确编译。

$cat  hello.c
#include <stdio.h>
int main() {
    printf("Hello, world!\n");
    return 0;
}

使用GCC编译代码。

gcc hello.c -o helloworld

运行程序以查看它是否打印 Hello, world!

$./helloworld 
Hello, world!