'A fatal error occurred. The required library libhostfxr.dylib could not be found

I'm working on ASP.NET Project with .NET 5.0. For Database creation, I've run the command

dotnet tool install --global dotnet-ef

After the installing, when I run this command:

dotnet ef

I got that error

A fatal error occurred. The required library libhostfxr.dylib could not be found. If this is a self-contained application, that library should exist in [/Users/afshalathar/.dotnet/tools/.store/dotnet-ef/6.0.0/dotnet-ef/6.0.0/tools/netcoreapp3.1/any/]. If this is a framework-dependent application, install the runtime in the global location [/usr/local/share/dotnet/x64] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].

The .NET runtime can be found at:

I'm using Mac M1



Solution 1:[1]

As mentioned here, first uninstall dotnet-ef and then reinstall it using the -a arm64 option:

dotnet tool uninstall dotnet-ef --global  
dotnet tool install dotnet-ef --global -a arm64

This worked for me.

Solution 2:[2]

Late to the party, but I had the same issue on a M1 Macbook. Strangely enough, the following steps worked for me:

  1. sudo dotnet tool uninstall dotnet-ef --global
  2. dotnet tool update --global dotnet-ef

Solution 3:[3]

Try installing EF tool locally

CD to your source directory and do this:

dotnet new tool-manifest
dotnet tool install  dotnet-ef

In this way, it works even with the .Net 5/6 arm64.

There's a bug in the arm64 tool installer that references the x64 version.

Solution 4:[4]

I was quite desperate with this bug until I found https://developercommunity.visualstudio.com/t/libhostfxrdylib-not-signed/909971.

I could resolve the libhostfxr.dylib error when calling dotnet ef command. By simply fully updating my Visual Studio for Mac.

Problem: Some code signing issue with this file and macOS just moves it to some kind of quarantine (as far as I understood)

Solution: Open Visual Studio for Mac and install all the updates.

I first found the link on developercommunity and then thought it might just work and it really did.

If this helped you, you too might just be hooked to Jetbrains Rider. But installing dotnet via Rider does not fix the problem and also installing this extension https://plugins.jetbrains.com/plugin/18147-entity-framework-core-ui did NOT resolve it.

If you don't mind having Visual Studio for Mac also on your machine it's worth a shot.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martinaut
Solution 2 Andrii Stashko
Solution 3
Solution 4 CodingYourLife