Install .NET SDK (6, 7, 8) on FreeBSD 14

UPDATE: There is now a port/package for dotnet from version 8.0 onwards: lang/dotnet

As at time of writing, there is no official port of the newer .NET SDKs to FreeBSD.

For now, we can obtain a FreeBSD version of the .NET SDK via a Github repository, linked here - https://github.com/sec/dotnet-core-freebsd-source-build/releases

On this page, find and download the corresponding version and architecture for your environment - in this example, I'm running FreeBSD 14 using amd64 architecture, and I want .NET 8, so I'm downloading the file dotnet-sdk-8.0.100-freebsd-x64.tar.gz.

We want to move this file from our Downloads folder into the users home directory, and we need to run some commands anyway, so we open up a Terminal.

First determine what shell you are using: Run ps -p $$ and whatever is listed under COMMAND is your currently-running shell type.

For csh execute the following:-
mv ~/Downloads/dotnet-sdk-8.0.100-freebsd-x64.tar.gz ~/
setenv DOTNET_FILE dotnet-sdk-8.0.100-freebsd-x64.tar.gz
set P=`pwd`
setenv DOTNET_ROOT $P/.dotnet
mkdir -p "$DOTNET_ROOT" && tar zxf "$DOTNET_FILE" -C "$DOTNET_ROOT"
setenv PATH $PATH\:$DOTNET_ROOT\:$DOTNET_ROOT/tools

You can update /etc/csh.cshrc with the following lines to persist the changes after reboot or terminal change (only for csh):
set P=`pwd`
setenv DOTNET_ROOT $P/.dotnet
setenv PATH $PATH\:$DOTNET_ROOT\:$DOTNET_ROOT/tools


For bash execute the following:-
mv ~/Downloads/dotnet-sdk-7.0.403-freebsd-x64.tar.gz ~/
DOTNET_FILE=dotnet-sdk-7.0.403-freebsd-x64.tar.gz
export DOTNET_ROOT=$(pwd)/.dotnet
mkdir -p "$DOTNET_ROOT" && tar zxf "$DOTNET_FILE" -C "$DOTNET_ROOT"
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

You can update /etc/profile with the following lines to persist the changes after reboot or terminal change (only for bash/sh etc.):
export DOTNET_ROOT=$(pwd)/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

Now, run the dotnet --version command, and it should return the installed SDK version number. If it works and returns the version number, then you're done!

Note: Microsoft harvests some usage and other data when you execute commands such as dotnet build and dotnet run, to disable this, set the environment variable as per below:

CSH:
Code:
setenv DOTNET_CLI_TELEMETRY_OPTOUT true

Bash:
Code:
export DOTNET_CLI_TELEMETRY_OPTOUT=true
 
Last edited:
I'll put together your script:

Code:
wget  https://github.com/sec/dotnet-core-freebsd-source-build/releases/download/8.0.102-vmr/dotnet-sdk-8.0.102-freebsd-x64.tar.gz
DOTNET_FILE=dotnet-sdk-8.0.102-freebsd-x64.tar.gz
export DOTNET_ROOT=/opt/.dotnet
mkdir -p "$DOTNET_ROOT" && tar zxf "$DOTNET_FILE" -C "$DOTNET_ROOT"
ln -s $DOTNET_ROOT/dotnet /bin/dotnet
dotnet --version

After the above, the following error missing so may occur: I failed to resolve it
 

Attachments

  • 1712908215706.png
    1712908215706.png
    330.8 KB · Views: 216
Back
Top