For this article, we will use.Net 6.0
Introduction
As we know, .Net 6.0 is built and run application on multiple OSs like Windows, macOS, and Linux. In this article, we will see creating and running a .net project on Ubuntu. As we know, Ubuntu is one of the Linux distributions based on Debian image.
Step 1. So, first we will download the .Net 6.0 SDK, use the below command
sudo apt-get install dotnet-sdk-6.0
If the above command throws an error that the package not found, follow the below commands install dotnet-sdk-6.0
In the home directory, create a dotnet folder and enter into that folder
mkdir ~/.dotnet
cd ~/.dotnet
Run below commands
wget https://download.visualstudio.microsoft.com/download/pr/17b6759f-1af0-41bc-ab12-209ba0377779/e8d02195dbf1434b940e0f05ae086453/dotnet-sdk-6.0.100-linux-x64.tar.gz
tar -xf dotnet-sdk-6.0.100-linux-x64.tar.gz
If you want to keep dotnet-sdk-6.0.100-linux-x64.tar.gz file as backup, you can keep it or else remove this file from the PC.
Step 2. We will set dotnet path in the environment variable so that we will be able to access to dotnet command from the terminal from any location.
Use the below command to set the Path variable
export PATH="$PATH:$HOME/.dotnet"
Step 3. Just to make sure dotnet is installed correctly, type the below command in the terminal. It should print the version of the .Net SDK
dotnet –-version
Step 4. To create a web API project, run the below command in the terminal
dotnet new webapi
Step 5. To build the project, run the below command
dotnet build
While building command required packages will be downloaded automatically from nuget.org. In case of custom artifactory repository you can mention it in NuGet.config file
For this, go to the Users directory,
Check for .nuget directory. If folder is not there, create .nuget directory
mkdir .nuget
Enter into that directory
cd .nuget
Create another folder
mkdir NuGet
Inside that, create file
cat NuGet.Config
And add the below content
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="keyA" value="custom antifactory repo" />
</packageSources>
</configuration>
Then using “dotnet build” command, build the project one more time, so it will download the required package from custom artifactory repo
Step 6. To run the project, run the below command
dotnet run
Summary
I hope this article helps create and run the dotnet project in Ubuntu.