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.debInstall the downloaded key by using –
sudo dpkg -i packages-microsoft-prod.debOnce it gets added to the list of trusted keys, use the following command to remove the downloaded key –
rm packages-microsoft-prod.debInstalling .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 updateNext, run the given command to install some prerequisite packages on your system –
sudo apt install -y apt-transport-httpsFinally, use the given command to install .NET SDK on your system –
sudo apt install -y dotnet-sdk-6.0Run C# hello world program
First, use the given command to create a dotnet project –
dotnet new console -o testAppMove to the project directory –
cd testAppUse an editor and edit the Program.cs file –
nano Program.csEdit the file content as given below, Here you can add whatever you want press ctrl+s to save and ctrl+x to exit –
Console.WriteLine("Hello, World!");![]()
Run this code at runtime –
dotnet run![]()
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.
Conclusion
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.