Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Forked from ramonsmits/HOWTO.md
Last active June 6, 2024 19:23
Show Gist options
  • Save Aaronontheweb/a277a8ef5716ec289acb3c6845ae2c7a to your computer and use it in GitHub Desktop.
Save Aaronontheweb/a277a8ef5716ec289acb3c6845ae2c7a to your computer and use it in GitHub Desktop.
Install .NET 8 on Raspberry pi

Install .NET 8 on Raspberry pi

Install .NET via the following script:

1. Perform dry run and review envvar DOTNET_INSTALL_DIR

I advise to first do a dry run and to enable verbose mode to review if envvar DOTNET_INSTALL_DIR is set correctly:

curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version latest --verbose --dry-run

Note: Preview must include the full preview release label like 8.0.100-rc.1.23463.5

2. Set DOTNET_INSTALL_DIR if needed

Inspect the output and validate the install path. You can override this as listed in the script its help:

export DOTNET_INSTALL_DIR=/opt/dotnet

I already had older SDK's installed in /opt/dotnet but the script will not add new SDK's to that path automatically although the DOTNET_ROOT envvar already points to this path.

3. Perform actual install

Run the script but now without --dry-run:

Latest

curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version latest --verbose

4. Review installed SDK's

Review the SDK's after installation:

dotnet --list-sdks

5. Ensure dotnet tool is Supported on $PATH

If you login or ssh into your Raspberry PI with a different profile the dotnet CLI may not work, and out of the box the above steps didn't allow me to install and run dotnet tools such as pbm on the terminal.

An easy fix for this is to append the following to your .bashrc profile:

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

5. Remove old SDK's

You can easily remove SDK's by removing the corresponding folders:

sudo -s
cd DOTNET_INSTALL_DIR
rm -r sdk/$version
rm -r shared/Microsoft.NETCore.App/$version
rm -r shared/Microsoft.AspNetCore.All/$version
rm -r shared/Microsoft.AspNetCore.App/$version
rm -r host/fxr/$version
@Aaronontheweb
Copy link
Author

Added some instructions on how to fix the PATH variable via the .bashrc file - this was a problem I ran into on my machine

@Aaronontheweb
Copy link
Author

To get this to work on a specific user profile on Raspberry PI - after logging in under ssh, make sure you update ~/.profile to include the following:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

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