No articles found
Try different keywords or browse our categories
Fix: dotnet command not found error C#
Complete guide to fix 'dotnet command not found' error in C#. Learn how to install and configure .NET SDK for command line usage.
The ‘dotnet command not found’ error occurs when the .NET SDK is installed but the dotnet command is not accessible from the command line, typically due to PATH configuration issues.
How the Error Happens
This error typically occurs when:
- .NET SDK is installed but not added to PATH
- Terminal/shell was opened before SDK installation
- PATH environment variable is misconfigured
- Wrong installation directory
- Multiple conflicting installations
Solution 1: Verify .NET SDK Installation
# ❌ This shows the error
dotnet --version
# Output: bash: dotnet: command not found (Linux/Mac) or 'dotnet' is not recognized (Windows)
# ✅ First, verify if .NET SDK is actually installed
# Windows:
dir "C:\Program Files\dotnet" /s
# macOS:
ls -la /usr/local/share/dotnet/
# Linux:
ls -la /usr/share/dotnet/
Solution 2: Add .NET to PATH (Windows)
# ✅ Check current PATH
echo %PATH%
# ✅ Add to PATH via Command Prompt (temporary)
set PATH=%PATH%;C:\Program Files\dotnet\
# ✅ Add to PATH permanently via Command Prompt
setx PATH "%PATH%;C:\Program Files\dotnet\" /M
# ✅ PowerShell method to add to PATH
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
$newPath = $currentPath + ";C:\Program Files\dotnet\"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
# ✅ Or add to user PATH
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$userPath += ";C:\Program Files\dotnet\"
[Environment]::SetEnvironmentVariable("PATH", $userPath, "User")
# ✅ Alternative: Use System Properties
# 1. Press Win+R, type "sysdm.cpl"
# 2. Go to Advanced tab
# 3. Click Environment Variables
# 4. Under System Variables, find "Path"
# 5. Click Edit > New > Add "C:\Program Files\dotnet\"
Solution 3: Add .NET to PATH (macOS/Linux)
# ✅ Check current PATH
echo $PATH
# ✅ Add to PATH in bash profile (permanent)
echo 'export PATH=$PATH:/usr/local/share/dotnet' >> ~/.bashrc
source ~/.bashrc
# ✅ For zsh users
echo 'export PATH=$PATH:/usr/local/share/dotnet' >> ~/.zshrc
source ~/.zshrc
# ✅ For fish shell users
echo 'set -gx PATH $PATH /usr/local/share/dotnet' >> ~/.config/fish/config.fish
# ✅ Create symbolic link (Linux/macOS)
sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/dotnet
# ✅ Or copy to bin directory
sudo cp /usr/local/share/dotnet/dotnet /usr/local/bin/
Solution 4: Restart Terminal/Shell
# ✅ Close and reopen terminal after PATH changes
# Or restart shell session:
# For bash:
exec bash
# For zsh:
exec zsh
# For PowerShell:
# Close and reopen PowerShell as Administrator
Solution 5: Use Full Path as Temporary Workaround
# ✅ Use full path to dotnet executable
# Windows:
"C:\Program Files\dotnet\dotnet.exe" --version
# macOS/Linux:
/usr/local/share/dotnet/dotnet --version
# ✅ Create alias for convenience
# Add to ~/.bashrc or ~/.zshrc:
alias dotnet="/usr/local/share/dotnet/dotnet"
Solution 6: Verify Installation Location
# ✅ Find where dotnet is installed
# Windows:
where /r C:\ dotnet.exe
# macOS/Linux:
which dotnet
find / -name dotnet 2>/dev/null
# ✅ Check common installation directories:
# Windows: C:\Program Files\dotnet\
# macOS: /usr/local/share/dotnet/, /opt/dotnet/
# Linux: /usr/share/dotnet/, /usr/local/share/dotnet/
Solution 7: Reinstall .NET SDK
# ✅ Download and reinstall .NET SDK
# Visit: https://dotnet.microsoft.com/download
# ✅ Or use package managers:
# Windows (Chocolatey):
choco uninstall dotnet-sdk
choco install dotnet-sdk
# macOS (Homebrew):
brew uninstall --cask dotnet-sdk
brew install --cask dotnet-sdk
# Linux (Ubuntu/Debian):
sudo apt remove dotnet-sdk-8.0
# Follow fresh installation steps
Solution 8: Use .NET Install Script
# ✅ Use official installation script (Linux/macOS)
curl -sSL https://dot.net/v1/dotnet-install.sh | sudo bash /dev/stdin -c LTS --install-dir /usr/share/dotnet
# ✅ For PowerShell (Windows):
Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
.\dotnet-install.ps1 -Channel LTS -InstallDir 'C:\Program Files\dotnet'
Solution 9: IDE-Specific Fixes
// ✅ VS Code settings.json
{
"omnisharp.dotnetPath": "/usr/local/share/dotnet", // Linux/macOS
// OR
"omnisharp.dotnetPath": "C:\\Program Files\\dotnet" // Windows
}
# ✅ Visual Studio Developer Command Prompt
# Use Visual Studio Developer Command Prompt instead of regular command prompt
# This automatically sets up the PATH
Solution 10: Docker and Container Solutions
# ✅ Use .NET SDK in Docker
FROM mcr.microsoft.com/dotnet/sdk:8.0
# dotnet command is available in this image
# ✅ Use .NET in container without local installation
docker run -it mcr.microsoft.com/dotnet/sdk:8.0 dotnet --version
Verification Steps
# ✅ After applying fixes, verify:
dotnet --version
dotnet --info
dotnet help
# ✅ Create and run a test project:
dotnet new console -n TestApp
cd TestApp
dotnet run
cd .. && rm -rf TestApp
# ✅ PowerShell verification script:
try {
$version = dotnet --version
Write-Host "✅ .NET SDK version: $version" -ForegroundColor Green
Write-Host "✅ dotnet command is working!" -ForegroundColor Green
} catch {
Write-Host "❌ dotnet command still not found" -ForegroundColor Red
}
Common Causes and Prevention
- PATH not updated: Manually add .NET installation directory to PATH
- Terminal not restarted: Close and reopen terminal after installation
- Wrong architecture: Install correct x64/x86 version
- Incomplete installation: Reinstall if installation was interrupted
- Multiple installations: Remove conflicting installations
- Permission issues: Install with appropriate permissions
Best Practices
- Always restart terminal after installing .NET SDK
- Use official Microsoft installation methods
- Keep PATH clean and organized
- Document installation paths for troubleshooting
- Use global.json for version consistency
- Test installation with basic commands
- Check for multiple SDK installations
- Verify both user and system PATH variables
Related Articles
Fix: .NET SDK not found C# error
Complete guide to fix '.NET SDK not found' error in C#. Learn how to install, configure, and troubleshoot .NET SDK installations.
Fix: BadImageFormatException C# error
Complete guide to fix BadImageFormatException in C#. Learn how to resolve assembly architecture and format compatibility issues in .NET applications.
Fix: System.IO.IOException C# error
Complete guide to fix System.IO.IOException in C#. Learn how to handle file access, network, and I/O operation errors in .NET applications.