- CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
- CentOS / RHEL 7: Install GCC Package list
- Installing GCC c and c++
- Command to list groups on a CentOS / RHEL 7
- Command to install GCC and Development Tools on a CentOS / RHEL 7 server
- A note about failing groupinstall on CentOS/RHEL 7.x
- Verify your gcc installation on a CentOS / RHEL 7 server
- 💄 Установка GCC и средста разработки на RHEL 8 / CentOS 8
- Как мне установить Инструменты разработки на RHEL / CentOS 8 ?
- Перечислите группы пакетов на CentOS / RHEL 8
- Установите GCC и средства разработки на сервере CentOS / RHEL 8
- Удаление GCC и средств разработки на сервере CentOS / RHEL 8
- Тестовый компилятор GCC
- How to install Clang/LLVM 5 and GCC 7 on RHEL
- How to install Clang/LLVM 5 and GCC 7
- About software collections
- Enable repos with additional developer tools
- Install GCC 7 and Clang/LLVM 5
- View additional packages, see other available versions
- How to install the Eclipse IDE with C/C++ Development Tooling
- How to use GCC 7 or Clang (scl enable)
- How to permanently enable a software collection
- But I need GCC 6, how do I install it?
- How to look at the manual page for a specific version
- How to see which software collections are installed
- How to tell which software collections are enabled
- Articles for C/C++ Developers
- Product information and documentation
CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
H ow do I install gnu gcc compiler and related tools such as autoconf, automake, flex, c++ compiler, and bison on a CentOS 7 or Red Hat Enterprise Linux version 7 server? How can I install GCC (C and C++ Compiler) and development tools on a CentOS or RHEL 7?
You can setup a basic development environment with the following packages on a CentOS Enterprise Linux or Red Hat Enterprise Linux version 7:
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | None |
Est. reading time | 5m |
CentOS / RHEL 7: Install GCC Package list
- autoconf
- automake
- binutils
- bison
- flex
- gcc (c compiler)
- gcc-c++ (c++ compiler)
- gettext
- libtool
- make
- patch
- pkgconfig
- redhat-rpm-config
- rpm-build
- rpm-sign
Installing GCC c and c++
Open the Terminal app and type the following commands.
Command to list groups on a CentOS / RHEL 7
Type the following yum command:
# yum group list
Sample outputs:
Fig. 01: CentOS / RHEL 7: List Package Groups Command
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Command to install GCC and Development Tools on a CentOS / RHEL 7 server
Type the following yum command as root user:
# yum group install «Development Tools»
OR
$ sudo yum group install «Development Tools»
If above command failed, try:
# yum groupinstall «Development Tools»
Sample outputs:
Animated gif 01: Installing C & C++ and related packages on a CentOS and RHEL 7
A note about failing groupinstall on CentOS/RHEL 7.x
To install all the packages belonging to a package group called “Development Tools” use the following command:
# yum —setopt=group_package_types=mandatory,default,optional groupinstall «Development Tools»
OR
# yum —setopt=group_package_types=mandatory,default,optional group install «Development Tools»
The yum has changed in Red Hat Enterprise Linux 7/CentOS 7. The package group “Development Tools”” has only the optional packages which by default doesn’t get installed. So we will need to pass the option —setopt=group_package_types=mandatory,default,optional to install the optional packages too.
Verify your gcc installation on a CentOS / RHEL 7 server
Type the following command to see gcc location:
Type the following command to see gcc compiler version:
Источник
💄 Установка GCC и средста разработки на RHEL 8 / CentOS 8
Как мне установить Инструменты разработки на RHEL / CentOS 8 ?
Дистрибутивы на основе RHEL предназначены для предприятий и запуска критически важных приложений.
Это самая стабильная и безопасная серверная операционная система.
По соображениям безопасности и производительности ОС часто поставляются с меньшим количеством предварительно установленных пакетов.
Если вы хотите заниматься разработкой или создавать приложения с открытым исходным кодом на RHEL / CentOS 8, вам необходимо установить инструменты разработки, которые включают в себя следующие инструменты.
- autoconf
- automake
- gcc
- gcc-c++
- bison
- flex
- binutils
- gdb
- glibc-devel
- libtool
- make
- pkgconf
- pkgconf-m4
- pkgconf–pkg-config
- redhat-rpm-config
- rpm-build
- rpm-sign
- strace
Перечислите группы пакетов на CentOS / RHEL 8
Введите следующую команду dnf, чтобы получить список групп пакетов, доступных на CentOS / RHEL 8.
Вы можете передать параметр summary , чтобы просмотреть количество установленных групп, доступных групп и т.д.
Установите GCC и средства разработки на сервере CentOS / RHEL 8
Следующая команда используется для установки GCC и средств разработки на сервере CentOS / RHEL 8.
Вы можете просмотреть информацию о группе пакетов Development Tools
Проверьте установку, проверив места расположения инструментов.
Проверьте установленную версию GCC.
Удаление GCC и средств разработки на сервере CentOS / RHEL 8
Ниже приведена команда, используемая для удаления группы пакетов в CentOS / RHEL 8.
Будьте внимательны к дереву зависимостей, чтобы не сломать другие системные пакеты.
Тестовый компилятор GCC
Давайте создадим программу Hello World, чтобы увидеть, правильно ли она компилируется.
Скомпилируйте код с GCC.
Запустите программу, чтобы увидеть, печатает ли она Hello, world на консоли!
Благодарим Вас за установку GCC и средств разработки на RHEL / CentOS 8 с помощью нашего руководства.
Вы можете проверить другие руководства RHEL / CentOS 8, доступные в нашем блоге.
Источник
How to install Clang/LLVM 5 and GCC 7 on RHEL
If you are developing with C/C++, Clang tools and newer versions of GCC can be quite helpful for checking your code and giving you better warnings and error messages to help avoid bugs. The newer compilers have better optimizations and code generation.
You can easily install the latest-supported Clang and GCC compilers for C, C++, Objective-C, and FORTRAN using yum on Red Hat Enterprise Linux. These compilers are available as software collections that are typically updated twice a year. The May 2018 update included Clang/LLVM 5 and GCC 7.3, as well as Go and Rust.
If you want your default gcc to always be GCC 7, or you want clang to always be in your path, this article shows how to permanently enable a software collection by adding it to the profile (dot files) for your user account. A number of common questions about software collections are also answered.
How to install Clang/LLVM 5 and GCC 7
- Become root.
- Enable the rhscl , devtools , and optional software repos.
- Add the Red Hat Developer Tools key to your system
- Use yum to install devtoolset7 (GCC 7) and llvm-toolset-7 (Clang 5).
- Optional: Install the Clang static analysis tools scan-build and clang-tidy
- Under your normal user ID, run scl enable to add devtoolset-7 and llvm-toolset-7 to your path(s)
- Optional: Permanently enable GCC 7 and Clang 5 by adding scl_source to your .bashrc
About software collections
Using software collections takes an extra step because you have to enable the collection you want to use. Enabling just adds the necessary paths ( PATH , MANPATH , LD_LIBRARY_PATH ) to your environment. Once you get the hang of it, they are pretty ease to use. It really helps to understand the way that environment variable changes work in Linux/UNIX. Changes can only be made to the current process. When a child process is created it inherits the environment of the parent. Any environment changes made in the parent after the child has been created will have no effect on the child.
The benefit of software collections is that you can have GCC 5, 6, 7 installed at the same time along with the base GCC 4 that shipped with Red Hat Enterprise Linux. You can easily switch between versions with scl enable . Note: The latest interpreted languages like Python 3, PHP 7, and Ruby 2.5 are also available via Red Hat Software Collections. The .NET Core packages that include the C# compiler are also distributed as software collections. So you should take the time to get comfortable with software collections.
Enable repos with additional developer tools
While the default/base Red Hat Enterprise Linux software repos have a lot of development tools, these are the older versions that are shipped with the OS and are supported for the full 10-year life of the OS. Packages that are updated more frequently and have a different support life cycle are distributed in other repos that aren’t enabled by default.
To enable the additional repos, run the following commands as the root user:
- You can enter the above all on one line without the backslashes. The backslashes are needed if you want to use multiple lines for readability.
- If you are using the workstation variant of Red Hat Enterprise Linux, change -server- to -workstation- .
- This command only needs to be run once. The repos will stay enabled. All of the enabled repos will be searched by yum when installing or updating software.
- The No-cost Red Hat Enterprise Linux subscription for developers includes access to all of these repos and the server variant of Red Hat Enterprise Linux. The server variant is a superset.
- For more information, see the FAQ for the No-cost subscription.
To see which repos are available for your current subscription, run the following command:
To see which repos are enabled, use —list-enabled :
Install GCC 7 and Clang/LLVM 5
You can install GCC 7 and Clang/LLVM 5 with one command:
- If you only want to install GCC 7, install just devtoolset-7 .
- If you only want to install Clang/LLVM 5, install just llvmtoolset-7 .
- These packages will install in /opt/rh .
- They will not be added to your path until you do an scl enable . See below.
View additional packages, see other available versions
You can use yum search to search for additional packages and see the other versions that are available:
If you’d like to install Clang’s static analysis tools scan-build and clang-tidy , run the following command:
How to install the Eclipse IDE with C/C++ Development Tooling
Red Hat Developer Tools includes the Eclipse IDE with C/C++ Development Tooling (CDT). The version as of the May 2018 update is 4.7.3 Oxygen. To install the IDE, run the following command:
As above, if you want to search for additional packages, or see the other versions that are available, you can use yum search . There are a lot of Eclipse packages, so you might want to redirect the output to a file and then use grep , less , or your favorite text editor.
How to use GCC 7 or Clang (scl enable)
GCC 7 and Clang/LLVM 5 are now installed. You no longer need to run under the root user ID. The rest of the commands should be executed using your normal user account.
As previously mentioned, software collections are installed under /opt/rh and aren’t automatically added to your PATH , MANPATH , and LD_LIBRARY_PATH . The command scl enable will make the necessary changes and run a command. Because of the way environment variables work in Linux (and UNIX), the changes will only take affect for the command run by scl enable . You can use bash as the command to start an interactive session. This is one of the most common ways (but not the only way) of working with software collections.
You can use the which command to see where gcc is found in your PATH . Note: Once you exit out of the bash shell that was started by scl enable , you will revert to your original PATH , which no longer has the software collection in it:
For Clang/LLVM, use llvm-toolset-7 as the collection to enable:
You can also enable both collections at the same time. The order will determine the order for the directories in the PATH. If there are any commands that are in both collections, the last collection added will take precedence.
How to permanently enable a software collection
To permanently enable GCC 7 and/or Clang/LLVM 5, you can add an scl_source command to the «dot files» for your specific user ID. This is the recommend approach for development, as only processes that run under your user ID will be affected. The benefit of this approach is if you are using a graphical desktop, anything that you start from the menu will already have the collection enabled.
Using your preferred text editor, add the following line to your
Note: you could also add the line to the start of a build script to select the desired compiler for the build. If your build script isn’t written as a shell/bash script you could just wrap it in a shell script that has the source scl_source collection-name command and then runs your build script.
A caveat with permanently enabling a software collection is that there is no disable command. Everything is in environment variables, so you can work around it, but it would be a manual process.
But I need GCC 6, how do I install it?
If you need GCC 6 instead of GCC 7, you can follow these same instructions. Installing devtoolset-6 will install GCC 6.3.
Note: There is no devtoolset-5 . GCC 5 was included in devtoolset-4 , which you could also install if needed. The version number was bumped to 6, skipping 5, in order to sync with GCC major versions.
Using software collections you can have GCC 4, 5, 6, and 7 all installed at the same time and easily switch between them.
How to look at the manual page for a specific version
Enabling a software collection will prepend that software collection’s manual pages to the MANPATH , which is the search path for manual pages. Just like commands, any existing manual pages in later directories with the same name will be hidden. This is one of the times when it can be useful to run a single command, like man with scl enable , instead of starting a bash shell.
Since there is no disable command, you need a work around to see the man page for GCC-4:
The above command just changes MANPATH in a subshell so it won’t affect anything else.
Note: The same techniques will work for other commands like GNU info and INFOPATH .
How to see which software collections are installed
You can use the command scl -l to see what software collections are installed. This will show all software collections that are installed, whether they are enabled or not.
How to tell which software collections are enabled
The environment variable X_SCLS contains a list of the software collections that are currently enabled. This is handy to use in shell scripts.
Articles for C/C++ Developers
There are a number of articles on the Red Hat Developer blog that are helpful to C/C++ developers:
- Getting started with Clang/LLVM
- Recommended compiler and linker flags for GCC—Improve warnings and code generation with the right flags.
- Implicit fall through detection with GCC 7—detect missing break statements inside of a switch block. The warning is enabled with -Wimplicit-fallthrough . It is also one of the warnings that will be enabled if you use -Wextra
- Memory error detection using GCC 7
Product information and documentation
For information and documentation about these Red Hat products:
Источник