在 Mac 中找不到命令

所以我下载了用于 Mac 的 NET Core 2.1 SDK 并安装了它。但是当我从终端运行 dotnet命令时,它会抛出 -bash: dotnet: command not found错误。

我正在尝试使用 dotnet new react开发一个新的.Net Core/React 项目。

我该怎么办? 谢谢!

85379 次浏览

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

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

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

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.

I solved by editing ~/.zshrc

#Add .NET to $PATH

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

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/

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

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