Red Hat Developer Toolset
Hello World!
Red Hat Enterprise Linux
Introduction and prerequisites
In this tutorial, you will install the GNU Compiler Collection 8.2 from the Red Hat Developer Toolset (RHDTS) and build a simple C++ Hello World application. This tutorial should take less than 30 minutes to complete.
Before you begin, you will need a current Red Hat Enterprise Linux (RHEL) workstation or server subscription that allows you to download software and get updates from Red Hat. If you don’t have an active subscription, register and obtain the RHEL Developer Suite (includes the RHEL server) from here.
If you encounter difficulties at any point, see Troubleshooting and FAQ.
1. Enable necessary software repositories ( 2 minutes )
In this step, you will configure your system to obtain software, including the RHDTS, latest dynamic languages, and open source databases from the Red Hat Software Collection (RHSCL) repository by using the command line interface.
You can add or remove software repositories from the command line using the subscription-manager
tool as the root user. Use the --list
option to view the available software repositories and verify that you have access to RHSCL, which includes RHDTS:
$ su - # subscription-manager repos --list | egrep rhscl
If you don’t see any RHSCL repositories in the list, your subscription might not include it. See Troubleshooting and FAQ for more information.
If you are using a desktop edition of RHEL, change -server-
to -desktop-
in the following commands:
# subscription-manager repos --list # subscription-manager repos --enable rhel-7-server-optional-rpms
2. Setup your development environment ( 10 minutes )
In this next step you will use a single command to download and install GCC 8.2, and other development tools that are part of RHDTS. The length of time this step takes depends on the speed of your Internet connection and your system. With a reasonably fast connection, this step should complete in well under 5 minutes.
To install all components, type:
$ su - # yum install devtoolset-8
If you want to install a subset of components, see the instructions here.
Note: You will still use devtoolset-8 as the name of the software collection in all scl commands. Only the name of the meta-package to be installed by yum changes.
3. Hello World and your first application ( 5 minutes )
Using DTS C++ from the command line
The GNU C++ compiler is run with the command, g++. You need to add RHDTS to your environment with scl enable in a Terminal
window. Also see Permanently adding DTS to your Development Environment for more information.
$ scl enable devtoolset-8 bash
Now create hello.cpp
using a text editor such as vi
, nano
, or gedit
with the following content:
hello.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "Hello, Red Hat Developer Program World!" << endl;
return 0;
}
Now compile and run the program:
$ g++ -o hello hello.cpp $ ./hello Hello, Red Hat Developer Program World!
For more information, see the GNU C++ Compiler section of the Red Hat Developer Toolset 8 User Guide.
Docker-formatted container images
Docker-formatted container
images can be used to run RHDTS components inside virtual software containers, thus isolating them from the host system and allowing for their rapid deployment. For detailed description of the RHDTS docker-formatted container images and RHDTS dockerfiles
, see Using Red Hat Software Collections Container Images.
Working with the Red Hat Developer Toolset and Software Collection packages
The RHDTS is delivered as a set of packages in the Red Hat Software Collection (RHSCL). The software packages in RHSCL are designed to allow multiple versions of software to be installed concurrently. To accomplish this, the desired package is added to your runtime environment as needed with the scl enable
command. When scl enable
runs, it modifies environment variables and then runs the specified command. The environmental changes only affect the command that is run by scl
and any processes that are run from that command. The steps in this tutorial run the command bash
to start a new interactive shell to work in the updated environment. The changes aren’t permanent. Typing exit
will return to the original shell with the original environment. Each time you login, or start a new terminal session, scl enable
needs to be run again.
While it is possible to change the system profile to make RHSCL packages part of the system’s global environment, this is not recommended. Doing this can cause conflicts and unexpected problems with other applications because the system version of the package is obscured by having the RHSCL version in the path first.
Permanently adding DTS to your development environment
To make RHDTS a permanent part of your development environment, you can add it to the login script for your specific user ID. This is the recommend approach for development, because only processes run under your user ID will be affected.
Using your preferred text editor, add the following line to the end of ~/.bashrc
:
source scl_source enable devtoolset-8
After logging out and logging back in again, you can verify that the RHDTS GCC is in your path by running which g++
or g++ --version
.
$ which g++ /opt/rh/devtoolset-4/root/usr/bin/g++
$ g++ -v g++ (GCC) 8.2 20181112 (Red Hat 8.2.1-0)
RHEL 6
Introduction and Prerequisites
In this tutorial, you will install the GNU Compiler Collection 7.3 from the Red Hat Developer Toolset (RHDTS) and build a simple C++ Hello World application. This tutorial should take less than 30 minutes to complete.
Before you begin, you will need a current Red Hat Enterprise Linux 6 workstation or server subscription that allows you to download software and get updates from Red Hat. If you don’t have an active subscription, register and obtain the RHEL Developer Suite (includes the RHEL server) from here.
If you encounter difficulties at any point, see Troubleshooting and FAQ.
1. Enable necessary software repositories ( 2 minutes )
In this step, you will configure your system to obtain software, including the Red Hat Developer Toolset (RHDTS), latest dynamic languages, and open source databases from the DevTools repository. Instructions are provided for both the command line (CLI) and graphical user interface (GUI).
Using the Red Hat Subscription Manager GUI
Red Hat Subscription Manager can be started from the System Tools group of the Applications menu. Alternatively, you can start it from the command prompt by typing subscription-manager-gui
.
-
On the Subscription Manager System menu, select Repositories.
-
In the list of repositories, check the Enabled column for rhel-server-rhscl-6-rpms and rhel-6-server-optional-rpms. If you are using a workstation version of Red Hat Enterprise Linux, the repositories will be named rhel-workstation-rhscl-6-rpms and rhel-6-workstation-optional-rpms. Note: After clicking, it might take several seconds for the check mark to appear in the enabled column.
If you don’t see any RHSCL repositories in the list, your subscription might not include it.
See Troubleshooting and FAQ for more information.
Using subscription-manager from the command line
You can add or remove software repositories from the command line using the subscription-manager
tool as the root user. Use the --list
option to view the available software repositories and verify that you have access to RHSCL, which includes RHDTS:
$ su - # subscription-manager repos --list | egrep rhscl
If you don’t see any RHSCL repositories in the list, your subscription might not include it. See Troubleshooting and FAQ for more information.
If you are using a desktop edition of RHEL, change -server-
to -desktop-
in the following commands:
# subscription-manager repos --enable rhel-server-devtools-6-rpms # subscription-manager repos --enable rhel-6-server-optional-rpms
2. Setup your development environment ( 10 minutes )
Install GCC tool chain from the command line
In this next step you will use a single command to download and install GCC 7, and other development tools that are part of Red Hat Developer Toolset. The length of time this step takes depends on the speed of your Internet connection and your system. With a reasonably fast connection, this step should complete in well under 5 minutes.
$ su - # yum install devtoolset-7
If you want to install a subset of components, see the instructions here.
Note: You will still use devtoolset-7
as the name of the software collection in all scl
commands. Only the name of the meta-package to be installed by yum
changes.
3. Hello World and your first application ( 5 minutes )
Using DTS C++ from the command line without an IDE
The GNU C++ compiler is run with the command, g++
. You need to add DTS to your environment with scl enable
in a Terminal window. Also see Permanently adding DTS to your Development Environment for more information.
$ scl enable devtoolset-7 bash
Now create hello.cpp
using a text editor such as vi
, nano
, or gedit
with the following content:
hello.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "Hello, Red Hat Developer Program World!" << endl;
return 0;
}
Now compile and run the program:
$ g++ -o hello hello.cpp $ ./hello Hello, Red Hat Developer Program World!
For more information, see the GNU C++ Compiler section of the Red Hat Developer Toolset 7 User Guide.
Docker-formatted container images
Docker-formatted container
images can be used to run Red Hat Developer Toolset components inside virtual software containers, thus isolating them from the host system and allowing for their rapid deployment. For detailed description of the Red Hat Developer Toolset docker-formatted container images and Red Hat Developer Toolset dockerfiles
, see Using Red Hat Software Collections Container Images.
Working with the Red Hat Developer Toolset and Software Collection packages
The Red Hat Developer Toolset is delivered as a set of packages in the Red Hat Software Collection. The software packages in RHSCL are designed to allow multiple versions of software to be installed concurrently. To accomplish this, the desired package is added to your runtime environment as needed with the scl enable
command. When scl enable
runs, it modifies environment variables and then runs the specified command. The environmental changes only affect the command that is run by scl
and any processes that are run from that command. The steps in this tutorial run the command bash
to start a new interactive shell to work in the updated environment. The changes aren’t permanent. Typing exit
will return to the original shell with the original environment. Each time you login, or start a new terminal session, scl enable
needs to be run again.
While it is possible to change the system profile to make RHSCL packages part of the system’s global environment, this is not recommended. Doing this can cause conflicts and unexpected problems with other applications because the system version of the package is obscured by having the RHSCL version in the path first.
Permanently adding DTS to your development environment
To make DTS a permanent part of your development environment, you can add it to the login script for your specific user ID. This is the recommend approach for development, because only processes run under your user ID will be affected.
Using your preferred text editor, add the following line to the end of ~/.bashrc
:
source scl_source enable devtoolset-7
After logging out and logging back in again, you can verify that the DTS GCC is in your path by running which g++
or g++ -v
.
$ which g++ /opt/rh/devtoolset-7/root/usr/bin/g++
$ g++ -v g++ (GCC) 7.2.1 20170729 (Red Hat 7.2.1-1)
Learn more about Red Hat Software Collections
Red Hat Software Collections (RHSCL) deliver the latest stable versions of dynamic languages, open source databases, and web development tools that can be deployed alongside those included in RHEL. RHSCL is available with select RHEL subscriptions and has a three-year life cycle to allow rapid innovation without sacrificing stability. For more information:
-
Red Hat Software Collections 3.6 Packaging Guide — The packaging guide for RHSCL explains the concept of software collections, documents the
scl
utility, and provides a detailed explanation of how to create a custom software collection or extend an existing one. -
Red Hat Software Collections 3.6 Release Notes — The release notes for RHSCL document known problems, possible issues, and other important information available at the time of release of the content set. They also contain useful information on installing, rebuilding, and migrating.
-
How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (RHDTS) — This article lists which Red Hat Enterprise Linux subscriptions include access to RHSCL and RHDTS.
You can view the list of packages available in RHSCL by running:
$ yum --disablerepo="*" --enablerepo="rhel-server-rhscl-7-rpms" list available
Developing with Red Hat Enterprise Linux
Red Hat Enterprise Linux 7 Developer Guide — The developer guide for Red Hat Enterprise Linux 7 provides an introduction to application development tools and using source code management tools such as Git in Red Hat Enterprise Linux 7.
Become a Red Hat developer: developers.redhat.com
Red Hat delivers the resources and ecosystem of experts to help you be more productive and build great solutions. Register for free at developers.redhat.com.
Troubleshooting and FAQ
-
As a developer, how can I get a Red Hat Enterprise Linux subscription that includes Red Hat Software Collections and Developer Toolset?
Developers can get a no-cost Red Hat Enterprise Linux Developer Suite subscription for development purposes by registering and downloading through developers.redhat.com. We recommend you follow our Getting Started Guide which covers downloading and installing Red Hat Enterprise Linux on a physical system or virtual machine (VM) using your choice of VirtualBox, VMware, Microsoft Hyper-V, or Linux KVM/Libvirt. For more information, see Frequently asked questions: no-cost Red Hat Enterprise Linux Developer Suite.
-
I can’t find the RHSCL repository on my system.
Some Red Hat Enterprise Linux subscriptions do not include access to RHSCL. For a list of what subscriptions include RHSCL see How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (RHDTS).
The name of the RHSCL repository depends on whether you have a server or workstation version of RHEL installed. You can use
subscription-manager
to view the available software repositories and verify that you have access to RHSCL:$ su - # subscription-manager repos --list | egrep rhscl
-
When I run
yum install devtoolset-7 (or devtoolset-8)
, it fails due to a missing dependency.Some RHSCL collections require packages that are in the optional RPMs repository, which is not enabled by default. See Step 1 above, for how to enable both the optional RPMs and RHSCL repositories.
-
How do I install and use Eclipse IDE with Developer Toolset?.
Follow these instructions to install Eclipse IDE for use with RHDTS.
-
Which version of GCC am I using?
I’m getting the older GCC that came with RHEL instead of the newer DTS version.
How do I include the DTS GCC in my path?
The Red Hat Developer Toolset uses RHSCL to install a parallel set of packages in
/opt/rh
where they will not override the system packages that come with Red Hat Enterprise Linux.Use
which g++
to see which compiler is in your path. The RHDTS GCC executable path will begin with/opt/rh
. Alternatively, useg++ -v
to confirm that the version number is the correct one for RHDTS.$ which g++ /opt/rh/devtoolset-7/root/usr/bin/gcc $ g++ -v g++ (GCC) 7.2.1 20170729 (Red Hat 7.2.1-1)
If
which
returns/usr/bin/g++
, org++ -v
shows a different version, you need to runscl enable
to add RHDTS GCC and the rest of RHDTS to your environment.$ scl enable devtoolset-7 bash
-
How can I view the manual pages for the DTS version of GCC?
When you use
scl enable
, the manual page search path, MANPATH, is updated. This is in addition to the other environment variables that are updated which include PATH, and LD_LIBRARY_PATH.$ scl enable devtoolset-7 bash $ man g++
Note: It is possible to use
scl enable
for a specific command. This might be handy if you want to compare the manual page differences between versions.$ scl enable devtoolset-7 'man g++'
-
How do I find out which other packages are available in the Red Hat Developer Toolset?
You can view the list of packages with the following command:
# yum list available devtoolset-7-\*
-
How can I find out what RHSCL packages are installed?
scl --list
will show the list of RHSCL packages that have been installed, whether they are enabled or not.$ scl --list devtoolset-7 rh-java-common