How to install .NET with dotnet-install script

Find more details in Microsoft scripted installation

  1. .NET SDK (Software Development Kit): The SDK includes everything you need to build and run .NET applications. This means it includes the runtime, but also includes other tools for developing, building, running, and testing .NET applications. This includes the .NET CLI (Command Line Interface), compilers, and libraries. You need the SDK to develop and build .NET applications.
  2. .NET Runtime: The runtime includes just the resources required to run existing .NET applications. It does not include the tools and libraries used for building applications. It's a smaller installation package compared to the SDK. When you deploy a .NET application to a server or a client machine, you usually only need to have the appropriate .NET Runtime installed on that machine, not the full SDK.

Installation

$ curl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.sh
$ chmod +x dotnet-install.sh
$ echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.zshrc
$ echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> ~/.zshrc

dotnet-install Script Reference

find reference for dotnet-install script reference in dotnet-install script reference

find options for dotnet-install script in dotnet-install script options

Installing .NET SDK LTS version

The following command will install latest Long term support (LTS) SDK version.

  1. –channel: The channel specifies a major.minor version. For example, '5.0' or '3.1'. The latest release within the specified channel will be installed. If you don't specify a --version, but you do specify a --channel, the script will install the latest SDK or runtime for that major.minor version.
  2. –version: The version specifies the full semantic version number of the SDK or runtime you want to install, for example, '5.0.101' or '3.1.404'. The specified version will be installed.

The version parameter overrides the channel parameter when any version other than latest is used.

The --channel and --version options provide flexibility for your .NET installation. For example, you might want to install the latest stable release (using --channel without --version), or you might want to install a specific version to ensure compatibility with a certain project (using --version).

Starting with .NET 6.0, Microsoft has been providing support for Apple Silicon (arm64). If the stable version of .NET 6.0 or later is available at the time of your question, you should install it for native arm64 support.

$ ./dotnet-install.sh --channel 5.0
$ ./dotnet-install.sh --architecture arm64 --channel 5.0
$ ./dotnet-install.sh --architecture arm64 --version 5.0.101 
$ ./dotnet-install.sh --version latest
$ ./dotnet-install.sh --architecture arm64 --version latest
$ ./dotnet-install.sh --channel 6.0
$ ./dotnet-install.sh --architecture arm64 --channel 6.0
$ ./dotnet-install.sh --channel 7.0
$ ./dotnet-install.sh --architecture arm64 --channel 7.0
$ ./dotnet-install.sh --channel 8.0
$ ./dotnet-install.sh --architecture arm64 --channel 8.0

Installing .NET Runtime LTS version

$ ./dotnet-install.sh --architecture arm64 --version latest --runtime dotnet
$ ./dotnet-install.sh --architecture arm64 --version latest --runtime aspnetcore
$ ./dotnet-install.sh --architecture arm64 --version latest --runtime windowsdesktop

Listing installed SDKs

$ dotnet --list-sdks

5.0.408 [/Users/kenanhancer/.dotnet/sdk]
6.0.411 [/Users/kenanhancer/.dotnet/sdk]
7.0.305 [/Users/kenanhancer/.dotnet/sdk]

Listing installed Runtimes

$ dotnet --list-runtimes

Microsoft.AspNetCore.App 5.0.17 [/Users/kenanhancer/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.19 [/Users/kenanhancer/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.8 [/Users/kenanhancer/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.5.23302.2 [/Users/kenanhancer/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [/Users/kenanhancer/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.19 [/Users/kenanhancer/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.8 [/Users/kenanhancer/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.5.23280.8 [/Users/kenanhancer/.dotnet/shared/Microsoft.NETCore.App]

Uninstalling .NET SDK and .NET Runtime

$ rm -rf /Users/kenanhancer/.dotnet/sdk/8.0.100-preview.5.23303.2
$ rm -rf /Users/kenanhancer/.dotnet/shared/Microsoft.NETCore.App/8.0.0-preview.5.23280.8