安装 Chocolatey报错

【前提】因为要安装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。直接改名字就行
  1. 执行修正后的脚本以管理员身份运行以下脚本(注意路径要和你实际的文件路径一致):
# 配置路径
$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

安装效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值