.NET Core

Runtimes and APIs for building and running .Net applications on Linux and in containers.

Hello World!

Build Something Today

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

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.

Using VirtualBox? You’ll find instructions here. Hyper-V? Your instructions are here. VMWare? Here is your link. KVM users, this way, please. Finally, yes, you can install on bare metal if you wish. Here is your page.

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:

$ su -
# subscription-manager register --auto-attach


If you need help, see Troubleshooting and FAQ.

1. Enable .NET Core Repository

2 minutes


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.

  1. Select Repositories from the System menu of the subscription manager.

  2. 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:

# subscription-manager repos --enable=rhel-7-server-dotnet-rpms


2. Set Up Your Development Environment

2 minutes


Next step, install .NET Core 2.2:

$ su -
# yum install rh-dotnet22

3. Hello World and Your First Application

2 minutes


Under your normal user ID, start a Terminal window. First, use scl enable to add .NET Core 2.2 to your environment:

$ scl enable rh-dotnet22 bash

Every time you start a new shell, you’ll need to re-run the scl enable command. Consider enabling it permanently.

Now, run dotnet --version to see the version number:

$ dotnet --version

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:


# Add .NET Core 2.2 to my login environment
source scl_source enable rh-dotnet22

After making the change, you should log out and log in again.

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.

Where to go next?

.NET Core Documentation at docs.microsoft.com

Find additional .NET Core packages

$ yum list available rh-dotnet21\*

View the full list of packages

For Red Hat Enterprise Linux Server edition:

$ yum --disablerepo="*" --enablerepo="rhel-7-server-dotnet-rpms" list available

For Red Hat Enterprise Linux Workstation edition:

$ yum --disablerepo="*" --enablerepo="rhel-7-workstation-dotnet-rpms" list available


Additional Content

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
  1. As a developer, how can I get a Red Hat Enterprise Linux subscription that includes .NET Core?

    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.

  2. I can’t find the .NET Core repository on my system.

    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
  3. 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.

  4. Is there an open-source community for .NET Core?

    How can I contribute or get involved with .NET Core?

    The open source community that is the upstream for .NET Core can be found at github.com/dotnet/core.

  5. I’ve installed rh-dotnetcore11, but dotnet is not in my path.

    I can’t find the dotnet command.

    $ scl enable rh-dotnet22 bash

    For more information see the Red Hat Software Collection documentation.

  6. 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.

  7. How do I uninstall .NET Core and any dependencies?

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

    # yum uninstall rh-dotnet22-runtime
  8. Some .NET/C# code/examples I’ve tried don’t work with .NET Core.

    .NET Core 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.