Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install multiple dotnet versions using brew?

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.

  • I installed dotnet-install scripts from here (chose .NET Runtime 6.0.20).
  • Then ran following commands
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
  • When I ran 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.
  • Reference, https://danielhilton.medium.com/how-to-install-multiple-asp-net-core-runtimes-in-macos-717e8d0176ea

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

like image 311
GThree Avatar asked Nov 20 '25 11:11

GThree


2 Answers

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"
  }
}
like image 167
cwillinx Avatar answered Nov 23 '25 03:11

cwillinx


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

like image 28
GThree Avatar answered Nov 23 '25 03:11

GThree