How to Install .NET 6.0 on AlmaLinux

Learn how to install .NET 6.0 on AlmaLinux with this comprehensive step-by-step guide. Includes runtime and SDK installation, application creation, and troubleshooting.

.NET 6.0 is a cutting-edge, open-source framework that supports a wide range of applications, including web, desktop, cloud, mobile, and IoT solutions. It is a Long-Term Support (LTS) release, providing stability and support through November 2024. AlmaLinux, as a reliable and enterprise-grade Linux distribution, is an excellent platform for hosting .NET applications due to its compatibility with Red Hat Enterprise Linux (RHEL).

This guide provides a detailed, step-by-step tutorial for installing .NET 6.0 on AlmaLinux, along with configuration and testing steps to ensure a seamless development experience.


Why Choose .NET 6.0?

.NET 6.0 introduces several key features and improvements:

  1. Unified Development Platform: One framework for building apps across all platforms (web, desktop, mobile, and cloud).
  2. Performance Enhancements: Improved execution speed and reduced memory usage, especially for web APIs and microservices.
  3. C# 10 and F# 6 Support: Access to the latest language features.
  4. Simplified Development: Minimal APIs for quick web API development.
  5. Long-Term Support: Backed by updates and fixes for the long term.

If you’re looking to build modern, high-performance applications, .NET 6.0 is the perfect choice.


Prerequisites

Before you begin, ensure the following prerequisites are met:

  1. AlmaLinux System Requirements:

    • AlmaLinux 8 or newer.
    • Sudo or root access to perform administrative tasks.
  2. Update Your System:

    sudo dnf update -y
    
  3. Install Development Tools:
    Install essential build tools and libraries:

    sudo dnf groupinstall "Development Tools" -y
    sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel git curl
    
  4. Firewall Configuration:
    Ensure ports required by your applications (e.g., 5000, 5001 for ASP.NET) are open:

    sudo firewall-cmd --add-port=5000/tcp --permanent
    sudo firewall-cmd --add-port=5001/tcp --permanent
    sudo firewall-cmd --reload
    

Step 1: Enable Microsoft’s Package Repository

.NET packages are provided by Microsoft’s official repository. You must add it to your AlmaLinux system.

  1. Import Microsoft’s GPG Key:

    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. Add the Repository:

    sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
    
  3. Update the Repository Cache:

    sudo dnf update -y
    

Step 2: Install .NET 6.0 Runtime or SDK

You can install the Runtime or the SDK, depending on your needs:

  • Runtime: For running .NET applications.
  • SDK: For developing and running .NET applications.

Install .NET 6.0 Runtime

If you only need to run applications, install the runtime:

sudo dnf install -y dotnet-runtime-6.0

Install .NET 6.0 SDK

For development purposes, install the SDK:

sudo dnf install -y dotnet-sdk-6.0

Step 3: Verify the Installation

To confirm that .NET 6.0 has been installed successfully:

  1. Check the Installed Runtime Versions:

    dotnet --list-runtimes
    

    Example output:

    Microsoft.NETCore.App 6.0.x [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    
  2. Check the Installed SDK Versions:

    dotnet --list-sdks
    

    Example output:

    6.0.x [/usr/share/dotnet/sdk]
    
  3. Verify the .NET Version:

    dotnet --version
    

    The output should display the installed version, e.g., 6.0.x.


Step 4: Create and Run a Sample .NET 6.0 Application

To test your installation, create a simple application.

  1. Create a New Console Application:

    dotnet new console -o MyApp
    

    This command generates a basic .NET console application in a folder named MyApp.

  2. Navigate to the Application Directory:

    cd MyApp
    
  3. Run the Application:

    dotnet run
    

    You should see:

    Hello, World!
    

Step 5: Set Up an ASP.NET Core Application (Optional)

.NET 6.0 includes ASP.NET Core for building web applications and APIs.

  1. Create a New Web Application:

    dotnet new webapp -o MyWebApp
    
  2. Navigate to the Application Directory:

    cd MyWebApp
    
  3. Run the Application:

    dotnet run
    
  4. Access the Application:
    Open your browser and navigate to http://localhost:5000 (or the displayed URL in the terminal).


Step 6: Deploying .NET 6.0 Applications

Publishing an Application

To deploy a .NET 6.0 application, publish it as a self-contained or framework-dependent application:

  1. Publish the Application:

    dotnet publish -c Release -o /path/to/publish
    
  2. Run the Published Application:

    dotnet /path/to/publish/MyApp.dll
    

Running as a Service

You can configure your application to run as a systemd service for production environments:

  1. Create a service file:

    sudo nano /etc/systemd/system/myapp.service
    
  2. Add the following content:

    [Unit]
    Description=My .NET 6.0 Application
    After=network.target
    
    [Service]
    WorkingDirectory=/path/to/publish
    ExecStart=/usr/bin/dotnet /path/to/publish/MyApp.dll
    Restart=always
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=myapp
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Production
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:

    sudo systemctl enable myapp.service
    sudo systemctl start myapp.service
    
  4. Check the service status:

    sudo systemctl status myapp.service
    

Step 7: Troubleshooting Common Issues

1. Dependency Errors

Ensure all required dependencies are installed:

sudo dnf install -y libunwind libicu

2. Application Fails to Start

Check the application logs:

journalctl -u myapp.service

3. Firewall Blocking Ports

Ensure the firewall is configured to allow the necessary ports:

sudo firewall-cmd --add-port=5000/tcp --permanent
sudo firewall-cmd --reload

Conclusion

Installing .NET 6.0 on AlmaLinux is a straightforward process, enabling you to build and run high-performance, cross-platform applications. With the powerful features of .NET 6.0 and the stability of AlmaLinux, you have a reliable foundation for developing and deploying modern solutions.

From creating basic console applications to hosting scalable web APIs, .NET 6.0 offers the tools you need for any project. Follow this guide to set up your environment and start leveraging the capabilities of this versatile framework.