'nuget' Is Not Recognized: Fix in CMD, PowerShell and PMC

You type nuget in Command Prompt, PowerShell or the Visual Studio Package Manager Console and Windows answers that it is not recognized. The message is accurate: there is no nuget.exe on your PATH. NuGet itself works inside Visual Studio and the .NET SDK, but nuget.exe is a separate download. You have three ways out: put nuget.exe in a folder and add that folder to PATH, use the dotnet CLI instead, or use the PowerShell commands built into the Package Manager Console. Pick the one that fits below.

Animated table matching each situation to a fix: add nuget.exe to PATH for CMD or PowerShell, Install-Package in the Package Manager Console, dotnet add package for projects, reopen the terminal if PATH was just changed, and use the dotnet CLI on macOS or Linux. It is an illustration, not a screenshot.
Which fix to use for your situation (illustration, not a screenshot).

Why ‘nuget’ is not recognized

The two messages are the same problem in two shells:

'nuget' is not recognized as an internal or external command,
operable program or batch file.
nuget : The term 'nuget' is not recognized as the name of a cmdlet, function,
script file, or operable program.

The first comes from Command Prompt, the second from PowerShell or the Package Manager Console. Both mean the shell searched every folder on PATH and found no nuget.exe. Microsoft describes nuget.exe as the original command-line tool that you download yourself, while the dotnet CLI ships with the .NET SDK (Install NuGet client tools (Microsoft Learn)).

Fix 1: install nuget.exe and add it to PATH

Use this when you need the nuget command itself, for example in build scripts for non-SDK projects.

  • Download the latest nuget.exe from https://dist.nuget.org/win-x86-commandline/latest/nuget.exe or pick a version on nuget.org downloads. It is a single file, not an installer.
  • Save it in a stable folder such as C:\Tools\nuget.
  • Open Edit the system environment variables, choose Environment Variables, select Path, click Edit, then New, and paste the folder path (the folder, not the .exe file).
  • Close every Command Prompt, PowerShell and Visual Studio window and open a new one, because running programs keep the old PATH.
  • Run nuget help. You should see the version and command list.

The same in PowerShell for the current user:

$dir = "C:\Tools\nuget"
New-Item -ItemType Directory -Force $dir | Out-Null
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "$dir\nuget.exe"

$user = [Environment]::GetEnvironmentVariable("Path", "User")
[Environment]::SetEnvironmentVariable("Path", "$user;$dir", "User")

Taking nuget.exe from the NuGet.CommandLine package

An older route also works: install the NuGet.CommandLine package from nuget.org in a project. The package contains nuget.exe under .nuget\packages\nuget.commandline\<version>\tools in your user profile.

Visual Studio NuGet Package Manager with NuGet.CommandLine 5.5.1 selected and the Output window showing the package installed
Screenshot: NuGet.CommandLine 5.5.1 installed from the Visual Studio package manager.

You can add that folder to PATH, as in the screenshot below, but the path contains the version number, so it stops working when the package is updated or the cache is cleared. A fixed folder from the steps above is more reliable.

Windows Environment Variables dialog with the Path variable selected and an edit window listing the NuGet.CommandLine tools folder as one entry
Screenshot: the Path variable with the nuget.commandline tools folder added.

Fix 2: use the dotnet CLI instead of nuget.exe

If you only need to add or restore packages for an SDK-style project, you do not need nuget.exe at all. The .NET SDK has the same operations:

dotnet add package Newtonsoft.Json --version 13.0.3
dotnet restore
dotnet nuget list source

I ran these three commands with .NET SDK 10.0.401. The first added <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> to the project, the second restored it, and the third listed nuget.org as the enabled source. The full options are in dotnet add package (Microsoft Learn). To check which .NET and C# versions you have, see how to check the C# and .NET version. To install a prerelease build, see installing a preview version of a NuGet package.

On macOS and Linux this is the only route: Microsoft states that nuget.exe is not supported there, including under Mono (Install NuGet client tools (Microsoft Learn)).

Fix 3: Package Manager Console in Visual Studio

The Package Manager Console runs PowerShell with NuGet cmdlets, so you rarely need the nuget command there. Use the cmdlets:

Install-Package Newtonsoft.Json -Version 13.0.3
Update-Package Newtonsoft.Json
Uninstall-Package Newtonsoft.Json

If your own script calls nuget inside the console, install nuget.exe and update PATH as in Fix 1, then restart Visual Studio so the console sees the new PATH. Want to publish a package rather than consume one? See creating and publishing a NuGet package with Visual Studio.

Still not recognized after changing PATH

  • The terminal was already open. Open a new window. Run where nuget in Command Prompt to see what Windows finds.
  • The wrong thing is in PATH. It must be the folder that contains nuget.exe, not the full path of the file.
  • The file was renamed. The name has to be exactly nuget.exe.
  • User PATH versus system PATH. A change to the user PATH applies to your account only. Build agents running under another account need their own entry.
  • macOS or Linux. nuget.exe is not supported; use dotnet.

What was tested and what was not

  • Run on macOS with .NET SDK 10.0.401: dotnet add package, dotnet restore and dotnet nuget list source. I also downloaded nuget.exe from the dist.nuget.org URL and confirmed it is a Windows executable (about 8.7 MB); I could not run it.
  • Not tested: the Windows steps (PATH dialog, the PowerShell script, where nuget) and the Package Manager Console cmdlets, because there is no Windows machine here. They follow Microsoft’s documentation, and the two screenshots come from an earlier Windows session with NuGet.CommandLine 5.5.1.

Summary

  • The error means no nuget.exe is on PATH. Visual Studio and the .NET SDK do not install it as a command.
  • Need the command: download nuget.exe, keep it in a fixed folder, add that folder to PATH, open a new terminal.
  • Just need packages: use dotnet add package, or Install-Package in the Package Manager Console.

Found this useful?

Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.

nuget not recognized FAQ

Why is nuget not recognized in PowerShell but works in Visual Studio?

Visual Studio uses its own built-in NuGet client. The nuget command in a shell needs nuget.exe on PATH, and the NuGet client in Visual Studio does not put it there.

Do I need nuget.exe if I have the .NET SDK?

Usually not. For SDK-style projects, dotnet add package, dotnet restore and dotnet pack cover the common tasks. nuget.exe is mainly for Windows, .NET Framework and non-SDK-style projects.

Can I run nuget.exe on macOS or Linux?

Microsoft does not support it, including under Mono. Use the dotnet CLI from the .NET SDK.

Did this clear the error? Tell us in the comments which fix worked for you.

9 thoughts on “‘nuget’ Is Not Recognized: Fix in CMD, PowerShell and PMC”

Leave a Reply

Your email address will not be published. Required fields are marked *