如何在Ubuntu 18.04 WSL中安装最新版本NuGet.exe CLI?
The default apt repository for Ubuntu 18.04 only ships with the outdated NuGet 2.8.x, but there are two straightforward ways to get the latest 5.x.x version:
Method 1: Install the .NET SDK (Recommended)
NuGet 5.x+ is tightly integrated with the .NET SDK, so installing the SDK gives you access to the latest NuGet tooling along with other .NET utilities. Here's how:
Add Microsoft's software repository to your system:
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.debInstall the .NET SDK 5.0 (or a newer version like 6.0 if preferred):
sudo apt-get update sudo apt-get install -y apt-transport-https sudo apt-get update sudo apt-get install -y dotnet-sdk-5.0Verify the installation:
Rundotnet nuget --version— you should see a 5.x.x version number pop up if everything worked.Run your package install command:
Usedotnet nuget install Test.Nuget.Version -OutputDirectory packagesinstead of the standalonenugetcommand. It works exactly the same way for your use case.
Method 2: Install the standalone NuGet CLI
If you only need the NuGet tool and don't want the full .NET SDK, you can download the official NuGet CLI binary directly:
Grab the latest NuGet CLI executable:
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exeRun it using Mono (since it's a Windows executable):
First install Mono if you don't have it:sudo apt install mono-completeThen execute your command with:
mono nuget.exe install Test.Nuget.Version -OutputDirectory packages(Optional) Make it easier to use:
Move the executable to your system path so you can run it without typingmonoevery time:sudo mv nuget.exe /usr/local/bin/nugetNow you can just run
nuget install Test.Nuget.Version -OutputDirectory packagesdirectly.
Method 1 is the more stable and maintainable option, as it keeps your NuGet tooling in sync with the official .NET ecosystem.
内容的提问来源于stack exchange,提问作者Unknown

