.NET Installation Guide
.NET is a free, cross-platform, open-source developer platform for building many types of applications. This guide covers installing the .NET SDK on Windows 11, macOS, and Linux.
.NET® is a trademark of Microsoft Corporation. All trademarks and logos are used for representation purposes only. No prior copyright or trademark authorization has been obtained. This documentation is for educational purposes only.
.NET Versions
| Version | Release Date | Support | End of Support |
|---|---|---|---|
| .NET 8 | November 2023 | LTS | November 2026 |
| .NET 7 | November 2022 | STS | May 2024 |
| .NET 6 | November 2021 | LTS | November 2024 |
Recommendation: Use .NET 8 (LTS) for new projects.
.NET SDK vs Runtime
- SDK: Includes everything to build and run .NET apps (development)
- Runtime: Only includes what's needed to run .NET apps (production)
For development, always install the SDK.
Windows 11 Installation
Method 1: Official Installer (Recommended)
# Download from https://dotnet.microsoft.com/download
# Choose .NET 8.0 SDK
# Or using winget
winget install Microsoft.DotNet.SDK.8
# Install specific version
winget install Microsoft.DotNet.SDK.7
# Verify installation
dotnet --version
dotnet --list-sdks
dotnet --list-runtimes
Method 2: Chocolatey
# Install .NET SDK
choco install dotnet-sdk
# Or specific version
choco install dotnet-8.0-sdk
choco install dotnet-7.0-sdk
# Verify
dotnet --version
Method 3: Visual Studio Installer
- Download Visual Studio 2022 (Community, Professional, or Enterprise)
- During installation, select ".NET desktop development" workload
- .NET SDK is included automatically
Method 4: Script Installation
# Download and run install script
Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
# Install latest SDK
.\dotnet-install.ps1 -Channel 8.0
# Install specific version
.\dotnet-install.ps1 -Version 8.0.100
# Install to custom location
.\dotnet-install.ps1 -InstallDir "C:\Program Files\dotnet"
# Verify
dotnet --version
Post-Installation (Windows)
# Verify PATH (should include C:\Program Files\dotnet)
echo $env:PATH
# If not in PATH, add it
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\dotnet", "Machine")
# Verify all installations
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes
macOS Installation
Method 1: Official Installer (PKG)
# Download from https://dotnet.microsoft.com/download
# Choose .NET 8.0 SDK for macOS
# Download and install .pkg file
# Follow installer prompts
# Verify
dotnet --version
Method 2: Homebrew
# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install .NET SDK
brew install --cask dotnet-sdk
# Or specific version
brew install --cask dotnet-sdk@8
brew install --cask dotnet-sdk@7
# Verify
dotnet --version
dotnet --list-sdks
Method 3: Script Installation
# Download install script
curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh
chmod +x dotnet-install.sh
# Install latest SDK
./dotnet-install.sh --channel 8.0
# Install specific version
./dotnet-install.sh --version 8.0.100
# Install to custom directory
./dotnet-install.sh --install-dir ~/.dotnet
# Add to PATH (if custom directory)
export PATH=$HOME/.dotnet:$PATH
echo 'export PATH=$HOME/.dotnet:$PATH' >> ~/.zshrc
# Verify
dotnet --version
Post-Installation (macOS)
# Verify PATH
echo $PATH | grep dotnet
# If not in PATH, add to ~/.zshrc or ~/.bash_profile
export PATH="/usr/local/share/dotnet:$PATH"
# Reload shell
source ~/.zshrc
# Verify all installations
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes
Linux Installation
Method 1: Package Manager (Ubuntu 22.04/24.04)
# Add Microsoft package repository
wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
# Update package list
sudo apt-get update
# Install .NET SDK 8
sudo apt-get install -y dotnet-sdk-8.0
# Or install .NET SDK 7
sudo apt-get install -y dotnet-sdk-7.0
# Verify
dotnet --version
dotnet --list-sdks
Method 2: Package Manager (Debian)
# Add Microsoft package repository
wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
# Update and install
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
# Verify
dotnet --version
Method 3: Package Manager (RHEL/CentOS/Fedora)
# Add Microsoft package repository (RHEL 9)
sudo dnf install -y https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm
# Install .NET SDK
sudo dnf install -y dotnet-sdk-8.0
# For Fedora
sudo dnf install -y dotnet-sdk-8.0
# Verify
dotnet --version
Method 4: Package Manager (Arch Linux)
# Install from official repositories
sudo pacman -S dotnet-sdk
# Or from AUR
yay -S dotnet-sdk-8.0
# Verify
dotnet --version
Method 5: Snap (Universal)
# Install .NET SDK using Snap
sudo snap install dotnet-sdk --classic --channel=8.0
# Set up alias
sudo snap alias dotnet-sdk.dotnet dotnet
# Verify
dotnet --version
Method 6: Script Installation (All Linux)
# Download install script
curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh
chmod +x dotnet-install.sh
# Install latest SDK
./dotnet-install.sh --channel 8.0
# Install to custom directory
./dotnet-install.sh --install-dir ~/.dotnet
# Add to PATH (~/.bashrc or ~/.zshrc)
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$DOTNET_ROOT:$PATH
# Reload shell
source ~/.bashrc
# Verify
dotnet --version
Post-Installation (Linux)
# Verify PATH
echo $PATH | grep dotnet
# If not in PATH, add to ~/.bashrc
export DOTNET_ROOT=/usr/share/dotnet
export PATH=$DOTNET_ROOT:$PATH
# Reload
source ~/.bashrc
# Verify all installations
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes
# Enable bash completion (optional)
echo 'eval "$(dotnet suggest shell bash)"' >> ~/.bashrc
source ~/.bashrc
Managing Multiple .NET Versions
Install Multiple SDKs
# Windows
winget install Microsoft.DotNet.SDK.8
winget install Microsoft.DotNet.SDK.7
winget install Microsoft.DotNet.SDK.6
# Linux (Ubuntu)
sudo apt-get install -y dotnet-sdk-8.0 dotnet-sdk-7.0 dotnet-sdk-6.0
# macOS
brew install --cask dotnet-sdk@8
brew install --cask dotnet-sdk@7
# Verify all installed SDKs
dotnet --list-sdks
global.json for Project-Specific Version
Create global.json in project root:
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
Options for rollForward:
"disable": Exact version match required"patch": Allow patch version updates"feature": Allow feature updates"minor": Allow minor version updates"major": Allow major version updates"latestPatch": Use latest patch"latestFeature": Use latest feature"latestMinor": Use latest minor (default)"latestMajor": Use latest major
# Create global.json
dotnet new globaljson --sdk-version 8.0.100
# Verify which SDK is used
dotnet --version
Verification & Testing
Basic Commands
# Check .NET version
dotnet --version
# List installed SDKs
dotnet --list-sdks
# List installed runtimes
dotnet --list-runtimes
# Display .NET info
dotnet --info
# Check for updates
dotnet sdk check
Create and Run Test Application
# Create new console app
dotnet new console -n HelloDotNet
cd HelloDotNet
# View Program.cs
cat Program.cs
# Run the app
dotnet run
# Build the app
dotnet build
# Clean build artifacts
dotnet clean
Create Different Project Types
# Console Application
dotnet new console -n MyConsoleApp
# Web API
dotnet new webapi -n MyWebApi
# MVC Web App
dotnet new mvc -n MyWebApp
# Blazor WebAssembly
dotnet new blazorwasm -n MyBlazorApp
# Class Library
dotnet new classlib -n MyLibrary
# xUnit Test Project
dotnet new xunit -n MyTests
# List all templates
dotnet new list
Test Web API
# Create Web API
dotnet new webapi -n TestApi
cd TestApi
# Run the API
dotnet run
# In another terminal, test the API
curl http://localhost:5000/weatherforecast
# Or open in browser
# http://localhost:5000/swagger
NuGet Package Management
Basic NuGet Commands
# Add package to project
dotnet add package Newtonsoft.Json
# Add specific version
dotnet add package Newtonsoft.Json --version 13.0.3
# Remove package
dotnet remove package Newtonsoft.Json
# List packages in project
dotnet list package
# Restore packages
dotnet restore
# Clear NuGet cache
dotnet nuget locals all --clear
Configure NuGet Sources
# List NuGet sources
dotnet nuget list source
# Add custom source
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
# Remove source
dotnet nuget remove source nuget.org
# Enable/Disable source
dotnet nuget enable source nuget.org
dotnet nuget disable source nuget.org
Entity Framework Core
Install EF Core Tools
# Install globally
dotnet tool install --global dotnet-ef
# Update to latest
dotnet tool update --global dotnet-ef
# Verify
dotnet ef --version
# Add to project
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
# or
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
Common EF Core Commands
# Create migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database update
# Remove last migration
dotnet ef migrations remove
# Generate SQL script
dotnet ef migrations script
# Drop database
dotnet ef database drop
ASP.NET Core Development
Install Developer Certificate
# Generate and trust HTTPS certificate
dotnet dev-certs https --trust
# Clean and regenerate
dotnet dev-certs https --clean
dotnet dev-certs https --trust
# Check certificate
dotnet dev-certs https --check
User Secrets (Development)
# Initialize user secrets
dotnet user-secrets init
# Set secret
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Server=localhost;Database=mydb"
# List secrets
dotnet user-secrets list
# Remove secret
dotnet user-secrets remove "ConnectionStrings:DefaultConnection"
# Clear all secrets
dotnet user-secrets clear
.NET Tools
Install Global Tools
# Install popular tools
dotnet tool install --global dotnet-ef
dotnet tool install --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-outdated-tool
dotnet tool install --global dotnet-format
# List installed tools
dotnet tool list --global
# Update tool
dotnet tool update --global dotnet-ef
# Uninstall tool
dotnet tool uninstall --global dotnet-ef
Useful Global Tools
# Check for outdated packages
dotnet tool install --global dotnet-outdated-tool
dotnet outdated
# Code formatting
dotnet tool install --global dotnet-format
dotnet format
# Report generator for test coverage
dotnet tool install --global dotnet-reportgenerator-globaltool
Common Issues & Solutions
Issue: Command 'dotnet' not found
# Verify installation
which dotnet # Unix/macOS
where.exe dotnet # Windows
# Add to PATH
# Linux/macOS (~/.bashrc or ~/.zshrc)
export PATH=$PATH:/usr/share/dotnet
# Windows (PowerShell as Admin)
$env:PATH += ";C:\Program Files\dotnet"
Issue: Multiple SDK Versions Conflict
# Create global.json to specify version
dotnet new globaljson --sdk-version 8.0.100
# Check which SDK is being used
dotnet --version
Issue: SSL/Certificate Issues
# Trust developer certificate
dotnet dev-certs https --clean
dotnet dev-certs https --trust
# For Linux, may need to set environment variable
export DOTNET_SSL_CERT_VERIFY=false
Issue: Package Restore Failures
# Clear NuGet cache
dotnet nuget locals all --clear
# Restore packages
dotnet restore
# Try with verbose logging
dotnet restore --verbosity detailed
Issue: Port Already in Use
# Kill process using port (Linux/macOS)
lsof -ti:5000 | xargs kill -9
# Or specify different port
dotnet run --urls "http://localhost:5001"
# Or in launchSettings.json
Development Environment Setup
Visual Studio Code
# Install VS Code
# Download from https://code.visualstudio.com/
# Install C# extension
code --install-extension ms-dotnettools.csharp
# Install C# Dev Kit
code --install-extension ms-dotnettools.csdevkit
# Other useful extensions
code --install-extension ms-dotnettools.vscode-dotnet-runtime
code --install-extension formulahendry.dotnet-test-explorer
Visual Studio 2022 (Windows/Mac)
- Windows: Download from https://visualstudio.microsoft.com/
- Mac: Download Visual Studio for Mac
JetBrains Rider
- Cross-platform .NET IDE
- Download from https://www.jetbrains.com/rider/
Best Practices
✅ Use LTS versions (.NET 8) for production
✅ Keep SDK updated for security and features
✅ Use global.json to pin SDK version per project
✅ Enable nullable reference types in new projects
✅ Use async/await for I/O operations
✅ Implement logging with ILogger
✅ Use dependency injection built into ASP.NET Core
✅ Write unit tests with xUnit or NUnit
Project Configuration
.NET 8 Project File Example
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-MyApp-guid</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
Next Steps
✅ .NET Installed Successfully!
Continue learning: