Setting up C# Development Environment on Ubuntu 22.04


Setting up C# Development Environment

To write and compile C# programs on Ubuntu 22.04, you can use the .NET SDK, which is a free, open-source, and cross-platform framework for building modern, cloud-based, and internet-connected applications. Here are the steps to set up your environment and write/compile C# programs:

Install .NET SDK:

Open a terminal and follow these steps to install the .NET SDK:
First let us add the Microsoft package repository

$ wget -O packages-microsoft-prod.deb

$ sudo dpkg -i packages-microsoft-prod.deb

Next let us install the .NET SDK, for that run the following commands in the terminal.

$ sudo apt update
$ sudo apt install -y apt-transport-https
$ sudo apt update
$ sudo apt install -y dotnet-sdk-7.0

Compiling & Execution

Create a New Project:

Enter the following command to create a new project, the last parameter is your Project Name.

$ dotnet new console -n HelloCSharp

You can see a HelloCSharp folder created in your current directory. It will contain a file Program.cs that has a simple Hello World program. You can edit this file to write your own program.
Let us write the following code in the Program.cs file.

using System;  
class Program  
    static void Main()  
        Console.WriteLine("Hello, Ubuntu 22.04!");  

Now save the file.

Compiling the C# program

To compile the C# program, use the following command:

$ dotnet build -o out HelloCSharp.csproj


To execute the C# program, use the following command:

$ ./out/HelloCSharp

After running the program you should see the following output.

$ ./out/HelloCSharp 
Hello, Ubuntu 22.04!

Prabodh C P is a faculty in the Dept of CSE SIT, Tumkur and also currently a Research Scholar pursuing PhD in IIT Hyderabad. He conducts online classes for C, C++, Python. For more info call +919392302100

Leave a Reply

Your email address will not be published. Required fields are marked *