I am trying to install .NET SDK to use with VS Code.
When I type dotnet new console
the following is returned:
The command could not be loaded, possibly because:
* You intended to execute a .NET application:
The application 'new' does not exist.
* You intended to execute a .NET SDK command:
No .NET SDKs were found.
Download a .NET SDK:
https://aka.ms/dotnet/download
Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
Typing dotnet --version
also returns the error above.
On the other hand dotnet --version
does not list anything.
I followed various sites to try to install the sdk How to Install .NET Core (dotnet) on Ubuntu 22.04 and C#(Dotnet) Setup in Ubuntu with VSCode without success.
Update: I followed the page at Install .NET SDK or .NET Runtime on Ubuntu 23.04. Below is the output of the commands on this site:
hadmin@hp-linux:~$ dotnet --list-sdks
hadmin@hp-linux:~$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.16 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.16 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
hadmin@hp-linux:~$ wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
--2023-05-25 17:55:54-- https://dot.net/v1/dotnet-install.sh
Resolving dot.net (dot.net)... 20.81.111.85, 20.53.203.50, 20.112.52.29, ...
Connecting to dot.net (dot.net)|20.81.111.85|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh [following]
--2023-05-25 17:55:54-- https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh
Resolving dotnet.microsoft.com (dotnet.microsoft.com)... 13.107.238.64, 13.107.237.64, 2620:1ec:4f:1::64, ...
Connecting to dotnet.microsoft.com (dotnet.microsoft.com)|13.107.238.64|:443... connected.
HTTP request sent, awaiting response... 200 OK
Cookie coming from dotnet.microsoft.com attempted to set domain to dotnetwebsite.azurewebsites.net
Cookie coming from dotnet.microsoft.com attempted to set domain to dotnetwebsite.azurewebsites.net
Length: 58824 (57K) [application/x-sh]
Saving to: ‘dotnet-install.sh’
dotnet-install.sh 100%[=========================>] 57.45K --.-KB/s in 0.01s
2023-05-25 17:55:54 (5.56 MB/s) - ‘dotnet-install.sh’ saved [58824/58824]
hadmin@hp-linux:~$ sudo chmod +x ./dotnet-install.sh
hadmin@hp-linux:~$ ./dotnet-install.sh --version latest
dotnet-install: .NET Core SDK with version '6.0.408' is already installed.
hadmin@hp-linux:~$ ./dotnet-install.sh --version latest --runtime aspnetcore
dotnet-install: ASP.NET Core Runtime with version '6.0.16' is already installed.
hadmin@hp-linux:~$ ./dotnet-install.sh --channel 7.0
dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.302/dotnet-sdk-7.0.302-linux-x64.tar.gz
dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.302/dotnet-sdk-7.0.302-linux-x64.tar.gz
dotnet-install: Installed version is 7.0.302
dotnet-install: Adding to current process PATH: `/home/hadmin/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
dotnet-install: Installation finished successfully.
hadmin@hp-linux:~$ dotnet --list-sdks
hadmin@hp-linux:~$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.16 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.16 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
hadmin@hp-linux:~$
Update following comment from @Khalid
hadmin@hp-linux:~$ env | grep DOTNET_ROOT
DOTNET_ROOT=/usr/lib/dotnet
hadmin@hp-linux:~$ ls /usr/lib/dotnet/
dotnet host LICENSE.txt packs shared ThirdPartyNotices.txt
hadmin@hp-linux:~$ ls $HOME/.dotnet/
corefx host packs sdk-manifests templates
dotnet LICENSE.txt sdk shared ThirdPartyNotices.txt
The environment variable is pointing to the wrong directory.
I would like to clean the installation including the multiple installations and set the environment variable to point to the correct folder.
How can I do that please (which file holds the .NET environment variables)?