Install, Configure, and Develop .NET Core Apps on Linux

.net framework, .net, microsoft, development

The Microsoft .NET framework is a powerful and versatile platform for developing a wide range of applications. Initially, .NET was restricted to Windows environments, but with the advent of .NET Core, you can now develop .NET applications on macOS and Linux too. This blog will walk you through the process of creating a .NET project on a Linux system.

Prerequisites

Before we start, ensure you have the following:

  1. A Linux system: This guide is applicable to most Linux distributions.
  2. A stable internet connection: You’ll need this to download the necessary software.
  3. A text editor or IDE: This is where you’ll write your code. You can use any text editor, but Visual Studio Code is recommended due to its powerful .NET Core support.

Table 1: .NET Core vs .NET Framework on Linux

A comparison of .NET Core and .NET Framework for Linux users.

Feature.NET Core.NET Framework
Cross-PlatformYes (Linux, Windows, macOS)No (Windows only)
PerformanceOptimized for high performanceGood, but Windows-dependent
Container SupportFully supported (Docker, Kubernetes)Limited containerization
Open SourceYes, under MIT licenseNo, proprietary
Use CaseModern apps, microservicesLegacy Windows applications

Why Do .NET Development on Linux?

Running .NET Core on Linux is becoming increasingly popular due to its performance, flexibility, and cost-effectiveness. Whether you’re building cloud applications, microservices, or enterprise-grade software, Linux provides a stable and efficient development environment. Here’s why it’s a great choice:

1. Cross-Platform Compatibility

.NET Core is designed to run seamlessly on Linux, Windows, and macOS. By developing on Linux, you ensure your applications can be deployed across multiple platforms without major code changes.

2. Improved Performance and Stability

Linux is lightweight, efficient, and optimized for performance-intensive applications. Many developers report that .NET Core applications run faster and more efficiently on Linux, especially when handling high-load scenarios like cloud-based microservices and APIs.

3. Lower Costs and Licensing Freedom

Unlike Windows Server, Linux is completely free and open-source. By running .NET Core on Linux, businesses save on OS licensing fees, making it a cost-effective choice for startups and enterprises alike.

4. Enhanced Security and Reliability

Linux is well-known for its security-first architecture. With frequent security patches, a strong permission model, and built-in package management, it reduces the risk of malware attacks compared to Windows environments.

5. Seamless DevOps and Cloud Integration

Linux is the go-to OS for cloud computing and DevOps workflows. It provides better support for CI/CD pipelines, automation tools, and containerized applications. Running .NET Core on Linux allows easy integration with Docker, Kubernetes, and cloud platforms like AWS, Azure, and Google Cloud.

6. Large and Active Developer Community

The open-source nature of Linux means a huge community of developers continuously improves its tools and packages. Microsoft officially supports .NET Core on Linux, providing comprehensive documentation, forums, and long-term updates.

7. First-Class IDE and Tooling Support

Popular development environments like Visual Studio Code, JetBrains Rider, and Vim offer excellent .NET Core support on Linux. Combined with CLI tools, you get a powerful and efficient development workflow without needing Windows-based IDEs.

Step-by-step Installation of .NET Core on Linux

Step 1: Installing .NET Core SDK

The first step is to install the .NET Core SDK. Open a terminal window and run the following commands based on your Linux distribution:

Ubuntu .NET Core Installation

Ubuntu is one of the most widely used Linux distributions, making it an excellent choice for .NET Core development. Microsoft provides official package repositories for Ubuntu, ensuring a smooth installation process. This guide will show you how to install the .NET Core SDK, allowing you to create and run .NET applications on your Ubuntu system with ease.

# Download the Microsoft package repository configuration
wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

# Register the Microsoft package repository on your system
sudo dpkg -i packages-microsoft-prod.deb

# Refresh package lists to include Microsoft's repo
sudo apt update

# Install .NET Core SDK (latest stable version)
sudo apt install -y dotnet-sdk-6.0

Fedora: .NET Core Installation

Fedora is a popular Linux distribution known for its cutting-edge features and strong support for developers. Installing .NET Core on Fedora is straightforward, thanks to its dnf package manager. This guide will walk you through the steps to install the .NET Core SDK, enabling you to build and run .NET applications seamlessly on Fedora.

# Install the .NET Core SDK on Fedora using the DNF package manager
sudo dnf install dotnet-sdk-6.0

openSUSE: .NET Core Installation

openSUSE is a powerful and flexible Linux distribution that provides a stable and developer-friendly environment. Microsoft offers official support for .NET Core on openSUSE, allowing developers to build and run modern applications seamlessly. This guide will walk you through the step-by-step process of installing the .NET Core SDK on openSUSE, ensuring you have everything set up for development.

# Install the ICU (International Components for Unicode) library,
# which is required for .NET Core's globalization and text processing features.
sudo zypper install libicu

# Import Microsoft's official package signing key to verify package authenticity.
# This ensures that all .NET Core packages installed from Microsoft's repo are trusted.
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

# Download the Microsoft package repository configuration file for openSUSE.
# This file contains details on where to fetch .NET Core packages.
wget https://packages.microsoft.com/config/opensuse/15/prod.repo

# Move the downloaded repository configuration file to Zypper’s repository directory.
# This allows openSUSE's package manager (zypper) to recognize Microsoft’s repo.
sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo

# Set the correct ownership for the repository configuration file.
# This ensures that only the root user can modify it, improving security.
sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo

# Install the .NET Core SDK (version 6.0) using the Zypper package manager.
# This allows you to develop and run .NET Core applications on openSUSE.
sudo zypper install dotnet-sdk-6.0

To verify the installation, type dotnet --version in your terminal. This should output the version of the .NET Core SDK installed on your machine.

Step 2: Creating a New .NET Project

After successfully installing the .NET Core SDK, you can create your first .NET project. In the terminal, navigate to the directory where you want to create the project and run the following command:

# Create a new .NET Core console application named "HelloWorld"
dotnet new console -o HelloWorld

This command creates a new console application named “HelloWorld”. The -o option creates a directory named “HelloWorld” where your project is stored.

Step 3: Running the Project

Navigate into the new project directory:

# Navigate into the project directory
cd HelloWorld

And run the project:

# Build and run the .NET Core application
dotnet run

The dotnet run command builds your project and runs the output. You should see “Hello, World!” printed in your terminal.

Step 4: Editing the Project

To edit the project, open the project directory in your chosen text editor or IDE. For instance, if you’re using Visual Studio Code, you can open it by running:

code .

The main file in your project is Program.cs. This file contains a Main method, which is the entry point for your application. You can modify this method to change what your application does.

Table 2: Common .NET Core Commands on Linux

This table provides frequently used .NET Core CLI commands and their purposes.

CommandDescription
dotnet --versionDisplays the installed .NET Core version.
dotnet new console -o MyAppCreates a new console application in the “MyApp” folder.
dotnet restoreRestores dependencies and tools from NuGet packages.
dotnet buildCompiles the application.
dotnet runRuns the application.
dotnet publish -c Release -o outPublishes the application for deployment.
dotnet testRuns unit tests in a test project.
dotnet --infoDisplays detailed system and .NET Core installation info.

FAQs

What is .NET Core, and why use it on Linux?

.NET Core is a cross-platform framework for building modern applications. Running it on Linux provides better performance, flexibility, and cost savings, especially for cloud-based and containerized applications. It also allows developers to work in open-source environments without being tied to Windows.

How do I install .NET Core on Linux?

You can install .NET Core using package managers like APT for Debian-based systems or YUM for Red Hat-based systems. Microsoft provides official repositories with installation guides. Alternatively, you can download the binaries directly from Microsoft’s website and install them manually.

Can I develop .NET Core applications on Linux?

Yes, Linux fully supports .NET Core development. You can use editors like Visual Studio Code, JetBrains Rider, or Vim, along with command-line tools like dotnet CLI. The development experience is similar to Windows, with support for debugging, unit testing, and package management.

What are the common issues when running .NET Core on Linux?

Common issues include missing dependencies, incorrect permissions, and environment variables not being set. Ensure that all required libraries are installed, check file execution permissions, and configure environment paths correctly. Running dotnet --info helps diagnose setup problems.

How do I deploy a .NET Core application on Linux?

You can deploy using self-contained or framework-dependent deployment. Common methods include using Docker, setting up a systemd service, or hosting on Nginx or Apache with a reverse proxy. Ensure proper file permissions and dependencies are in place before running the application.

Can I run ASP.NET Core applications on Linux?

Yes, ASP.NET Core runs smoothly on Linux. You can host applications using Kestrel, Nginx, or Apache. Deployment options include self-hosting or using containerized environments. Be sure to configure HTTPS, environment variables, and file permissions correctly for a smooth setup.

With better performance, cost savings, security, and DevOps readiness, Linux is an ideal platform for .NET Core development. Whether you’re deploying a high-performance web app or running microservices in a cloud-native environment, Linux + .NET Core is a winning combination.

Photo of author
As Editor in Chief of HeatWare.net, Sood draws on over 20 years in Software Engineering to offer helpful tutorials and tips for MySQL, PostgreSQL, PHP, and everyday OS issues. Backed by hands-on work and real code examples, Sood breaks down Windows, macOS, and Linux so both beginners and power-users can learn valuable insights. For questions or feedback, he can be reached at sood@heatware.net.