Install and Set Up .NET SDK on Windows, macOS, and Linux
C# is a powerful programming language used in various applications from desktop to mobile development. It is widely used for building full-stack web applications, AI (Artificial Intelligence), Augmented Reality (AR), and Virtual Reality (VR). In this article, we will set up an environment for C# by installing the .NET SDK.
The official recommendation is to use Visual Studio (IDE) for C# development, as it provides comprehensive features. If we install Visual Studio, the .NET SDK is included and does not need to be downloaded separately.
Download and Install and .NET SDK – Windows Operating System
Step 1: Go to the official website and choose the latest .NET SDK version. Here, we are downloading .NET SDK version 9.

Step 2: Go to Downloads and install the dotnet-sdk.exe file as shown in the below image.

Step 3: Click on the Install button and wait until the installation process is completed.

Step 4: After installation, open command prompt and type the below command to verify the .NET SDK version that is installed in the system.
dotnet --version
If installed correctly, it will display the installed .NET SDK version.

Note: The path is automatically set when we install .NET SDK
Step 5: Now open a command prompt and create an empty .NET project using the following command:
dotnet new console -o <Project-Name>
In the <Project-Name> we can provide the name of the project which we want to build in this example as shown below. Here, we use the project name as HelloWorld. This command will create an empty project template with all the necessary packages required to run the .NET project.

This is the complete folder structure which is created using the above command.

The Program.cs is the entry point in this file the C# code is written we can not directly open this file but we can open it in any IDE like Visual Studio or Visual Studio Code this is the default code which is written inside the program.cs file as shown in the below image

This is a simple program we can run it using the following command mentioned in the below steps.
Step 6: Now we need to build the project using the command mentioned below.
Navigate to the project directory:
cd HelloWorld
Build the project using:
dotnet build

Step 7: Now to see the output run the command mentioned below.
dotnet run

This will execute the default Program.cs file and display output in the console.
Note: Navigate to the newly created project directory using cd <Project-Name> before running dotnet build or dotnet run.
Download and Install .NET SDK - macOS
Step 1: Go to the official website. The website will automatically detect the operating system and then click on Download for macOS.
Step 2: Then go to Downloads and find the dotnet.pkg file and double-click to install it. Then follow the installation instructions.
Step 3: Verify that it is installed correcting by checking the version using the below command on the terminal:
dotnet --version
If it is correctly installed then it shows the version which we download.
Alternative Installation via Homebrew
You can also install .NET SDK using Homebrew:
brew install dotnet-sdk
If necessary, add the .NET CLI tools to your system PATH:
echo 'export PATH="/usr/local/share/dotnet:$PATH"' >> ~/.zshrc
source ~/.zshrc
Download and Install .NET SDK - Linux (Ubuntu)
Step 1: Go to the official website and choose the distribution which we are using. Also, check the compatible version.
Here, we are downloading and installing .NET SDK for ubuntu.
Before installing, update package lists and add Microsoft’s repository:
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
Step 2: Now install the .NET SDK using the below command:
sudo apt-get install -y dotnet-sdk-9.0
Step 3: If you plan to run web applications, install the ASP.NET Core Runtime. This step is optional.
sudo apt-get install -y aspnetcore-runtime-9.0
Step 4: Now verify the installation by using the commanding the terminal which checks the version of the current .NET SDK on the system.
dotnet --version
If the installation is completed successfully then it shows the current version of dotnet.