Start Developing .NET Core on Linux/Ubuntu in 5 minutes

.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.

Why Do .NET Development on Linux?

Developing .NET applications on Linux brings several benefits and can be an excellent choice for a development environment. Here are some reasons why:

  1. Cross-Platform: .NET Core, the modern, open-source, cross-platform framework from Microsoft, runs seamlessly on Linux. This allows you to develop and deploy .NET applications on any platform you choose, increasing your application’s accessibility and reach.
  2. Performance: Linux, known for its superior performance and stability, can provide a robust environment for your .NET applications. It is optimized for running high-demand applications, making it a great choice for performance-intensive .NET applications.
  3. Cost-Efficient: Linux is open source and free, which makes it a cost-effective choice for development and deployment. The savings from OS licensing costs can be significant, especially for startups or large-scale applications.
  4. Security: Linux is renowned for its security. The open-source nature of Linux means that a large community of developers continually scrutinizes and improves its security features.
  5. DevOps and Containerization: Linux is an excellent platform for DevOps practices. Tools like Docker and Kubernetes, which are essential for modern application development and deployment strategies, work exceptionally well on Linux.
  6. Community and Support: There is an active community of .NET developers on Linux, along with extensive documentation, tutorials, and resources. Microsoft also provides official support for .NET on Linux.
  7. IDE Support: Integrated Development Environments (IDEs) like Visual Studio Code provide first-class support for .NET on Linux, offering a smooth and efficient development experience.
See also  Linux Tips: Using 'tail' to Display File Updates in Realtime

All these factors make Linux an excellent choice for developing .NET applications. You get the power and flexibility of Linux, combined with the modern, efficient development practices provided by .NET Core.

.net on linux

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:

.NET Installation on Ubuntu:

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

.NET Installation on Fedora:

sudo dnf copr enable @dotnet-sig/dotnet
sudo dnf install dotnet-sdk-5.0

.NET Installation on openSUSE:

sudo zypper install libicu
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
wget https://packages.microsoft.com/config/opensuse/15/prod.repo
sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo

sudo zypper install dotnet-sdk-5.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:

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:

cd HelloWorld

And run the project:

dotnet run

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

See also  How to Restart SSH in Solaris 10/11

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.

Hope you found this guide helpful, please let us know by leaving a comment below.

Leave a Comment