Hello World!

Introduction and Prerequisites

In this tutorial, you will set up your system to install software from the Red Hat .NET repository, which provides the latest versions of .NET Core for Red Hat Enterprise Linux. You will install .NET Core and run a simple "Hello, World" application. The tutorial should take less than 10 minutes to complete.

Before you begin, you will need a current Red Hat Enterprise Linux 7 Server or Workstation subscription that allows you to download software and get updates from Red Hat. Developers can get a no-cost Red Hat Enterprise Linux Developer Suite Subscription for development purposes by registering and downloading through developers.redhat.com.

Be sure to register and attach a subscription to your Red Hat Enterprise Linux 7 installation to get access to .NET repositories. If this is a VM, you can register and attach by using subscription-manager:

In this step, you will configure your system to obtain software, including the latest .NET Core from the .NET software repository. Instructions are provided for both the command line interface (CLI) and the graphical user interface (GUI).

Using the Red Hat Subscription Manager GUI

Start Red Hat Subscription Manager using the System Tools group of the Applications menu. Alternatively, you can start it from the command prompt by typing subscription-manager-gui.

Select Repositories from the System menu of the subscription manager.

In the list of repositories, check the Enabled column for rhel-7-server-dotnet-rpms. If you are using a Workstation version of Red Hat Enterprise Linux, the repository will be named rhel-7-workstation-dotnet-rpms. Note: After clicking, it might take several seconds for the checkmark to appear in the enabled column.

If you don’t see any .NET 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 .NET:

$ su -
# subscription-manager repos --list | egrep dotnet

If you don’t see any .NET repositories in the list, your subscription might not include it. See Troubleshooting and FAQ for more information.

If you are using a Workstation edition of Red Hat Enterprise Linux, change -server- to -workstation- in the following command:

Next, create a directory and move into it. Next, run dotnet new console. This will create the C# source code for the “Hello, World” app. You can look around the source code and all the generated files to get a sense of what’s necessary to support a .NET Core application. You may notice that dotnet restore ran automatically. This fetches all the necessary dependency libraries.

Finally, run dotnet run. This will build and run the application. Note that you can run dotnet build first if you wish, but it’s not necessary for this simple console application. In the future, you’ll use dotnet build with command line options to do things such as build self-contained applications; that is, apps that can be copied and run without any need to first install .NET Core.

Working with .NET Core packages

The .NET Core software packages 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, you will need to run scl enable.

While it is possible to change the system profile to make .NET Core 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 other version in the path first.

Permanently enable .NET Core in your development environment

To make the .NET Core packages 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 as only processes run under your user ID will be affected.

Using your preferred text editor, add the following line to your ~/.bashrc:

When you deliver an application that uses .NET Core packages, a best practice is to have your startup script handle the scl enable step for your application. You should not ask your users to change their environment as this is likely to create conflicts with other applications.

Some Red Hat Enterprise Linux subscriptions do not include access to .NET Core.

The name of the repository depends on whether you have a Server or Workstation version of Red Hat Enterprise Linux installed. You can use subscription-manager to view the available software repositories and verify that you have access to .NET Core for Red Hat Enterprise Linux:

$ su -
# subscription-manager repos --list | egrep dotnet

Can I use .NET Core in containers?

Yes, .NET Core is available as a docker-formatted container image from the Red Hat Container Registry. Get started guides for building your first container are available on developers.redhat.com.

When I try to run dotnet, I get an error about a missing shared library.

This is due to not having run scl enable first. When scl enable runs, in addition to setting up the command search PATH, it also sets up the search path for shared libraries, LD_LIBRARY_PATH.

How do I uninstall .NET Core and any dependencies?

Uninstalling the rh-dotnet20-runtime package will cause the dependent packages that are no longer needed to be removed.

# yum uninstall rh-dotnet20-runtime

Some .NET/C# code/examples I’ve tried don’t work with .NET Core.

.NET Core 2.0 is a new version of the .NET platform that is incompatible with the previous .NET Framework 2.x, 3.x, and 4.x series. There is a large amount of code written for .NET Framework that will not run without modification on .NET Core.

Build Something Today

Let's walk through everything you need to build your first application.