117

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!

blankface
  • 5,757
  • 19
  • 67
  • 114

11 Answers11

246

Make sure your macOS version meets the prerequisites

https://learn.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

Mazaher Muraj
  • 2,459
  • 1
  • 6
  • 10
99

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.

For M1 and M2, make sure you are installing the Arm64 version - Marcelo Gonella

  • Thank you so much!!! Your post was very helpful for me. I couldn't understand from other comments what I am missing. Thanks again! – KazKazar Dec 21 '21 at 20:37
  • 1
    Welcome bro , enjoy the pain. :) – Tan Hoo Chuan Nickson Dec 28 '21 at 15:42
  • I think I did add the symbolic link not to the x64 version and failed, this solved the issue for me – DanielV Feb 01 '22 at 14:49
  • 3
    For M1 and M2, make sure you are installing the Arm64 version... – Marcelo Gonella Aug 12 '22 at 01:23
  • 2
    dotnet 6 now offers ARM version for Apple Silicon. If you downloaded the ARM version, use `sudo ln -s /usr/local/share/dotnet/dotnet/dotnet /usr/local/bin/` command instead to establish a symbolic link. – AlienKevin Aug 20 '22 at 23:50
  • I'd echo what Marcelo said if you are on an M1. This fixed the issue in terminal but did not fix any issues in Visual Studio Code i.e. intellisense was failing and the OmniSharp server was not loading (after installing the C# plugin). I delete dotnet SDK completely and reinstalled the Arm54 version. Everything then ran smoothly – bmd Dec 23 '22 at 19:13
  • For anyone else who, like me, tried one of the other answers first and kept getting a "file exists" error when trying this answer, you can include the `-f` flag to unlink the existing link and force the new link: `sudo ln -s -f /usr/local/share/dotnet/x64/dotnet /usr/local/bin/` – Alexander Nied Apr 26 '23 at 21:07
42

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

You also need to download & install Runtime from here

Jemshit
  • 9,501
  • 5
  • 69
  • 106
  • To add to confusion , you need this to run `dotnet` from CLI. I was getting with [this other formula](https://formulae.brew.sh/cask/dotnet), which, I guess is part of installing Visual Studio. – CodeFinity Feb 16 '22 at 19:49
  • I **also** had to do: `brew link dotnet`. But you can run `brew doctor` to see if it suggests this. – CodeFinity Feb 16 '22 at 19:52
  • 1
    As another advantage this was the only way to get intellisense working with VSCode on a Mac, at least for me. I even installed VS Studio which didn't work. Thank you. – Keithsoulasa Nov 08 '22 at 19:08
  • 1
    This should be the accepted answer. There are a variety of paths possible on macOS, or /user/local/bin/ may not exist. – Matthew Dean Mar 20 '23 at 19:53
11

I solved by editing ~/.zshrc

#Add .NET to $PATH

export PATH="/usr/local/share/dotnet:$PATH"

Steven
  • 1,071
  • 15
  • 15
8

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/
Kyamasam
  • 183
  • 2
  • 5
2

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.

WeatheJT
  • 21
  • 2
1

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

codepen
  • 409
  • 5
  • 9
0

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
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
0

For Rider Users: If you are installed Rider and making development on it, dotnet must be installed on your machine.

For me, I can not found dotnet installation in specified locations; here or microsoft documentations. But Rider makes its own installation.

Go to Rider - Preferences - Buildy, execution, deploymend - Toolset and build and get the path of ".NET CLI executable path". This path specifies the path of sdk installation.

You can run the command below with location you found.

sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
0

If you are using mac with M1 (arm) make sure you install the Arm64 version and not the x64 version that you download by default

0

April 2023, Please open a new terminal before trying the top answer.

macOS 13.3, .NET 7.0 I think it's no longer an issue.

Alvin Smith
  • 547
  • 5
  • 9