How to Install .NET SDK and Runtime on RHEL 7

The .NET platform from Microsoft is an open-source, cross-platform framework for building modern web applications, APIs, command-line tools, microservices, and more. Since .NET Core 3.x and the subsequent unified .NET 5+ releases, Linux has been a first-class deployment target — and Red Hat Enterprise Linux is officially supported by Microsoft. Installing the .NET SDK on RHEL 7 gives you access to the dotnet CLI, which handles project creation, compilation, publishing, and testing. This tutorial covers adding the Microsoft .NET repository for RHEL 7, installing the SDK and runtime, creating and running a console application, publishing a self-contained deployment, and configuring a production-ready systemd service for an ASP.NET Core web application behind Nginx.

Prerequisites

  • RHEL 7 system with a user holding sudo privileges.
  • A registered RHEL subscription (or access to package repositories through RHEL Developer Subscription, which is free for development use).
  • Internet access to download the Microsoft repository package.
  • Nginx installed for reverse proxy: sudo yum install -y nginx.
  • At least 1.5 GB of free disk space.

Step 1: Register the Microsoft .NET Repository

Microsoft provides an official RPM repository for RHEL. Add the repository and its GPG key using the packages Microsoft provides:

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

This command downloads and installs the packages-microsoft-prod package, which adds the Microsoft repository definition to /etc/yum.repos.d/ and imports the GPG key used to sign Microsoft’s packages. Verify the repository was added:

sudo yum repolist | grep microsoft
packages-microsoft-com-prod   packages-microsoft-com-prod   enabled: 163

Step 2: Install the .NET SDK

The SDK includes the runtime plus the compiler, CLI tools, and everything needed to develop and build .NET applications. Install the latest LTS version:

sudo yum install -y dotnet-sdk-8.0

If you only need to run existing .NET applications (not develop them), install only the ASP.NET Core runtime or the base runtime to minimize the installation footprint:

# ASP.NET Core runtime only (for hosting web apps)
sudo yum install -y aspnetcore-runtime-8.0

# Base .NET runtime only (for console apps)
sudo yum install -y dotnet-runtime-8.0

Multiple SDK and runtime versions can be installed side by side. Verify the installation:

dotnet --version
8.0.204
dotnet --list-sdks
8.0.204 [/usr/lib/dotnet/sdk]
dotnet --list-runtimes
Microsoft.AspNetCore.App 8.0.4 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.4 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

Step 3: Create a Console Application

The dotnet new command scaffolds projects from templates. Create a simple console application:

mkdir ~/dotnetdemo && cd ~/dotnetdemo
dotnet new console -n HelloWorld
cd HelloWorld

The generated project contains:

HelloWorld/
├── HelloWorld.csproj
└── Program.cs

The default Program.cs uses .NET 6+ top-level statements:

Console.WriteLine("Hello, World!");

Run the application directly with the dotnet run command, which compiles and executes in one step:

dotnet run
Hello, World!

Step 4: Build and Publish the Application

Compile the project into a binary without running it:

dotnet build
Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.34

To publish a framework-dependent deployment (smaller output, requires .NET runtime on the target machine):

dotnet publish -c Release -o ./publish

To publish a self-contained deployment that bundles the .NET runtime and runs on machines without .NET installed:

dotnet publish -c Release -r linux-x64 --self-contained true -o ./publish-sc

The self-contained output directory contains a single executable along with the runtime libraries. Copy the publish-sc directory to any RHEL 7 x64 machine and run it without installing .NET:

./publish-sc/HelloWorld

Step 5: Create an ASP.NET Core Web Application

Scaffold a minimal API application:

cd ~/dotnetdemo
dotnet new webapi -n MyWebApi
cd MyWebApi

This creates an ASP.NET Core Web API project with a sample weather forecast controller. Run it in development mode:

dotnet run
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

Test the default endpoint:

curl http://localhost:5000/weatherforecast

Step 6: Configure the Application for Production

Set the Kestrel server to listen on a specific port (or Unix socket for Nginx proxy) by editing appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      }
    }
  }
}

Publish the web application for production:

dotnet publish -c Release -o /var/www/mywebapi

Step 7: Create a systemd Service for the ASP.NET Core App

Manage the application process with systemd to ensure it starts on boot and restarts after failures:

sudo tee /etc/systemd/system/mywebapi.service <<'EOF'
[Unit]
Description=ASP.NET Core Web API
After=network.target

[Service]
WorkingDirectory=/var/www/mywebapi
ExecStart=/usr/bin/dotnet /var/www/mywebapi/MyWebApi.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=mywebapi
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://localhost:5000
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable mywebapi
sudo systemctl start mywebapi
sudo systemctl status mywebapi

View application logs through journald:

sudo journalctl -u mywebapi -f

Step 8: Configure Nginx as a Reverse Proxy

Place Nginx in front of Kestrel to handle TLS, static file caching, and connection management:

sudo tee /etc/nginx/conf.d/mywebapi.conf <<'EOF'
server {
    listen 80;
    server_name api.example.com;

    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        proxy_read_timeout 120s;
    }
}
EOF

sudo nginx -t
sudo systemctl reload nginx

Step 9: Open Firewall Ports

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

If SELinux is active, allow Nginx to forward connections:

sudo setsebool -P httpd_can_network_connect 1

Your .NET application is now running as a managed system service on RHEL 7, proxied through Nginx, with automatic restarts and structured logging through journald. The .NET platform on RHEL 7 provides a robust foundation for building cross-platform web services and APIs. From this foundation you can add HTTPS with Let’s Encrypt, integrate with SQL Server or PostgreSQL using Entity Framework Core, implement health checks, and containerize the application with Podman or Docker for portable, scalable deployments.