Skip to content

Instantly share code, notes, and snippets.

@BuriedStPatrick
Created February 8, 2024 11:11
Show Gist options
  • Save BuriedStPatrick/51707a204fbf932b4a5940e938f3e386 to your computer and use it in GitHub Desktop.
Save BuriedStPatrick/51707a204fbf932b4a5940e938f3e386 to your computer and use it in GitHub Desktop.
Installing .NET & PowerShell properly on Linux by ignoring Microsoft's bad suggestions

Installing .NET & PowerShell properly on Linux by ignoring Microsoft's bad suggestions

Set the following variables:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$HOME/.dotnet/:$PATH
export PATH=$HOME/.dotnet/tools/:$PATH

Setting DOTNET_ROOT will ensure that powershell, for instance, knows where to access the dotnet runtime since it's now installed in the home-directory rather than /usr/share/dotnet. We also need to update the PATH to include the dotnet cli itself, plus any globally installed tools.

Also set these variables in your system environment variables so they're active outside your terminal session. For instance, in: /etc/profile.d/dotnet.env.

Then Download the dotnet-install.sh script:

# Download script
wget -O ~/Downloads/dotnet-install.sh https://dot.net/v1/dotnet-install.sh

# Make script executable
chmod +x ~/Downloads/dotnet-install.sh

Install the latest LTS and STS versions with:

~/Downloads/dotnet-install.sh --version latest --channel LTS
~/Downloads/dotnet-install.sh --version latest --channel STS

Reboot your session, ensuring the DOTNET_ROOT environment variable points to $HOME/.dotnet when loaded from the system environment variables.

Install PowerShell using the dotnet tool command:

dotnet tool install --global powershell

This will install PowerShell into $HOME/.dotnet/tools/powershell. This should already be in your PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment