Win10离线安装choco方案

news/2024/5/6 10:30:35/文章来源:https://blog.csdn.net/omaidb/article/details/126669503

Win10离线安装choco方案

    • 问题描述
    • 前置条件,下载必须的`nupkg`
    • 解决办法: 离线安装choco
      • 修改`install.ps1`脚本
        • 修改第46行:
        • 修改第277行:
      • `powersell`开启`信任脚本`策略
      • 以`管理员`powershell执行安装脚本
    • 结果验证

问题描述

安装choco的时候,总是超时失败.


前置条件,下载必须的nupkg

https://packages.chocolatey.org/chocolatey.0.10.15.nupkg
下载chocolatey.0.10.15.nupkg,和下面的install.ps1脚本放在同一目录。


解决办法: 离线安装choco

参考: https://blog.csdn.net/sw3114/article/details/104299003
choco官方离线安装方案: https://docs.chocolatey.org/en-us/choco/setup


修改install.ps1脚本

install.ps1内容如下,将该脚本保存到本地,和chocolatey.0.10.15.nupkg文件放在同一目录

# 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"
# 46行的变量值携程nupkg的路径,用单引号括起来
$localChocolateyPackageFilePath = 'E:\Downloads\choco\chocolatey.0.10.15.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)) {# 277行 Download-Package 这个注释掉# Download-Package $searchUrl $localChocolateyPackageFilePath}# Install ChocolateyInstall-ChocolateyFromPackage $localChocolateyPackageFilePath
}

修改第46行:

# 修改第46行的nupkg包路径
$localChocolateyPackageFilePath = 'nupkg包路径'

在这里插入图片描述


修改第277行:

# 第277行 Download-Package 这个注释掉
Download-Package $searchUrl $localChocolateyPackageFilePath

在这里插入图片描述


powersell开启信任脚本策略

# 开启信任脚本策略
set-ExecutionPolicy RemoteSigned

管理员powershell执行安装脚本

# 进入脚本所在目录
cd D:\Choco脚本所在目录# 执行安装脚本
iex install.ps1

结果验证

# 查看choco版本
choco -v

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_4981.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 动态更新Menu菜单

1. 需求描述 Android Menu菜单是比较常见的功能&#xff0c;在ActionBar or ToolBar上显示&#xff0c;点击更多(3个点)&#xff0c;会有下拉列表菜单展示, 在工作项目中有个小需求改动: 在 ToolBar上添加一个图标&#xff0c;点击后会切换图标状态&#xff0c;界面也会显示对…

搭建简易Spring-ioc框架

SpringFrameWork系列1 文章目录SpringFrameWork系列1一、谈谈对Spring的认识二、控制反转(ioc)的作用2.1 ioc的优缺点三、搭建Spring-ioc框架一、谈谈对Spring的认识 Spring是一个开源框架&#xff0c;是为了解决企业应用开发的复杂性而产生的。 特征&#xff1a;轻量级别&…

第66章 基于.Net(Core)x框架的开源分页插件

1 Jquery DataTable 分页插件 Jquery DataTable分页插件是完全基于javaScript的&#xff0c;所以它是跨框架的&#xff0c;即不管你使用的是那种语言&#xff0c;那种平台开发网站程序&#xff0c;基本上都能通过使用Jquery DataTable分页插件实现分页操作。 在nopCommerce开发…

TASK04分组|joyfulpandas

目录一、分组模式及其对象1. 分组的一般模式2. 分组依据的本质【练一练】【END】3.Groupby对象【练一练】【END】 size4. 分组的三大操作二、聚合函数1. 内置聚合函数【练一练】【END】2. agg方法【练一练】【练一练】【END】三、变换和过滤1. 变换函数与transform方法【练一练…

02|一条MySQL更新语句是如何执行的

02|一条MySQL更新语句是如何执行的 update T set cc1 where ID2;其实一条更新语句的执行操作和查询语句的执行操作基本相同->一条SQL查询语句是如何查询的&#xff1f;&#xff0c;唯一不同的是一条更新语句在执行过程中需要涉及到两个日志操作&#xff08;redo log、binlo…

四、集合

四、集合 集合和数组区别 &#xff08;1&#xff09;数组定长&#xff0c;集合不定长&#xff08;2&#xff09;数组可存基础数据类型和引用类型&#xff0c;集合只能存引用类型 位置&#xff1a;java.util.*; 这是一位仁兄的笔记&#xff0c;师出同门&#xff0c;点我跳转~ 1、…

高级js 面向对象 和面向过程 三种函数

判断数据类型 // 创建一个Cat对象&#xff0c;属性:颜色&#xff0c;品种&#xff0c;行为:吃&#xff0c;跑&#xff0c;捉老鼠var Cat new Object() //new一个对象Cat.catys red //属性Cat.catname cat //对象名// 行为Cat.catxw function () {console.log("喜欢跑&…

Python3,我用这种方式讲解python模块,80岁的奶奶都说能理解。建议收藏 ~ ~

Python模块讲解1、引言2、python模块详解2.1 含义2.2 代码示例2.3 进阶3、总结1、引言 小屌丝&#xff1a;鱼哥&#xff0c;你看天上的月亮越来越圆了。 小鱼&#xff1a;唉~ 又是一年团圆夜&#xff0c;又是一年中秋节。 小屌丝&#xff1a;嘿嘿&#xff0c;可不滴&#xff0…

