如何检查是否已安装 .NET CoreHow to check that .NET Core is already installed

本文介绍如何检查计算机上安装的 .NET Core 运行时和 SDK 的版本。This article teaches you how to check which versions of the .NET Core runtime and SDK are installed on your computer. 如果你拥有一个集成开发环境(如 Visual Studio 或 Visual Studio for Mac),则可能已安装 .NET core。.NET core may have already been installed if you have an integrated development environment, such as Visual Studio or Visual Studio for Mac.

安装 SDK 便会安装相应的运行时。Installing an SDK installs the corresponding runtime.

如果本文中的任何命令失败,则未安装运行时或 SDK。If any command in this article fails, you don't have the runtime or SDK installed. 有关详细信息,请参阅 WindowsmacOSLinux 的安装文章。For more information, see the install articles for Windows, macOS, or Linux.

检查 SDK 版本Check SDK versions

可使用终端查看当前安装的 .NET Core SDK 版本。You can see which versions of the .NET Core SDK are currently installed with a terminal. 打开终端并运行以下命令。Open a terminal and run the following command.

dotnet --list-sdks

将获得类似于下面的输出。You get output similar to the following.

2.1.500 [C:\program files\dotnet\sdk]
2.1.502 [C:\program files\dotnet\sdk]
2.1.504 [C:\program files\dotnet\sdk]
2.1.600 [C:\program files\dotnet\sdk]
2.1.602 [C:\program files\dotnet\sdk]
2.2.101 [C:\program files\dotnet\sdk]
3.0.100 [C:\program files\dotnet\sdk]
3.1.100 [C:\program files\dotnet\sdk]
2.1.500 [/home/user/dotnet/sdk]
2.1.502 [/home/user/dotnet/sdk]
2.1.504 [/home/user/dotnet/sdk]
2.1.600 [/home/user/dotnet/sdk]
2.1.602 [/home/user/dotnet/sdk]
2.2.101 [/home/user/dotnet/sdk]
3.0.100 [/home/user/dotnet/sdk]
3.1.100 [/home/user/dotnet/sdk]
2.1.500 [/usr/local/share/dotnet/sdk]
2.1.502 [/usr/local/share/dotnet/sdk]
2.1.504 [/usr/local/share/dotnet/sdk]
2.1.600 [/usr/local/share/dotnet/sdk]
2.1.602 [/usr/local/share/dotnet/sdk]
2.2.101 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]

检查运行时版本Check runtime versions

可使用以下命令查看当前安装的 .NET Core 运行时版本。You can see which versions of the .NET Core runtime are currently installed with the following command.

dotnet --list-runtimes

将获得类似于下面的输出。You get output similar to the following.

Microsoft.AspNetCore.All 2.1.7 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [c:\program files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.6 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.7 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.AspNetCore.All 2.1.7 [/home/user/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [/home/user/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [/home/user/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [/home/user/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [/home/user/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.6 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/home/user/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.7 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/home/user/dotnet/shared/Microsoft.NETCore.App]
Microsoft.AspNetCore.All 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

检查安装文件夹Check for install folders

可以安装 .NET Core,但不能将其添加到操作系统或用户配置文件的 PATH 变量。It's possible that .NET Core is installed but not added to the PATH variable for your operating system or user profile. 运行前面几节中的命令可能不起作用。Running the commands from the previous sections may not work. 作为替代方法,可以检查 .NET Core 安装文件夹是否存在。As an alternative, you can check that the .NET Core install folders exist.

从安装程序或脚本安装 .NET Core 时,会将其安装到标准文件夹中。When you install .NET Core from an installer or script, it's installed to a standard folder. 大多数时候,安装 .NET Core 时使用的安装程序或脚本会让你选择安装到另一个文件夹。Much of the time the installer or script you're using to install .NET Core gives you an option to install to a different folder. 如果选择安装到其他文件夹,请调整文件夹路径的开头。If you choose to install to a different folder, adjust the start of the folder path.

  • dotnet executabledotnet executable
    C:\program files\dotnet\dotnet.exeC:\program files\dotnet\dotnet.exe

  • .NET SDK.NET SDK
    C:\program files\dotnet\sdk\{version}\C:\program files\dotnet\sdk\{version}\

  • .NET Runtime.NET Runtime
    C:\program files\dotnet\shared\{runtime-type}\{version}\C:\program files\dotnet\shared\{runtime-type}\{version}\

  • dotnet executabledotnet executable
    /home/user/share/dotnet/dotnet/home/user/share/dotnet/dotnet

  • .NET SDK.NET SDK
    /home/user/share/dotnet/sdk/{version}//home/user/share/dotnet/sdk/{version}/

  • .NET Runtime.NET Runtime
    /home/user/share/dotnet/shared/{runtime-type}/{version}//home/user/share/dotnet/shared/{runtime-type}/{version}/

  • dotnet executabledotnet executable
    /usr/local/share/dotnet/dotnet/usr/local/share/dotnet/dotnet

  • .NET SDK.NET SDK
    /usr/local/share/dotnet/sdk/{version}//usr/local/share/dotnet/sdk/{version}/

  • .NET Runtime.NET Runtime
    /usr/local/share/dotnet/shared/{runtime-type}/{version}//usr/local/share/dotnet/shared/{runtime-type}/{version}/

详细信息More information

可通过命令 dotnet --info 查看 SDK 版本和运行时版本。You can see both the SDK versions and runtime versions with the command dotnet --info. 你还将获得其他环境相关信息,如操作系统版本和运行时标识符 (RID)。You'll also get other environmental related information, such as the operating system version and runtime identifier (RID).

后续步骤Next steps