How to install multiple dotnet versions using brew?
Asked Answered
N

4

9

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

  • Installed .NET 7. Here, I see successful installation under /opt/homebrew/Cellar/dotnet/7.0.100 which is good.
  • Installed .NET 6. This is installed under /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.

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

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:

enter image description here

enter image description here

Newmown answered 17/7, 2023 at 15:33 Comment(0)
D
15

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"
  }
}
Disown answered 19/7, 2023 at 8:20 Comment(0)
N
3

After spending almost a day and half, I think following approach is easiest one which worked for me:

  • Delete .NET installed via Brew by running brew uninstall dotnet
  • I would recommend delete all .NET by using .NET uninstall tool and do fresh installation.
  • Use Microsoft installer for respected .NET version. i.e., This is for .NET 7
    • If you are using a Mac with M1 chip, then use ARM64. For intel, you can use X64.

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.

enter image description here

If you are using .zshrc file then you can set usr/local/share/dotnet:~/.dotnet/tools:$PATH for export PATH=.

Newmown answered 17/7, 2023 at 18:30 Comment(2)
This does not solve it using brew though. I do not want to install it using MS installer (same as the person who asked the question)Orlandoorlanta
@Orlandoorlanta it was me who asked (and added the answer). I do not want to use brew for this, so went with this route.Newmown
S
0

Not sure if this will be useful, but here's a thought I had.

Finder & text editor

  1. Open .zshrc in your Home directory

  2. 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.

  3. Then, you can use either dotnet6 or dotnet7:

    dotnet6 new blazorserver -o BlazorApp

  4. It's always worth considering other possibilities. Perhaps someone else has a different approach that might be even more effective.

Subsocial answered 16/2, 2024 at 9:45 Comment(2)
This will end up in creating multiple aliases which I want to avoid.Newmown
You right! sorry about that.Subsocial
S
0

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:

Cleanup

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.

Find available versions

brew search dotnet

Install the versions you need

Install the versions you like (in my case 6 & 8) using either of these two methods.

Method 1:

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
Method 2:

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.

Switching between versions

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

Check installation

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.

Spiegel answered 7/9, 2024 at 2:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.