Dotnetup as alternative to package managers
The recently released dotnetup works great for managing the installed versions of .NET SDK on Linux and macOS. I have now fully switched to using it instead of the OS package managers: yay on CachyOS and Homebrew on macOS.
The whole process would have been even simpler if I hadn't already had several .NET SDKs installed by other means which I wanted to uninstall first.
On Linux, I installed all of them, including the preview version of .NET 11, via AUR packages, so I could also uninstall them using yay:
yay -Rsn dotnet-sdk-bin dotnet-runtime-bin
yay -Rsn aspnet-runtime-9.0-bin dotnet-sdk-9.0-bin dotnet-runtime-9.0-bin
yay -Rsn aspnet-runtime-8.0-bin dotnet-sdk-8.0-bin dotnet-runtime-8.0-bin
yay -Rsn dotnet-sdk-preview-bin dotnet-runtime-preview-bin dotnet-host-preview-bin
Doing it on macOS required more work because the Homebrew package for the preview version conflicts with release versions. So, I had to install .NET 11 SDK manually using the installer from the .NET download page. I could still use Homebrew to uninstall to non-preview SDK versions:
brew uninstall --cask dotnet-sdk@8
brew uninstall --cask dotnet-sdk@9
brew uninstall --cask dotnet-sdk
I couldn't find a simple way to uninstall the preview version. Even the .NET uninstall tool reported that it
Cannot uninstall version 11.0.0 and above
I ended up manually deleting the folders:
sudo rm -rf /usr/local/share/dotnet/sdk/11.0.100-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/sdk-manifests/11.0.100-rc.1
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/host/fxr/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/packs/Microsoft.AspNetCore.App.Ref/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Host.osx-arm64/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Ref/11.0.0-rc.1.26425.128
sudo rm -rf /usr/local/share/dotnet/templates/11.0.0-rc.1.26425.128
Now I was finally ready to start with dotnetup installation. As Zsh user on both Linux and macOS, I used:
curl -fsSL https://aka.ms/dotnetup/get-dotnetup.sh | zsh
The next step was first time setup:
~/.dotnetup/dotnetup init
This downloaded the latest .NET SDK and modified my .zshrc file to add dotnet to path. But in doing that it managed to replace the symbolic link to my dotfiles managed by dotter with a local copy of a file. Once I noticed that, I reverted the change and did the necessary modifications myself. I added the following to my .zprofile instead of .zshrc so that dotnet would be in path also for Rider and Visual Studio Code which I usually don't run from the terminal:
# dotnetup: begin
if [ -x "$HOME/.dotnetup/dotnetup" ]; then
eval "$("$HOME/.dotnetup/dotnetup" env script --shell zsh --dotnet --dotnetup)"
fi
# dotnetup: end
With that set up, it was time to install the channels I was generally interested in:
dotnetup install latest
dotnetup install lts
dotnetup install preview
I'll likely remove the preview channel in a couple of days when .NET 11 gets released and hence installed via the latest channel. And I might add 10 next year when .NET 10 gets replaced by .NET 12 in lts channel.
To keep everything up-to-date, I added the following two commands to my regular update script:
dotnetup self update # updates dotnetup
dotnetup update # updates all installed channels
Although dotnetup is still in early preview, it already does its job well. I have been using similar tools for managing other development frameworks (SDKMAN! for Java and fnm for Node.js) and I'm glad to now have a similar tool at my disposal for .NET.
