dotnet-install scripts - .NET CLI (original) (raw)

Name

dotnet-install.ps1 | dotnet-install.sh - Script used to install the .NET SDK and the shared runtime.

Synopsis

Windows:

dotnet-install.ps1 [-Architecture <ARCHITECTURE>] [-AzureFeed]
    [-Channel <CHANNEL>] [-DryRun] [-FeedCredential]
    [-InstallDir <DIRECTORY>] [-JSonFile <JSONFILE>]
    [-NoPath] [-ProxyAddress] [-ProxyBypassList <LIST_OF_URLS>]
    [-ProxyUseDefaultCredentials] [-Quality <QUALITY>] [-Runtime <RUNTIME>]
    [-SkipNonVersionedFiles] [-UncachedFeed] [-KeepZip] [-ZipPath <PATH>] [-Verbose]
    [-Version <VERSION>]

Get-Help ./dotnet-install.ps1

Linux/macOS:

dotnet-install.sh  [--architecture <ARCHITECTURE>] [--azure-feed]
    [--channel <CHANNEL>] [--dry-run] [--feed-credential]
    [--install-dir <DIRECTORY>] [--jsonfile <JSONFILE>]
    [--no-path] [--quality <QUALITY>]
    [--runtime <RUNTIME>] [--runtime-id <RID>]
    [--skip-non-versioned-files] [--uncached-feed] [--keep-zip] [--zip-path <PATH>] [--verbose]
    [--version <VERSION>]

dotnet-install.sh --help

The bash script also reads PowerShell switches, so you can use PowerShell switches with the script on Linux/macOS systems.

Description

The dotnet-install scripts perform a non-admin installation of the .NET SDK, which includes the .NET CLI and the shared runtime. There are two scripts:

Note

.NET collects telemetry data. To learn more and how to opt out, see .NET SDK telemetry.

Purpose

The intended use of the scripts is for Continuous Integration (CI) scenarios, where:

To set up a development environment or to run apps, use the installers rather than these scripts.

We recommend that you use the stable version of the scripts:

The source for the scripts is in the dotnet/install-scripts GitHub repository.

Script behavior

Both scripts have the same behavior. They download the ZIP/tarball file from the CLI build drops and proceed to install it in either the default location or in a location specified by -InstallDir|--install-dir.

By default, the installation scripts download the SDK and install it. If you wish to only obtain the shared runtime, specify the -Runtime|--runtime argument.

By default, the script adds the install location to the $PATH for the current session. Override this default behavior by specifying the -NoPath|--no-path argument. The script doesn't set the DOTNET_ROOT environment variable.

Important

The script doesn't add the install location to the user's PATH environment variable, you must manually add it.

Before running the script, make sure that your operating system is supported. For more information, see Install .NET on Windows, Linux, and macOS.

You can install a specific version using the -Version|--version argument. The version must be specified as a three-part version number, such as 2.1.0. If the version isn't specified, the script installs the latest version.

The install scripts do not update the registry on Windows. They just download the zipped binaries and copy them to a folder. If you want registry key values to be updated, use the .NET installers.

Options

Examples

./dotnet-install.ps1 -Channel LTS  

macOS/Linux:

./dotnet-install.sh --channel LTS  
./dotnet-install.ps1 -Channel 6.0.1xx -Quality preview -InstallDir C:\cli  

macOS/Linux:

./dotnet-install.sh --channel 6.0.1xx --quality preview --install-dir ~/cli  
./dotnet-install.ps1 -Runtime dotnet -Version 6.0.0  

macOS/Linux:

./dotnet-install.sh --runtime dotnet --version 6.0.0  
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -Proxy $env:HTTP_PROXY -ProxyUseDefaultCredentials -OutFile 'dotnet-install.ps1';  
./dotnet-install.ps1 -InstallDir '~/.dotnet' -Version '6.0.2' -Runtime 'dotnet' -ProxyAddress $env:HTTP_PROXY -ProxyUseDefaultCredentials;  
# Run a separate PowerShell process because the script calls exit, so it will end the current PowerShell session.  
&powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) <additional install-script args>"  

macOS/Linux:

curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin <additional install-script args>  

Set environment variables

Manually installing .NET doesn't add the environment variables system-wide, and generally only works for the session in which .NET was installed. There are two environment variables you should set for your operating system:

Tip

For Linux and macOS, use the echo command to set the variables in your shell profile, such as .bashrc:

echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.bashrc
echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> ~/.bashrc

Uninstall

There is no uninstall script. For information about manually uninstalling .NET, see How to remove the .NET Runtime and SDK.

Signature validation of dotnet-install.sh

Signature validation is an important security measure that helps ensure the authenticity and integrity of a script. By verifying the signature of a script, you can be sure that it has not been tampered with and that it comes from a trusted source.

Here is a step-by-step guide on how to verify the authenticity of the dotnet-install.sh script using GPG:

  1. Install GPG: GPG (GNU Privacy Guard) is a free and open-source tool for encrypting and signing data. You can install it by following the instructions on the GPG website.
  2. Import our public key: Download the install-scripts public key file, and then import it into your GPG keyring by running the command gpg --import dotnet-install.asc.
  3. Download the signature file: The signature file for our bash script is available at https://dot.net/v1/dotnet-install.sig. You can download it using a tool like wget or curl.
  4. Verify the signature: To verify the signature of our bash script, run the command gpg --verify dotnet-install.sig dotnet-install.sh. This will check the signature of the dotnet-install.sh file against the signature in the dotnet-install.sig file.
  5. Check the result: If the signature is valid, you will see a message containing Good signature from "Microsoft DevUXTeamPrague <devuxteamprague@microsoft.com>". This means that the script has not been tampered with and can be trusted.

Preparing environment

Installing GPG and importing our public key is a one time operation.

sudo apt install gpg
wget https://dot.net/v1/dotnet-install.asc
gpg --import dotnet-install.asc

When successful, you should see output like the following:

gpg: directory '/home/<user>/.gnupg' created
gpg: keybox '/home/<user>/.gnupg/pubring.kbx' created
gpg: /home/<user>/.gnupg/trustdb.gpg: trustdb created
gpg: key B9CF1A51FC7D3ACF: public key "Microsoft DevUXTeamPrague <devuxteamprague@microsoft.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Download and verification

With the key imported, you can now download the script and the signature, then verify the script matches the signature:

wget https://dot.net/v1/dotnet-install.sh
wget https://dot.net/v1/dotnet-install.sig
gpg --verify dotnet-install.sig dotnet-install.sh

When successful, you should see output like the following:

gpg: Signature made <datetime>
gpg:                using RSA key B9CF1A51FC7D3ACF
gpg: Good signature from "Microsoft DevUXTeamPrague <devuxteamprague@microsoft.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 2B93 0AB1 228D 11D5 D7F6  B6AC B9CF 1A51 FC7D 3ACF

The warning means that you don't trust the public key in the keyring, but the script is still verified. The exit code returned by the verification command should be 0, indicating success.

See also