70

As far as I can tell, NuGet is meant to be installed as a Visual Studio extension:

http://docs.nuget.org/docs/start-here/installing-nuget

But what if I need NuGet on a machine that doesn't have VS installed?

Specifically, I would like to install NuGet with a PowerShell script.

knocte
  • 16,941
  • 11
  • 79
  • 125
BaltoStar
  • 8,165
  • 17
  • 59
  • 91

6 Answers6

126
  1. Run Powershell with Admin rights
  2. Type the below PowerShell security protocol command for TLS12:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
Syam Kallada
  • 1,285
  • 1
  • 5
  • 3
57

Here's a short PowerShell script to do what you probably expect:

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$rootPath\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose

Note that Invoke-WebRequest cmdlet arrived with PowerShell v3.0. This article gives the idea.

Phobis
  • 7,524
  • 10
  • 47
  • 76
Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • 3
    I updeated script to grab the latest NuGet.exe, here: [https://dist.nuget.org/win-x86-commandline/latest/nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe) – Phobis Jul 09 '16 at 15:58
  • Invoke-WebRequest should get -UseBasicParsing in PS older that 6.0. – Palec Dec 20 '19 at 15:47
25

This also seems to do it. PS Example:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
colej4586
  • 409
  • 5
  • 10
  • But how to you get a newer version than 2? – Brain2000 Dec 10 '18 at 21:30
  • 27
    Note: around the 3rd April 2020 the minimum TLS version was raised on the provider lookup site, if your machine has not been set by policy, you can set using [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls11,Tls12' – Jules Clements Apr 04 '20 at 19:28
  • Use `Install-PackageProvider -Name NuGet -Scope CurrentUser` to use it without admin rights. That command will not work on Powershell Core. – KargWare Apr 07 '20 at 01:50
  • @JulesClements thanks, you saved me a couple of hours – Pavel Anikhouski May 05 '20 at 12:53
10

Without having Visual Studio, you can grab Nuget from: http://nuget.org/nuget.exe

For command-line executions using this, check out: http://docs.nuget.org/docs/reference/command-line-reference

With respect to Powershell, just copy the nuget.exe to the machine. No installation required, just execute it using commands from the above documentation.

SeanPrice
  • 464
  • 2
  • 8
  • Thanks for the response. Do you know if links are available for specific versions of NuGet.exe ? – BaltoStar May 20 '13 at 20:54
  • Hmm, I do not know where to find commands for an associated version of nuget. But I guess if you need to know what version of nuget.exe you have, just type "nuget help". This can help assist in searching further for command compatibilities. – SeanPrice May 20 '13 at 20:59
  • Worth noting that the version at `http://nuget.org/nuget.exe` is old compared to the one at `https://dist.nuget.org/win-x86-commandline/latest/nuget.exe` – Alex Angas Feb 06 '19 at 13:27
  • Just under three years later, worth noting is also [https://www.nuget.org/downloads](https://www.nuget.org/downloads) – RolfBly Sep 23 '22 at 13:41
6

With PowerShell but without the need to create a script:

Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile Nuget.exe
knocte
  • 16,941
  • 11
  • 79
  • 125
3

None of the above solutions worked for me, I found an article that explained the issue. The security protocols on the system were deprecated and therefore displayed an error message that no match was found for the ProviderPackage.

Here is a the basic steps for upgrading your security protocols:

Run both cmdlets to set .NET Framework strong cryptography registry keys. After that, restart PowerShell and check if the security protocol TLS 1.2 is added. As of last, install the PowerShellGet module.

The first cmdlet is to set strong cryptography on 64 bit .Net Framework (version 4 and above).

[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
1
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
The second cmdlet is to set strong cryptography on 32 bit .Net Framework (version 4 and above).

[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
1
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Restart Powershell and check for supported security protocols.

[PS] C:\>[Net.ServicePointManager]::SecurityProtocol
Tls, Tls11, Tls12
1
2
[PS] C:\>[Net.ServicePointManager]::SecurityProtocol
Tls, Tls11, Tls12
Run the command Install-Module PowershellGet -Force and press Y to install NuGet provider, follow with Enter.

[PS] C:\>Install-Module PowershellGet -Force
 
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

[PS] C:\>Install-Module PowershellGet -Force
 
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
Ben
  • 311
  • 2
  • 6
  • I never got asked for NuGet to be installed. Perhaps because I already have nuget.exe in the directory running the above PS lines? – Fandango68 Jul 13 '21 at 05:48