参考链接:https://blog.csdn.net/sw3114/article/details/104299003?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1

按照https://chocolatey.org/install#individual的安装命令搞了半天无果,按照参考链接搞定了,对链接中的setup.ps1文件稍作修改,可用使用,步骤如下:
1.下载chocolatey.XXX.nupkg,小主下载的版本为chocolatey.0.10.15.nupkg,地址为:https://chocolatey.org/install#organization
2.新建记事本文件,并改名为setup.ps1,下面是内容:

# Download and install Chocolatey nupkg from an OData (HTTP/HTTPS) url such as Artifactory, Nexus, ProGet (all of these are recommended for organizational use), or Chocolatey.Server (great for smaller organizations and POCs)
# This is where you see the top level API - with xml to Packages - should look nearly the same as https://chocolatey.org/api/v2/
# If you are using Nexus, always add the trailing slash or it won't work
# === EDIT HERE ===
$packageRepo = '<INSERT ODATA REPO URL>'# If the above $packageRepo repository requires authentication, add the username and password here. Otherwise these leave these as empty strings.
$repoUsername = ''    # this must be empty is NOT using authentication
$repoPassword = ''    # this must be empty if NOT using authentication# Determine unzipping method
# 7zip is the most compatible, but you need an internally hosted 7za.exe.
# Make sure the version matches for the arguments as well.
# Built-in does not work with Server Core, but if you have PowerShell 5
# it uses Expand-Archive instead of COM
$unzipMethod = 'builtin'
#$unzipMethod = '7zip'
#$7zipUrl = 'https://chocolatey.org/7za.exe' (download this file, host internally, and update this to internal)# === ENVIRONMENT VARIABLES YOU CAN SET ===
# Prior to running this script, in a PowerShell session, you can set the
# following environment variables and it will affect the output# - $env:ChocolateyEnvironmentDebug = 'true' # see output
# - $env:chocolateyIgnoreProxy = 'true' # ignore proxy
# - $env:chocolateyProxyLocation = '' # explicit proxy
# - $env:chocolateyProxyUser = '' # explicit proxy user name (optional)
# - $env:chocolateyProxyPassword = '' # explicit proxy password (optional)# === NO NEED TO EDIT ANYTHING BELOW THIS LINE ===
# Ensure we can run everything
Set-ExecutionPolicy Bypass -Scope Process -Force;# If the repository requires authentication, create the Credential object
if ((-not [string]::IsNullOrEmpty($repoUsername)) -and (-not [string]::IsNullOrEmpty($repoPassword))) {$securePassword = ConvertTo-SecureString $repoPassword -AsPlainText -Force$repoCreds = New-Object System.Management.Automation.PSCredential ($repoUsername, $securePassword)
}$searchUrl = ($packageRepo.Trim('/'), 'Packages()?$filter=(Id%20eq%20%27chocolatey%27)%20and%20IsLatestVersion') -join '/'# Reroute TEMP to a local location
New-Item $env:ALLUSERSPROFILE\choco-cache -ItemType Directory -Force
$env:TEMP = "$env:ALLUSERSPROFILE\choco-cache"$localChocolateyPackageFilePath = 'D:\E_DRIVE\wireshark\chocolatey.0.10.15.nupkg'
#$env:TEMP 'chocolatey.nupkg'
$ChocoInstallPath = "$($env:SystemDrive)\ProgramData\Chocolatey\bin"
$env:ChocolateyInstall = "$($env:SystemDrive)\ProgramData\Chocolatey"
$env:Path += ";$ChocoInstallPath"
$DebugPreference = 'Continue';# PowerShell v2/3 caches the output stream. Then it throws errors due
# to the FileStream not being what is expected. Fixes "The OS handle's
# position is not what FileStream expected. Do not use a handle
# simultaneously in one FileStream and in Win32 code or another
# FileStream."
function Fix-PowerShellOutputRedirectionBug {$poshMajorVerion = $PSVersionTable.PSVersion.Majorif ($poshMajorVerion -lt 4) {try{# http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments$bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField"$objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host)$bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty"$consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @())[void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @())$bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField"$field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags)$field.SetValue($consoleHost, [Console]::Out)[void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @())$field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags)$field2.SetValue($consoleHost, [Console]::Error)} catch {Write-Output 'Unable to apply redirection fix.'}}
}Fix-PowerShellOutputRedirectionBug# Attempt to set highest encryption available for SecurityProtocol.
# PowerShell will not set this by default (until maybe .NET 4.6.x). This
# will typically produce a message for PowerShell v2 (just an info
# message though)
try {# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is# installed (.NET 4.5 is an in-place upgrade).[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
} catch {Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3+.'
}function Get-Downloader {param ([string]$url)$downloader = new-object System.Net.WebClient$defaultCreds = [System.Net.CredentialCache]::DefaultCredentialsif (Test-Path -Path variable:repoCreds) {Write-Debug "Using provided repository authentication credentials."$downloader.Credentials = $repoCreds} elseif ($defaultCreds -ne $null) {Write-Debug "Using default repository authentication credentials."$downloader.Credentials = $defaultCreds}$ignoreProxy = $env:chocolateyIgnoreProxyif ($ignoreProxy -ne $null -and $ignoreProxy -eq 'true') {Write-Debug 'Explicitly bypassing proxy due to user environment variable.'$downloader.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()} else {# check if a proxy is required$explicitProxy = $env:chocolateyProxyLocation$explicitProxyUser = $env:chocolateyProxyUser$explicitProxyPassword = $env:chocolateyProxyPasswordif ($explicitProxy -ne $null -and $explicitProxy -ne '') {# explicit proxy$proxy = New-Object System.Net.WebProxy($explicitProxy, $true)if ($explicitProxyPassword -ne $null -and $explicitProxyPassword -ne '') {$passwd = ConvertTo-SecureString $explicitProxyPassword -AsPlainText -Force$proxy.Credentials = New-Object System.Management.Automation.PSCredential ($explicitProxyUser, $passwd)}Write-Debug "Using explicit proxy server '$explicitProxy'."$downloader.Proxy = $proxy} elseif (!$downloader.Proxy.IsBypassed($url)) {# system proxy (pass through)$creds = $defaultCredsif ($creds -eq $null) {Write-Debug 'Default credentials were null. Attempting backup method'$cred = get-credential$creds = $cred.GetNetworkCredential();}$proxyaddress = $downloader.Proxy.GetProxy($url).AuthorityWrite-Debug "Using system proxy server '$proxyaddress'."$proxy = New-Object System.Net.WebProxy($proxyaddress)$proxy.Credentials = $creds$downloader.Proxy = $proxy}}return $downloader
}function Download-File {param ([string]$url,[string]$file)$downloader = Get-Downloader $url$downloader.DownloadFile($url, $file)
}function Download-Package {param ([string]$packageODataSearchUrl,[string]$file)$downloader = Get-Downloader $packageODataSearchUrlWrite-Output "Querying latest package from $packageODataSearchUrl"[xml]$pkg = $downloader.DownloadString($packageODataSearchUrl)$packageDownloadUrl = $pkg.feed.entry.content.srcWrite-Output "Downloading $packageDownloadUrl to $file"$downloader.DownloadFile($packageDownloadUrl, $file)
}function Install-ChocolateyFromPackage {param ([string]$chocolateyPackageFilePath = ''
)if ($chocolateyPackageFilePath -eq $null -or $chocolateyPackageFilePath -eq '') {throw "You must specify a local package to run the local install."}if (!(Test-Path($chocolateyPackageFilePath))) {throw "No file exists at $chocolateyPackageFilePath"}$chocTempDir = Join-Path $env:TEMP "chocolatey"$tempDir = Join-Path $chocTempDir "chocInstall"if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)}$file = Join-Path $tempDir "chocolatey.zip"Copy-Item $chocolateyPackageFilePath $file -Force# unzip the packageWrite-Output "Extracting $file to $tempDir..."if ($unzipMethod -eq '7zip') {$7zaExe = Join-Path $tempDir '7za.exe'if (-Not (Test-Path ($7zaExe))) {Write-Output 'Downloading 7-Zip commandline tool prior to extraction.'# download 7zipDownload-File $7zipUrl "$7zaExe"}$params = "x -o`"$tempDir`" -bd -y `"$file`""# use more robust Process as compared to Start-Process -Wait (which doesn't# wait for the process to finish in PowerShell v3)$process = New-Object System.Diagnostics.Process$process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo($7zaExe, $params)$process.StartInfo.RedirectStandardOutput = $true$process.StartInfo.UseShellExecute = $false$process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden$process.Start() | Out-Null$process.BeginOutputReadLine()$process.WaitForExit()$exitCode = $process.ExitCode$process.Dispose()$errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:"switch ($exitCode) {0 { break }1 { throw "$errorMessage Some files could not be extracted" }2 { throw "$errorMessage 7-Zip encountered a fatal error while extracting the files" }7 { throw "$errorMessage 7-Zip command line error" }8 { throw "$errorMessage 7-Zip out of memory" }255 { throw "$errorMessage Extraction cancelled by the user" }default { throw "$errorMessage 7-Zip signalled an unknown error (code $exitCode)" }}} else {if ($PSVersionTable.PSVersion.Major -lt 5) {try {$shellApplication = new-object -com shell.application$zipPackage = $shellApplication.NameSpace($file)$destinationFolder = $shellApplication.NameSpace($tempDir)$destinationFolder.CopyHere($zipPackage.Items(),0x10)} catch {throw "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = 'false' and call install again to use 7zip to unzip. Error: `n $_"}} else {Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force}}# Call Chocolatey installWrite-Output 'Installing chocolatey on this machine'$toolsFolder = Join-Path $tempDir "tools"$chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1"& $chocInstallPS1Write-Output 'Ensuring chocolatey commands are on the path'$chocInstallVariableName = 'ChocolateyInstall'$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName)if ($chocoPath -eq $null -or $chocoPath -eq '') {$chocoPath = 'C:\ProgramData\Chocolatey'}$chocoExePath = Join-Path $chocoPath 'bin'if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower()) -eq $false) {$env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine);}Write-Output 'Ensuring chocolatey.nupkg is in the lib folder'$chocoPkgDir = Join-Path $chocoPath 'lib\chocolatey'$nupkg = Join-Path $chocoPkgDir 'chocolatey.nupkg'if (!(Test-Path $nupkg)) {Write-Output 'Copying chocolatey.nupkg is in the lib folder'if (![System.IO.Directory]::Exists($chocoPkgDir)) { [System.IO.Directory]::CreateDirectory($chocoPkgDir); }Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue}
}# Idempotence - do not install Chocolatey if it is already installed
if (!(Test-Path $ChocoInstallPath)) {# download the package to the local pathif (!(Test-Path $localChocolateyPackageFilePath)) {#Download-Package $searchUrl $localChocolateyPackageFilePath}# Install ChocolateyInstall-ChocolateyFromPackage $localChocolateyPackageFilePath
}
  1. 按照下载路径修改第46行:
    $localChocolateyPackageFilePath = ‘C:\choco\chocolatey.0.10.15.nupkg’
  2. 管理员身份打开powershell,跳转到setup.ps1目录, 执行
    iex .\setup.ps1
  3. 电脑如果安装360,记得点击允许~ 等待安装完成…
  4. 安装完成,输入choco小试一下, 下边开始品尝巧克力吧

Chocolatey离线安装相关推荐

  1. Chocolatey离线安装步骤

    Chocolatey在Windows上离线安装步骤 一.Chocolatey介绍 chocolatey是一个包管理工具,类似Node.docker.yarn等.而chocolatey又可以很方便地安装 ...

  2. Chocolatey离线安装方法

    By: Ailson Jack Date: 2020.05.05 个人博客:首页 | 说好一起走 本文在我博客的地址是:Chocolatey离线安装方法 | 说好一起走,排版更好,便于学习,也可以去我 ...

  3. Chocolatey 的安装

    1 Chocolatey 的安装 在国内这个工具不好安装,经常由于超时,不能成功. 前面两种方法是推荐的,但是不好用.最好使用第三种,即离线安装的方法. 安装的系统要求 (1) Windows 7+ ...

  4. VS Code 离线安装插件方法

    本文以离线安装 C/C++ 插件为例进说明,其它语言的插件的离线安装方法类似. 离线安装 C/C++ 插件相对比较麻烦一些,主要是因为 C/C++ 插件还依赖其他需要在线下载的组件: C/C++ la ...

  5. 离线安装Visual Studio Code插件

    在使用Visual Studio Code 开发时候,有时可能会碰到需要离线安装插件的情况.这时候就需要单独下载插件包,本文就以C/C++插件包为例说明如何离线安装Visual Studio Code ...

  6. Angular CLI在线安装和离线安装

    Angular CLI 安装方式 默认已经安装了 Node.js 和 npm 包管理器. 1. 在线安装 可以使用外网的情况下,可以使用在线安装的方式. 要使用 npm 命令全局安装 CLI,请打开终 ...

  7. Anaconda3 离线安装 Django-3.2.7 及依赖项setuptools、sqlparse 、asgiref、typing_extensions等模块

    目录 一.背景 二.离线安装 setuptools.sqlparse .asgiref.typing_extensions等依赖模块 三.离线安装django 一.背景 因为信息安全管理的规定,这台服 ...

  8. linux离线安装docker教程,Linux 离线安装docker的过程

    前言 有时候会遇到服务器不能联网的情况,这样就没法用yum安装软件,docker也是如此,针对这种情况,总结了一下离线安装docker的步骤 1. 准备docker离线包 下载需要安装的docker版 ...

  9. centos7离线安装ansible

    centos7离线安装ansible: 1.通过在线的centos7将rpm包下载好了,上传到指定服务器. 下载官方repo,rpm -iUvh http://dl.Fedoraproject.org ...

最新文章

  1. 学习Python,这22个包怎能不掌握?
  2. telegram 创建机器人
  3. JavaScipt30(第三个案例)(主要知识点:css变量)
  4. 从偏远的小山村出来的孩子,一路的 “辛酸史”
  5. 详解C语言中 # 和 ## 的用法
  6. php - preg_match
  7. 12-order by和group by 原理和优化 sort by 倒叙
  8. Struts2源码学习(一)——Struts2中的XWork容器
  9. async与await详解
  10. 提高sas安装成功率的方法
  11. 读书笔记-计算机视觉
  12. elasticsearch 更新数据 (部分字段更新)
  13. [CF235C] Cyclical Quest
  14. 固态硬盘SSD和机械硬盘哪个好?它们有什么区别?
  15. 关于CC的完全非线性椭圆方程一书的一些小结
  16. 工业交换机智能监控管理方案
  17. [BLE]低功耗蓝牙介绍
  18. events(事件触发器)
  19. 北京市中 高英语听说计算机考,北京市教育委员会关于听力及言语障碍考生参加2019年中考英语听说计算机考试有关事项的通知...
  20. 包,内部类,常用类,集合

热门文章

  1. I.MX6 FFmpeg 录制视频
  2. 推荐几个好用的Python国内镜像源
  3. 车辆姿态表达:旋转矩阵、欧拉角、四元数的转换以及eigen、matlab、pathon方法实现
  4. php 算页数,PHP 分页的计算
  5. 拥抱人工智能,从机器学习开始
  6. jdbc-01入门操作-实现对单表的CRUD操作和单元测试
  7. Bugku——可爱的故事
  8. 在阿里云服务器上配置端口步骤
  9. 1143 联络员(kruskal算法)
  10. 2013年版《史上最全的桌面级CPU天梯图》