Windows 快速安装 wget 指南 🚀

一站式解决方案:从零开始安装 Chocolatey 包管理器并配置 wget 工具
📋 目录
一、管理员 PowerShell 打开方式 🪟
方法一:通过开始菜单
步骤 |
操作 |
截图提示 |
1 |
右键点击「开始」按钮或按 Win + X |
 |
2 |
选择「Windows PowerShell(管理员)」 |
|
3 |
如果出现 UAC(用户账户控制)弹窗,点击「是」 |
 |
方法二:通过搜索栏
- 按
Win + S
打开搜索栏
- 输入「PowerShell」
- 右侧选择「以管理员身份运行」
方法三:通过运行对话框
- 按
Win + R
打开运行对话框
- 输入「powershell」
- 按
Ctrl + Shift + Enter
以管理员身份运行
验证管理员权限
在打开的 PowerShell 窗口中输入以下命令验证权限:
1
| whoami /groups | findstr "S-1-16-12288"
|
如果显示结果中包含「Mandatory Label\High Mandatory Level」,则表示已获得管理员权限。
二、一键安装 Chocolatey + wget ⚙️
完整安装脚本
将以下完整脚本复制-粘贴-回车即可完成全部安装过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Write-Host "开始安装 Chocolatey 包管理器和 wget..." -ForegroundColor Green
Write-Host "步骤 1/4: 设置执行策略..." -ForegroundColor Yellow Set-ExecutionPolicy Bypass -Scope Process -Force -ErrorAction Stop
Write-Host "步骤 2/4: 配置网络安全协议..." -ForegroundColor Yellow [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Write-Host "步骤 3/4: 安装 Chocolatey 包管理器..." -ForegroundColor Yellow try { $chocoInstallScript = Invoke-WebRequest -Uri 'https://community.chocolatey.org/install.ps1' -UseBasicParsing -ErrorAction Stop Invoke-Expression $chocoInstallScript.Content Write-Host "✓ Chocolatey 安装成功" -ForegroundColor Green } catch { Write-Host "✗ Chocolatey 安装失败: $($_.Exception.Message)" -ForegroundColor Red exit 1 }
Write-Host "步骤 4/4: 安装 wget..." -ForegroundColor Yellow try { choco install wget -y --force --accept-license --no-progress Write-Host "✓ wget 安装成功" -ForegroundColor Green } catch { Write-Host "✗ wget 安装失败: $($_.Exception.Message)" -ForegroundColor Red exit 1 }
Write-Host "刷新环境变量..." -ForegroundColor Yellow refreshenv
Write-Host "安装完成!请重启 PowerShell 使更改生效。" -ForegroundColor Green Write-Host "使用 'wget --version' 验证安装。" -ForegroundColor Cyan
|
分步安装说明
如果您想了解每个步骤的作用,可以分步执行:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install wget -y
refreshenv
|
三、验证安装与配置 ✅
基本验证
安装完成后,重启 PowerShell 并运行以下命令验证安装:
1 2 3 4 5 6 7 8
| choco --version
wget --version
wget --help | more
|
环境变量验证
确保 wget 已正确添加到系统 PATH 中:
1 2 3 4 5 6 7 8 9 10 11 12
| Get-Command wget | Format-List
$env:PATH -split ';' | Select-String 'chocolatey'
$chocoPath = "$env:ProgramData\chocolatey\bin" if ($env:PATH -notcontains $chocoPath) { [Environment]::SetEnvironmentVariable("PATH", "$env:PATH;$chocoPath", [EnvironmentVariableTarget]::Machine) Write-Host "已添加 Chocolatey 到系统 PATH" -ForegroundColor Green }
|
测试下载功能
验证 wget 是否可以正常工作:
1 2 3 4 5 6 7 8
| wget -O test-download.txt "https://httpbin.org/get"
Get-Content test-download.txt
Remove-Item test-download.txt -Force
|
四、wget 使用指南 📥
基本下载命令
1 2 3 4 5 6 7 8 9 10 11
| wget https://example.com/file.zip
wget -O custom-name.zip https://example.com/file.zip
wget -c https://example.com/large-file.iso
wget -b https://example.com/large-file.iso
|
高级下载选项
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wget --limit-rate=100k https://example.com/large-file.iso
wget -t 5 https://example.com/file.zip
wget -T 30 https://example.com/file.zip
wget -r -l 2 https://example.com/
wget -mk https://example.com/
|
实用示例
1 2 3 4 5 6 7 8 9 10 11
| wget -c "https://dufs.mobufan.eu.org:666/file/myfile/docker/tvhelper.tar"
wget -i files.txt
wget -e use_proxy=yes -e http_proxy=127.0.0.1:8080 https://example.com/file.zip
wget --no-check-certificate https://example.com/file.zip
|
与 PowerShell 结合使用
1 2 3 4 5 6 7 8 9 10 11
| $url = "https://example.com/file.zip" $output = "downloaded-file.zip"
if (Get-Command wget -ErrorAction SilentlyContinue) { wget -O $output $url Write-Host "下载完成: $output" -ForegroundColor Green } else { Write-Host "wget 未安装,使用 PowerShell 替代方法" -ForegroundColor Yellow Invoke-WebRequest -Uri $url -OutFile $output }
|
五、常见问题与解决方案 🛠️
安装问题
问题现象 |
解决方案 |
无法识别 choco 命令 |
关闭并重新打开 PowerShell,或运行 refreshenv |
wget 不是内部或外部命令 |
检查 Chocolatey bin 目录是否在 PATH 中 |
执行策略错误 |
以管理员身份运行:Set-ExecutionPolicy RemoteSigned -Scope CurrentUser |
网络连接超时 |
检查代理设置或尝试使用镜像源 |
网络问题解决方案
1 2 3 4 5 6 7 8
| choco config set proxy http://proxy.example.com:8080
choco config unset proxy
choco config set cacheLocation C:\choco-cache
|
权限问题
1 2 3 4 5
| Start-Process powershell -Verb RunAs
icacls "$env:ProgramData\chocolatey" /reset /T
|
Chocolatey 故障排除
1 2 3 4 5 6 7 8
| choco list --local-only
choco upgrade chocolatey -y
choco optimize --reduce-nupkg-only
|
六、高级配置与优化 🔧
环境变量配置
1 2 3 4 5 6 7 8 9 10 11 12
| [Environment]::SetEnvironmentVariable("ChocolateyInstall", "$env:ProgramData\chocolatey", [EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("PATH", "$env:PATH;$env:ProgramData\chocolatey\bin", [EnvironmentVariableTarget]::Machine)
$wgetrcPath = "$env:USERPROFILE\.wgetrc" @" # 默认设置 quiet = on dir_prefix = ./ progress = bar "@ | Set-Content -Path $wgetrcPath -Force
|
性能优化
1 2 3 4 5
| wget --span-hosts --level=inf --recursive --no-parent --no-clobber --page-requisites --adjust-extension --convert-links --restrict-file-names=windows --random-wait -e robots=off --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" https://example.com/
choco install aria2 -y
|
安全配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| $verificationScript = @" # 验证 Chocolatey 安装 if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { Write-Error "Chocolatey 未正确安装" exit 1 }
# 验证 wget 安装 if (-not (Get-Command wget -ErrorAction SilentlyContinue)) { Write-Error "wget 未正确安装" exit 1 }
Write-Host "所有组件验证通过" -ForegroundColor Green "@
Set-Content -Path "$env:USERPROFILE\verify-install.ps1" -Value $verificationScript
|
七、替代安装方法 🔄
方法一:手动安装 wget(无需 Chocolatey)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| $wgetUrl = "https://eternallybored.org/misc/wget/current/wget.exe" $wgetPath = "$env:SYSTEMROOT\System32\wget.exe"
try { Invoke-WebRequest -Uri $wgetUrl -OutFile $wgetPath -ErrorAction Stop Write-Host "wget 手动安装成功" -ForegroundColor Green } catch { Write-Host "手动安装失败: $($_.Exception.Message)" -ForegroundColor Red }
if (Test-Path $wgetPath) { Write-Host "wget 已安装到: $wgetPath" -ForegroundColor Green }
|
方法二:使用 Scoop 包管理器
1 2 3 4 5 6 7 8 9
| Set-ExecutionPolicy RemoteSigned -Scope CurrentUser Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop install wget
scoop list
|
方法三:使用 Winget(Windows 官方包管理器)
1 2 3 4 5 6 7 8
| if (Get-Command winget -ErrorAction SilentlyContinue) { winget install -e --id GnuWin32.Wget Write-Host "已使用 Winget 安装 wget" -ForegroundColor Green } else { Write-Host "Winget 不可用,请使用其他方法" -ForegroundColor Yellow }
|
方法比较
方法 |
优点 |
缺点 |
推荐度 |
Chocolatey |
软件丰富,社区活跃 |
需要管理员权限 |
⭐⭐⭐⭐⭐ |
手动安装 |
简单直接,无需额外工具 |
需要手动更新 |
⭐⭐⭐ |
Scoop |
用户级安装,无需管理员 |
软件库相对较小 |
⭐⭐⭐⭐ |
Winget |
微软官方,系统集成 |
软件数量有限 |
⭐⭐⭐⭐ |
🎯 总结
通过本指南,您已经学会了:
- 多种方式在 Windows 上安装 wget 工具
- 一键脚本快速安装 Chocolatey + wget
- 验证方法确保安装正确无误
- 使用技巧充分发挥 wget 的功能
- 故障排除解决常见安装问题
- 替代方案应对不同环境需求
现在您可以享受 Linux 风格的下载体验了!使用 wget -c URL
开始您的下载之旅吧!🚀
💡 提示:建议定期更新 Chocolatey 和已安装的软件包: