.NET development on Linux Ubuntu

.NET development on Linux Ubuntu

Develop .NET Applications on Linux Ubuntu OS

These are steps to take if you want to start .NET development on Ubuntu Linux

Over the years .NET has evolved immensely and has had different changes but one of the most notable is the .NET Core.

Prior to then, the .NET Framework has only supported development on Microsoft's OS ~Windows~ and Visual Studio as the primary development tool. Thanks to the .NET team you can now develop scalable and powerful .NET applications using Linux Ubuntu

If you work with Ubuntu and will love to develop and deploy .NET applications here is what you should do.

image.png

Download the .NET SDK

This is the backbone of the backbone that supports any .NET application and enables them to run. Conventionally this is done by downloading the .NET SDK and installing it as an executable. But for Ubuntu you might have to use the terminal.

  • Open your terminal.

You can do this by searching using "terminal" as keyword on your Ubuntu machine something like the below should pop up.

Screenshot from 2021-04-24 10-26-34.png

Select the terminal and paste in the following commands you can use Ctrl + Shift + V to paste in the terminal and press enter after each command.

wget https://packages.microsoft.com/config/ubuntu/20.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
  • Install the SDK

Paste the following commands to the terminal to install the runtime. If you install the SDK, you do not need to install the runtime as it is installed alongside the SDK.

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

To install later versions of the .NET SDK you can use

For version 3.1

 sudo apt-get install -y dotnet-sdk-3.1
  • Check if .NET is installed

Be sure to check if the installation was successful. To check if .NET is installed use the following command

dotnet
dotnet --version

Group 46.png

Group 46 (1).png

Download an IDE Text-Editor

Just like for any development, there is need for an environment to enable you write the actual code.

There are a ton of them out there. Sublime, Atom, Visual Studio Code. e.t.c I will advice VSCode.

There are various ways to do this but I will advice using snap install.

  • First you do a routine update of your linux packages by pasting this on your terminal
sudo apt update
sudo apt install snapd
  • Then install using snap
sudo snap install code --classic

Install .NET dependencies and extensions for VS Code

To start development on VSCode you will need to install the following extensions.

  • C# ms-dotnettools.csharp After opening VSCode on your ubuntu machine.

At the left hand side of the IDE

Screenshot from 2021-04-24 11-42-46.png

  • You should see the MarketPlace or Extensions Icon

Screenshot from 2021-04-24 11-43-04.png

  • Search for C#

Screenshot from 2021-04-24 11-43-19.png

  • Install if you have not.

You should have the omnisharp installed alongside that.

Create a dotnet application

  • Open a directory on your terminal and run the following commands
dotnet new mvc -o NameOfApp

This command will enable you create a new dotnet application using ASP.NETCore MVC, a lightweight, open source framework for building powerful and scalable web applications. To know about the list of applications you can build you can use the command dotnet new

You can also build powerful console applications using the command

dotnet new console -o NameOfApp
  • Navigate to the directory using cd NameOfApp

Then use the command

dotnet run

to run the application .

You can access the MVC application by following the localhost URL on the terminal on any browser of choice.

Screenshot from 2021-04-24 12-41-35.png

Voila!!! now you are ready

image.png

If you want more on .NET development on Ubuntu let me know in the comments