How to Install .NET Core 3.1 on AlmaLinux
Categories:
How to Install .NET Core 3.1 on AlmaLinux
.NET Core 3.1, now part of the broader .NET platform, is a popular open-source and cross-platform framework for building modern applications. It supports web, desktop, mobile, cloud, and microservices development with high performance and flexibility. AlmaLinux, an enterprise-grade Linux distribution, is an excellent choice for hosting and running .NET Core applications due to its stability and RHEL compatibility.
This guide will walk you through the process of installing .NET Core 3.1 on AlmaLinux, covering prerequisites, step-by-step installation, and testing.
Why Choose .NET Core 3.1?
Although newer versions of .NET are available, .NET Core 3.1 remains a Long-Term Support (LTS) release. This means:
- Stability: Backed by long-term updates and security fixes until December 2022 (or beyond for enterprise).
- Compatibility: Supports building and running applications across multiple platforms.
- Proven Performance: Optimized for high performance in web and API applications.
- Extensive Libraries: Includes features like gRPC support, new JSON APIs, and enhanced desktop support.
If your project requires a stable environment, .NET Core 3.1 is a reliable choice.
Prerequisites
Before installing .NET Core 3.1 on AlmaLinux, ensure the following prerequisites are met:
Updated System:
Update all existing packages on your AlmaLinux system:sudo dnf update -y
Development Tools:
Install essential build tools to support .NET Core:sudo dnf groupinstall "Development Tools" -y
Administrative Privileges:
You need root or sudo access to install .NET Core packages and make system changes.Check AlmaLinux Version:
Ensure you are using AlmaLinux 8 or higher, as it provides the necessary dependencies.
Step 1: Enable Microsoft’s Package Repository
.NET Core packages are provided directly by Microsoft. To install .NET Core 3.1, you first need to enable the Microsoft package repository.
Import the Microsoft GPG key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Add the Microsoft repository:
sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
Update the repository cache:
sudo dnf update -y
Step 2: Install .NET Core 3.1 Runtime or SDK
You can choose between the .NET Core Runtime or the SDK depending on your requirements:
- Runtime: For running .NET Core applications.
- SDK: For developing and running .NET Core applications.
Install .NET Core 3.1 Runtime
If you only need to run .NET Core applications:
sudo dnf install -y dotnet-runtime-3.1
Install .NET Core 3.1 SDK
If you are a developer and need to build applications:
sudo dnf install -y dotnet-sdk-3.1
Step 3: Verify the Installation
Check if .NET Core 3.1 has been installed successfully:
Verify the installed runtime:
dotnet --list-runtimes
You should see an entry similar to:
Microsoft.NETCore.App 3.1.x [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Verify the installed SDK:
dotnet --list-sdks
The output should include:
3.1.x [/usr/share/dotnet/sdk]
Check the .NET version:
dotnet --version
This should display
3.1.x
.
Step 4: Create and Run a Sample .NET Core Application
To ensure everything is working correctly, create a simple .NET Core application.
Create a New Console Application:
dotnet new console -o MyApp
This command creates a new directory
MyApp
and initializes a basic .NET Core console application.Navigate to the Application Directory:
cd MyApp
Run the Application:
dotnet run
You should see the output:
Hello, World!
Step 5: Configure .NET Core for Web Applications (Optional)
If you are building web applications, you may want to set up ASP.NET Core.
Install ASP.NET Core Runtime
To support web applications, install the ASP.NET Core runtime:
sudo dnf install -y aspnetcore-runtime-3.1
Test an ASP.NET Core Application
Create a new web application:
dotnet new webapp -o MyWebApp
Navigate to the application directory:
cd MyWebApp
Run the web application:
dotnet run
Access the application in your browser at
http://localhost:5000
.
Step 6: Manage .NET Core Applications
Start and Stop Applications
You can start a .NET Core application using:
dotnet MyApp.dll
Replace MyApp.dll
with your application file name.
Publish Applications
To deploy your application, publish it to a folder:
dotnet publish -c Release -o /path/to/publish
The -c Release
flag creates a production-ready build.
Step 7: Troubleshooting Common Issues
1. Dependency Issues
Ensure all dependencies are installed:
sudo dnf install -y gcc libunwind libicu
2. Application Fails to Start
Check the application logs for errors:
journalctl -u myapp.service
3. Firewall Blocks ASP.NET Applications
If your ASP.NET application cannot be accessed, allow traffic on the required ports:
sudo firewall-cmd --add-port=5000/tcp --permanent
sudo firewall-cmd --reload
Step 8: Uninstall .NET Core 3.1 (If Needed)
If you need to remove .NET Core 3.1 from your system:
Uninstall the SDK and runtime:
sudo dnf remove dotnet-sdk-3.1 dotnet-runtime-3.1
Remove the Microsoft repository:
sudo rm -f /etc/yum.repos.d/microsoft-prod.repo
Conclusion
Installing .NET Core 3.1 on AlmaLinux is a straightforward process, enabling you to leverage the framework’s power and versatility. Whether you’re building APIs, web apps, or microservices, this guide ensures that you have a stable development and runtime environment.
With .NET Core 3.1 installed, you can now start creating high-performance applications that run seamlessly across multiple platforms. If you’re ready for a more cutting-edge experience, consider exploring .NET 6 or later versions once your project’s requirements align.