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:
|
|
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:
|
|
The first command works, of course. But usually the second one yields something like this:
|
|
So you search some more or ask your LLM of choice for help and eventually maybe you find this (which works):
|
|
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:
|
|
You’ll see something like this:
|
|
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:
|
|
Update your shell profile (typically .bashrc). Add these lines:
|
|
Then reload (or exit and re-enter wsl):
|
|
And finally test again:
|
|
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.
|
|
Remove the global.json file (to use the default installed version) or update it to use the current version (currently would look like this):
|
|