dotnet: command not found in Mac
Macos.Net CoreMacos Problem Overview
So I downloaded NET Core 2.1 SDK for mac and installed it. But when I run the dotnet
command from terminal it throws -bash: dotnet: command not found
error.
I am trying to use the dotnet new react
to spin up a new .Net Core/React project.
How can I fix this? Thanks!
Macos Solutions
Solution 1 - Macos
Make sure your macOS version meets the prerequisites
https://docs.microsoft.com/en-us/dotnet/core/macos-prerequisites?tabs=netcore2x
If it does, then after installing via the installer, in a new terminal run this command
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
Then try dotnet --version
hopefully that should work
EDIT:
You might need to add x64
like so:
ln -s /usr/local/share/dotnet/x64/dotnet /usr/local/bin/
Courtesy of Stan in the comments
Solution 2 - Macos
For Mac M1
sudo ln -s /usr/local/share/dotnet/x64/dotnet /usr/local/bin/
If you add symbolic link to /usr/local/bin/ but you get file exist error.
You can delete the dotnet file at /usr/local/bin/
or
at you finder Shift + ⌘ Command + G and type /usr/local/bin/ , delete the dotnet file in finder.
Solution 3 - Macos
Just another way how to successfully install dotnet on a Mac: using Homebrew, you can simply run:
brew install dotnet
to have it install. Advantages include automatic updates via brew upgrade
and less to worry about permissions or any of the workarounds mentioned as solutions before me.
You can find the formula information here: https://formulae.brew.sh/formula/dotnet
Solution 4 - Macos
If you are using the dotnet x64 installer for mac which can be found here , use this command
sudo su
ln -s /usr/local/share/dotnet/x64/dotnet /usr/local/bin/
Solution 5 - Macos
Run sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
in the command line, you then should be prompted for your password. This is the solution that worked for me on Mac OS Catalina.
Solution 6 - Macos
I solved by editing ~/.zshrc
#Add .NET to $PATH
export PATH="/usr/local/share/dotnet:$PATH"
Solution 7 - Macos
.NET 6.x on MacOS I had to run with updated path
ln -s /usr/local/share/dotnet/**x64**/dotnet /usr/local/bin/
Run with sudo if you getting a permission error.
Solution 8 - Macos
I solved it this way:
Add entry to .bash_profile
Before:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/opt/gradle/gradle-4.10.2/bin
After:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/opt/gradle/gradle-4.10.2/bin:/usr/local/share/dotnet