【前提】因为要安装gitleaks所以第一步是安装chocolatey,然后一直报基础连接关闭错误。
尝试了ps1直接执行不生效,还是这个报错。也做了清除历史c盘文件路径,再次执行还是报错
1.尝试操作步骤报错

2.nupkg尝试、命令执行尝试都不行

【可行方案】
检查了framework版本,tls也正常,采取离线安装
1.我们需要先把 .nupkg 重命名为 .zip,再进行解压和安装:Release 2.6.0 · chocolatey/choco · GitHub
- 下载
chocolatey.2.6.0.nupkg - 重命名文件把你的
chocolatey.2.6.0.nupkg重命名为chocolatey.2.6.0.zip。直接改名字就行
-
执行修正后的脚本以管理员身份运行以下脚本(注意路径要和你实际的文件路径一致):
# 配置路径
$chocoPackage = "D:\10stools\00gitleaks\chocolatey.2.6.0.zip" # 注意这里是 .zip
$installDir = "C:\ProgramData\chocolatey"
$tempDir = "$installDir\temp"
try {
# 检查安装包
if (-not (Test-Path -Path $chocoPackage -PathType Leaf)) {
throw "Chocolatey package not found at: $chocoPackage"
}
Write-Host "[1/5] Package verified." -ForegroundColor Cyan
# 创建目录
if (-not (Test-Path -Path $installDir)) {
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
Write-Host "[2/5] Created directory: $installDir" -ForegroundColor Green
}
# 清理临时目录
if (Test-Path -Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction Stop
}
# 解压(现在是 .zip 文件,可以正常解压)
Expand-Archive -Path $chocoPackage -DestinationPath $tempDir -Force -ErrorAction Stop
Write-Host "[3/5] Extracted package." -ForegroundColor Green
# 移动核心文件
$chocoInstallSource = "$tempDir\tools\chocolateyInstall"
if (Test-Path -Path $chocoInstallSource) {
Copy-Item -Path "$chocoInstallSource\*" -Destination $installDir -Recurse -Force -ErrorAction Stop
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "[4/5] Copied files." -ForegroundColor Green
} else {
throw "Core files not found in package."
}
# 添加到PATH
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
$chocoBinPath = "$installDir\bin"
if ($currentPath -notlike "*$chocoBinPath*") {
[Environment]::SetEnvironmentVariable('PATH', "$currentPath;$chocoBinPath", 'Machine')
Write-Host "[5/5] Added to PATH." -ForegroundColor Green
}
Write-Host "`n✅ Installation completed! Close and re-open PowerShell, then run 'choco --version'." -ForegroundColor Green
}
catch {
Write-Host "`n❌ Failed: $($_.Exception.Message)" -ForegroundColor Red
if (Test-Path -Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
exit 1
}
3.此时差不多有的人能成功了。但是choco -v查不到文件(因为 PATH 里没有包含 choco.exe 的路径,所以 PowerShell 找不到这个命令),这个时候到c盘路径下,看exe是否都下载过来了,如果有的话,那就是环境变量不对,或者没设置过来。 新建个空白bin把3个关于exe的挪进去,查询就ok
安装效果:



914

被折叠的 条评论
为什么被折叠?



