Score:0

dotnet new console not working [Ubuntu 23.04]

pe flag

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)?

Score:1
in flag

The solution to this problem was explained here: https://github.com/dotnet/sdk/issues/32804. To quickly summarize, Canonical recently released the official dotnet package, removing MS source.list (or commenting out deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/23.04/prod lunar main ) and installing dotnet* solves the problem:

$ sudo apt-get purge dotnet-sdk-7.0
$ sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list && sudo apt update
$ sudo apt install -y dotnet7
$ dotnet --info
.NET SDKs installed:
  7.0.110 [/usr/lib/dotnet/sdk]

If you still want to use dotnet-sdk-7.0 sourced from packages.microsoft.com, the priority of the package needs to be increased (haven't tried this solution myself, but it makes sense):

echo -e "Package: *\nPin: origin packages.microsoft.com\nPin-Priority: 1001" > /etc/apt/preferences.d/dotnet
Score:0
jp flag

You're not installing the SDKs. You get no results when you run dotnet --list-sdks, which hints that you're only installing the runtimes.

I recommend installing the SDKs using the install.sh file on https://dot.net and then ensuring the install directories are in your path. Which it seems you are doing.

You might need to restart your terminal and try again. Sometimes the .bashrc isn't reloaded.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.