Reputation: 3562
I am trying to install .NET 6 and 7 on my Mac (M1 chip) and after trying several approaches, I am going nowhere.
Option-1: Using brew
/opt/homebrew/Cellar/dotnet/7.0.100
which is good./opt/homebrew/Cellar/dotnet@6/6.0.114
When I run dotnet --list-runtimes
then I only see 7.0.0
.
Microsoft.AspNetCore.App 7.0.0 [/opt/homebrew/Cellar/dotnet/7.0.100/libexec/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.0 [/opt/homebrew/Cellar/dotnet/7.0.100/libexec/shared/Microsoft.NETCore.App]
I get that brew command creates dotnet@6
.
How can I have this with .NET 7
so that I don't run into You must install or update .NET to run this application.
error?
Option-2: Using Install-scripts
.
.NET Runtime 6.0.20
).chmod +x dotnet-install.sh
sudo ./dotnet-install.sh --runtime dotnet --version 6.0.20 --install-dir /opt/homebrew/Cellar/dotnet
sudo ./dotnet-install.sh --runtime aspnetcore --version 6.0.20 --install-dir /opt/homebrew/Cellar/dotnet
dotnet --list-runtimes
again, then it just showed 7.0.0
. Here, I was expecting the above command to create a new folder, like 6.0.20
similar to 7.0.100
but it didn't. All files were directly installed under dotnet
folder.Option-3-Using Installers and SDK and Runtime which installs successfully, but I end up seeing 7.0.0
only.
My end goal is to fix the following error: How to fix this?
You must install or update .NET to run this application.
App: /Users/USERNAME/.dotnet/tools/.store/dotnet-ef/6.0.14/dotnet-ef/6.0.14/tools/net6.0/any/tools/netcoreapp2.0/any/ef.dll
Architecture: arm64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (arm64)
.NET location: /opt/homebrew/Cellar/dotnet/7.0.100/libexec/
The following frameworks were found:
7.0.0 at [/opt/homebrew/Cellar/dotnet/7.0.100/libexec/shared/Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=arm64&rid=osx.13-arm64
Additional Info:
Upvotes: 15
Views: 18753
Reputation: 680
After reading many posts, and nothing working consistently with Homebrew (except for manual zsh
or bash
profile updates, which I left as a final solution), I came up with this:
If you have anything installed so far just uninstall them to start with a clean slate:
curl -O https://raw.githubusercontent.com/dotnet/sdk/main/scripts/obtain/uninstall/dotnet-uninstall-pkgs.sh
chmod u+x dotnet-uninstall-pkgs.sh
sudo ./dotnet-uninstall-pkgs.sh
I wouldn't worry too much about brew installations, because it will nicely manage the versions installed through that.
brew search dotnet
Install the versions you like (in my case 6 & 8) using either of these two methods.
I like this method because it is easier to document and cleaner to understand. And Homebrew will take care of the versions for you automatically.
brew install --cask dotnet-sdk6
brew install --cask dotnet-sdk8
If you like to use the versions directly from the brew search dotnet
result:
brew install --cask dotnet-sdk6-0-400
brew install --cask dotnet-sdk8-0-400
At the end of this step, you will now have the versions you need installed on your Mac.
Let's go ahead and switch to the version you need now. Now the trick I found was the folder naming was not matching what you requested in the versions above. So to find out exactly what Homebrew did:
ls -lad `brew --prefix`/Cellar/dotnet*
In my result it looks like this:
/opt/homebrew/Cellar/dotnet
/opt/homebrew/Cellar/dotnet@6
You might have figured out that version 6 is dotnet@6
and version 8 is dotnet
there.
Now to switch between:
# For v6:
brew unlink dotnet && brew link --overwrite dotnet@6
# For v8:
brew unlink dotnet && brew link --overwrite dotnet
Pre-requisite: Either remove the ./global.json
or make sure the current version in the path matches the one in your ./global.json
file.
Check V6:
> brew unlink dotnet && brew link --overwrite dotnet@6
> dotnet --list-sdks
6.0.133 [/opt/homebrew/Cellar/dotnet@6/6.0.133/libexec/sdk]
> dotnet --version
6.0.133
Check V8:
> brew unlink dotnet && brew link --overwrite dotnet
> dotnet --list-sdks
8.0.104 [/opt/homebrew/Cellar/dotnet/8.0.4/libexec/sdk]
> dotnet --version
8.0.104
Hope this helps.
Upvotes: 3
Reputation: 1
Not sure if this will be useful, but here's a thought I had.
Open .zshrc in your Home directory
add text into your .zshrc:
alias dotnet7="/usr/local/opt/homebrew/Cellar/dotnet/7.0.100/bin/dotnet"
alias dotnet6="/usr/local/opt/homebrew/Cellar/dotnet@6/6.0.114/bin/dotnet"
// For changes in your .zshrc file to take effect, you'll need to restart your terminal session.
Then, you can use either dotnet6 or dotnet7:
dotnet6 new blazorserver -o BlazorApp
It's always worth considering other possibilities. Perhaps someone else has a different approach that might be even more effective.
Upvotes: 0
Reputation: 1377
I'm using homebrew-dotnet-sdk-versions
brew tap isen-ng/dotnet-sdk-versions
brew install --cask dotnet-sdk6-0-400
dotnet --list-sdks
This way multiple versions can be used in parallel.
In your .net code you might need to define which version to use in a file called global.json
in the root folder:
{
"sdk": {
"version": "6.0.412"
}
}
Upvotes: 21
Reputation: 3562
After spending almost a day and half, I think following approach is easiest one which worked for me:
brew uninstall dotnet
Result:
As you can see, /opt/homebrew/Cellar/
is gone now (due to uninstallation) and all .NET versions are coming from user/local/....
path, which is the key. Here, all your future installation will be in this path, so you don't have to worry about it later on.
If you are using .zshrc
file then you can set usr/local/share/dotnet:~/.dotnet/tools:$PATH
for export PATH=
.
Upvotes: 3