二维凸包问题

什么是二维凸包 假设墙上顶一组钉子&#xff0c;这些钉子的集合为X&#xff0c;我们用橡皮筋围住这些钉子&#xff0c;橡皮筋的形状就是凸包(来源于网络)。 向量的叉乘 对于两个向量pq⃗\vec{pq}pq​和qr⃗\vec{qr}qr​ 如果pq⃗\vec{pq}pq​和qr⃗\vec{qr}qr​的叉积结果大于0…

分销商城小程序开发运营逻辑是什么?

商城分销现在用的人比较多&#xff0c;其中用的最多的差不多就是二级分销、三级分销&#xff0c;除了这两种分销方式&#xff0c;还有一种是一级分销&#xff0c;不过裂变效果可能不如二级分销、三级分销要好&#xff0c;所以用的人不是特别的多。 二级分销跟三级分销的逻辑都差…

C++PrimerPlus跟读记录【第五章】循环和关系表达式

1、for 循环 for(initialization; test-expression; updata-expression)test-expression 关系表达式&#xff0c;结果强制为bool类型&#xff0c;true or false。 表达式和语句 C表达式是 值 或 值与运算符的组合&#xff0c;每个表达式都有值。表达式只要加上分号&#xff0…

剑指offer32-42字符串数组的应用

剑指 Offer II 032. 有效的变位词 给定两个字符串 s 和 t &#xff0c;编写一个函数来判断它们是不是一组变位词&#xff08;字母异位词&#xff09;。t 是 s的变位词等价于「两个字符串不相等且两个字符串排序后相等」 注意&#xff1a;若 s 和 t 中每个字符出现的次数都相同…

QT QTextEdit富文本插入字体-表格-编号-图片-查找-语法高亮功能

QT QTextEdit富文本插入字体-表格-编号-图片与查找功能&#xff0c;输入char 自动变成蓝色-语法高亮功能 QTQTextEdit富文本插入字体-表格-编号-图片-查找-语法高亮功能.rar-QT文档类资源-CSDN下载QTQTextEdit富文本插入字体-表格-编号-图片-查找-语法高亮功能.rarhttps:/更多…

Vue使用脚手架(ref、props、mixin、插件、scoped)(七)

系列文章目录 第一章&#xff1a;Vue基础知识笔记&#xff08;模板语法、数据绑定、事件处理、计算属性&#xff09;&#xff08;一&#xff09; 第二章&#xff1a;Vue基础知识&#xff08;计算属性、监视属性、computed和watch之间的区别、绑定样式&#xff09;&#xff08;…

四、 java的对象和类

四、 java的对象和类 对象&#xff08;Object&#xff09;&#xff1a;对象是类的一个实例&#xff0c;有状态和行为。例如&#xff0c;一条狗是一个对象&#xff0c;它的状态有&#xff1a;颜色、名字、品种&#xff1b;行为有&#xff1a;摇尾巴、叫、吃等。类&#xff08;c…

物理服务器安装CentOS 7操作系统

目录 1、下载系统镜像 2、制作安装盘 2.1 方法一&#xff1a;光盘制作 2.2 方法二&#xff1a;U盘制作 3、更改bios启动顺序 4、安装CentOS 7操作系统 4.1 安装命令选择&#xff0c;及常见错误解决 4.2 语言选择 4.3 时区选择 4.4 软件选择 4.5 安装位置选择 4.6 手…

猿创征文|【C++游戏引擎Easy2D】学C++还不会绘制一个简单的二维图形?一篇文章教会你

&#x1f9db;‍♂️iecne个人主页&#xff1a;&#xff1a;iecne的学习日志 &#x1f4a1;每天关注iecne的作品&#xff0c;一起进步 &#x1f4aa;学C必看iecne 本文专栏&#xff1a;【C游戏引擎】. &#x1f433;希望大家多多支持&#x1f970;一起进步呀&#xff01; ✨前…

Apache Maven 3.6.0的下载安装和环境配置(详细图解+不限速下载链接)

标题工具/原料 apache-maven-3.6.0 下载地址 云盘不限速下载 或者进入官网按下图下载 方法/步骤一 安装 打开压缩包&#xff0c;将maven压缩包解压至软件安装处&#xff0c;建议D根目录或其他&#xff0c;记住安装位置 类似于 方法/步骤二 环境变量配置 变量 1.新建变…

Eolink 通过可信云权威认证,数据保护能力业内领先!

Eolink 正式通过由中国信息通信研究院组织发起的可信云评估考核&#xff0c;在数据安全保障领域获得权威认证&#xff0c;并荣获 “企业级 SaaS 服务” 认证证书。 在云时代&#xff0c;保护用户数据安全、预防隐私泄露是数字化企服厂商的重中之重。Eolink 作为一个 API 在线管…

计算机毕业设计ssm+vue基本微信小程序的个人健康管理系统

项目介绍 首先,论文一开始便是清楚的论述了小程序的研究内容。其次,剖析系统需求分析,弄明白“做什么”,分析包括业务分析和业务流程的分析以及用例分析,更进一步明确系统的需求。然后在明白了小程序的需求基础上需要进一步地设计系统,主要包罗软件架构模式、整体功能模块、数…