Enable .NET channel

In order to install .NET Core from Red Hat on RHEL, you first need to register using the Red Hat Subscription Manager. If this has not been done on your system, or if you are unsure, see the Red Hat Getting Started Guide.

Install the .NET SDK

After registering with the Subscription Manager and enabling the .NET Core channel, you are ready to install and enable the .NET SDK.

In your terminal, run the following commands:

Terminal

yum install rh-dotnet22 -yscl enable rh-dotnet22 bash

Register Microsoft key and feed

Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.

Check everything installed correctly

Once you've installed, open a new command prompt and run the following command:

Once you've installed, open a new terminal and run the following command:

Command prompt

dotnet

If the command runs, printing out information about how to use dotnet, you're good to go.

If you receive a 'dotnet' is not recognized as an internal or external command error, make sure you opened a new command prompt. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.

Create your app

In your command prompt, run the following commands:

In your terminal, run the following commands:

Command prompt

dotnet new webApp -o myWebApp --no-httpscd myWebApp

What do these commands mean?

The dotnet new command creates a new application.

The webApp parameter selects what template to use when creating your app.

The -o parameter creates a directory named myWebApp where your app is stored.

The --no-https flag specifies not to enable HTTPS.

The cd myWebApp command puts you into the newly created app directory.

What files were created?

Several files were created in the myWebApp directory, to give you a simple web application that is ready to run.

Startup.cs contains all the settings and configurations.

The myWebApp/Pages directory contains some example web pages for the application.

myWebApp.csproj defines what libraries are referenced etc.

Run your app

In your command prompt, run the following command:

In your terminal, run the following command:

Command prompt

dotnet run

Once the command completes, browse to http://localhost:5000

Congratulations, you've built and run your first .NET web app!

Edit your code

Open Pages/Index.cshtml in any text editor and replace all of the code with the following:

Index.cshtml

@page@model IndexModel@{ ViewData["Title"] = "Home page";}<h1>Hello, world!</h1><p>The time on the server is @DateTime.Now</p>

Save the file then refresh the browser to see the change:

Next steps

Now that you've got the basics, continue building your first ASP.NET app with Razor Pages.