How to Update .NET on Wsl or Ubuntu

Ever year or so, a new version of .NET ships, and I need to upgrade the .NET SDK version on my machines. Not just the Windows machines, but also the WSL Ubuntu bits that live on those same machines.

First, determine what version of dotnet you already have using this:

1
2
dotnet --version
> 10.0.100-rc.1.25451.107

Yep, I need to update that. But how? Surely there must be a simple way to do it using just the command line. If you just do a quick search for how to do this, you’ll find instructions like this:

1
2
sudo apt-get update
sudo apt-get install -y dotnet-sdk-10.0

The first command works, of course. But usually the second one yields something like this:

1
2
3
4
5
6
> Reading package lists... Done
> Building dependency tree... Done
> Reading state information... Done
> E: Unable to locate package dotnet-sdk-10.0
> E: Couldn't find any package by glob 'dotnet-sdk-10.0'
> E: Couldn't find any package by regex 'dotnet-sdk-10.0'

So you search some more or ask your LLM of choice for help and eventually maybe you find this (which works):

1
2
 wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
 chmod +x dotnet-install.sh

What does this do? Well it downloads the file dotnet-install.sh locally and outputs it in the current folder as a file with the same name. Then, it makes that file executable so you can run it.

NOTE: You should review this file! It’s a script you just download off the Internet! You shouldn’t blindly trust it! If nothing else, run more ./dotnet-install.sh to see what’s in it.

After reviewing the script, you can run it like this to install your .NET version of choice:

1
./dotnet-install.sh --channel 10.0

You’ll see something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dotnet-install: Attempting to download using aka.ms link https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100/dotnet-sdk-10.0.100-linux-x64.tar.gz
dotnet-install: Remote file https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100/dotnet-sdk-10.0.100-linux-x64.tar.gz size is 239125653 bytes.
dotnet-install: Extracting archive from https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.100/dotnet-sdk-10.0.100-linux-x64.tar.gz
dotnet-install: Downloaded file size is 239125653 bytes.
dotnet-install: The remote and local file sizes are equal.
dotnet-install: Installed version is 10.0.100
dotnet-install: Adding to current process PATH: `/home/steve/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
dotnet-install: Installation finished successfully.

You can verify the install by running dotnet --version (and dotnet --list-sdks to see all installed versions) once more.

HTH!

Troubleshooting

What if you still see the older .NET version? It may be that your paths are not configured correctly. You want to ensure that the ~/.dotnet is in your path before /usr/local/share/dotnet. You will want to use the first, global one, not your local one. You can detect which one is being called by running:

1
which dotnet

Update your shell profile (typically .bashrc). Add these lines:

1
2
export DOTNET_ROOT="$HOME/.dotnet"
export PATH="$DOTNET_ROOT:$PATH"

Then reload (or exit and re-enter wsl):

1
source ~/.bashrc

And finally test again:

1
2
which dotnet
dotnet --version

One more thing! Watch out for global.json files which might be referencing the older version! Run a search to find any in your folder structure.

1
find . -name global.json

Remove the global.json file (to use the default installed version) or update it to use the current version (currently would look like this):

1
2
3
4
5
{
  "sdk": {
    "version": "10.0.100"
  }
}