C# is a general-purpose, strongly typed, multiparadigm programming language which is developed by Microsoft. It is used to develop web apps, desktop apps, mobile apps, etc.
In this article, I will discuss how to install and use the C# programming language in Ubuntu Linux.
How to install .NET SDK or .NET runtime on Ubuntu
To run programs or applications developed in C# you need to have the .NET SDK (which includes runtime) or .NET runtime installed on your system.
Now follow the steps that are given below to install .NET SDK and run the programs written in C# on your Ubuntu system.
Add Microsoft package signing key
First, use the given command to download the Microsoft package signing key –
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
Install the downloaded key by using –
sudo dpkg -i packages-microsoft-prod.deb
Once it gets added to the list of trusted keys, use the following command to remove the downloaded key –
Installing .NET SDK on Ubuntu
.NET SDK allows you to develop the .NET apps it also includes libraries and runtime for many programming languages. To install it on your system first run the given command to make sure the package repository is updated –
sudo apt update
Next, run the given command to install some prerequisite packages on your system –
sudo apt install -y apt-transport-https
Finally, use the given command to install .NET SDK on your system –
sudo apt install -y dotnet-sdk-6.0
Run C# hello world program
First, use the given command to create a dotnet project –
dotnet new console -o testApp
Move to the project directory –
Use an editor and edit the Program.cs file –
Edit the file content as given below, Here you can add whatever you want press ctrl+s to save and ctrl+x to exit –
Run this code at runtime –
As you can see the output in the above image.
Another way to run the C# program on Ubuntu is to install Mono on your system.
So now we hope you have successfully installed the .NET runtime and are able to run C# programs and applications on your Ubuntu system.
Now if you have a query or feedback then write us in the comments below.