How do I install Chocolatey packages behind a proxy on Windows 2012 R2 Core?

3.2k views Asked by At

I am currently using Chocolatey in conjunction with Ansible to roll out a number of applications to a mixed Windows/Linux environment.

All the Windows machines, bar one are running as server core installations, and for all the machines except the one with a GUI installed, Chocolatey will not install any applications as it fails to use the proxy.

I have set the proxy environment variables using netsh:

PS C:\Windows\system32> netsh winhttp show proxy

Current WinHTTP proxy settings:

Proxy Server(s) :  http://aaa.bbb.ccc.ddd:3128
Bypass List     :  <local>;localhost;127.0.0.1;172.16.*;192.168.*;*.domain.local;

Also in %APPDATA%\NuGet\NuGet.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="HTTP_PROXY" value="http://aaa.bbb.ccc.ddd:3128" />
  </config>
</configuration>

However, when Powershell scripts scripts call $webclient = new-object System.Net.WebClient the proxy element of this object returns nothing:

PS C:\Windows\system32> $webclient = new-object System.Net.WebClient
PS C:\Windows\system32> $webclient.Proxy

Credentials
-----------

I've found that if I manually force the code within functions/Get-Headers.ps1 and functions/Get-webFiles.ps1 to use the proxy then the installs work, however this is not a great workaround to the problem as my Ansible tasks are now fixed to a specific version of chocolatey where I know the workaround works.

Does anyone have any other ideas/solutions to try?

4

There are 4 answers

0
ferventcoder On BEST ANSWER

Choco series 0.9.9+ was a total rewrite and hasn't implemented all the things yet, including proxy support out of what you set in IE.

Watch issue https://github.com/chocolatey/choco/issues/243 to know when it available again.

Update: proxy support is in Chocolatey now - see https://github.com/chocolatey/choco/wiki/Proxy-Settings-for-Chocolatey

0
Menelaos On

I tried this in November 2018:

So, three steps are needed to install and run chocolatey:

  1. You need to go and manually download the installation file from:

    https://chocolatey.org/install.ps1

  2. You need to either: a. edit the ps1 file OR
    b. your environmental variables.

You need to have the following variables:

    $env:chocolateyProxyLocation = "http://USER:PASSWORD@http://USER:PASSWORD@IP_ADDRESS:PORT
    $env:chocolateyProxyUser = "USER"
    $env:chocolateyProxyPassword  =  "PASSWORD"

   THEY MUST BE AS THEY ARE ABOVE with USER:PASSWORD@PROXY_LOCATION:PORT format.
  1. You must call the install.ps1 file. You can call it either from Windows-PowerShell ISE or from the CommandLine

You must call your local script!!! Not the online one, e.g.:

file:///E:/softwares/chocolate_install_script/install.ps1

Call the following:

C:\WINDOWS\system32>@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('file:///E:/softwares/chocolate_install_script/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

  1. And everything will work if you run this with admin provileges

After, you will need to do:

choco config set proxy http://USER:PASSWORD@IP_ADDRESS:PORT
choco config set proxyUser bob
choco config set proxyPassword 123Sup#rSecur3
0
Tijazz On

This below completely solved this problem...

Kindly follow this link below to resolve this issue. https://duanenewman.net/blog/post/installing-chocolatey-behind-a-corporate-proxy/

However, for future sake this is the code beneath.

@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Just copy and paste the above code to your CMD which you run as an administrator. And that's all. Thanks to Duane Newman for the originality of the code

1
Subin Sugunan On

run this first

choco config set proxy http://proxy_host:proxy_port