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
|
# Windows wget 一键安装脚本
# 作者: Mobufan
# 日期: $(Get-Date -Format "yyyy-MM-dd")
Write-Host "开始安装 Chocolatey 包管理器和 wget..." -ForegroundColor Green
# 1. 设置执行策略(允许脚本运行)
Write-Host "步骤 1/4: 设置执行策略..." -ForegroundColor Yellow
Set-ExecutionPolicy Bypass -Scope Process -Force -ErrorAction Stop
# 2. 设置安全协议(支持 TLS 1.2)
Write-Host "步骤 2/4: 配置网络安全协议..." -ForegroundColor Yellow
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# 3. 安装 Chocolatey
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
}
# 4. 安装 wget
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
}
# 5. 刷新环境变量
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
|
# 步骤 1: 允许 PowerShell 执行脚本
Set-ExecutionPolicy Bypass -Scope Process -Force
# 步骤 2: 启用 TLS 1.2 支持(解决某些网络环境问题)
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# 步骤 3: 下载并安装 Chocolatey
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# 步骤 4: 使用 Chocolatey 安装 wget
choco install wget -y
# 步骤 5: 刷新环境变量
refreshenv
|
三、验证安装与配置 ✅
基本验证
安装完成后,重启 PowerShell 并运行以下命令验证安装:
1
2
3
4
5
6
7
8
|
# 检查 Chocolatey 版本
choco --version
# 检查 wget 版本
wget --version
# 检查 wget 帮助信息
wget --help | more
|
环境变量验证
确保 wget 已正确添加到系统 PATH 中:
1
2
3
4
5
6
7
8
9
10
11
12
|
# 检查 wget 可执行文件位置
Get-Command wget | Format-List
# 检查 PATH 环境变量
$env:PATH -split ';' | Select-String 'chocolatey'
# 手动添加 Chocolatey bin 目录到 PATH(如果需要)
$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
|
# 限速下载(限制为 100k/s)
wget --limit-rate=100k https://example.com/large-file.iso
# 重试次数(默认 20 次)
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
|
# 下载 Docker 镜像备份
wget -c "https://dufs.mobufan.eu.org:666/file/myfile/docker/tvhelper.tar"
# 下载多个文件
wget -i files.txt # files.txt 包含多个 URL
# 使用代理下载
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
|
# 在 PowerShell 脚本中使用 wget
$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
|
# 设置 Chocolatey 代理
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
|
# 以管理员身份运行 PowerShell
Start-Process powershell -Verb RunAs
# 修复 Chocolatey 安装权限
icacls "$env:ProgramData\chocolatey" /reset /T
|
Chocolatey 故障排除
1
2
3
4
5
6
7
8
|
# 检查 Chocolatey 状态
choco list --local-only
# 修复 Chocolatey 安装
choco upgrade chocolatey -y
# 清理 Chocolatey 缓存
choco optimize --reduce-nupkg-only
|
六、高级配置与优化 🔧
环境变量配置
1
2
3
4
5
6
7
8
9
10
11
12
|
# 永久设置 Chocolatey 环境变量
[Environment]::SetEnvironmentVariable("ChocolateyInstall", "$env:ProgramData\chocolatey", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("PATH", "$env:PATH;$env:ProgramData\chocolatey\bin", [EnvironmentVariableTarget]::Machine)
# 自定义 wget 配置文件
$wgetrcPath = "$env:USERPROFILE\.wgetrc"
@"
# 默认设置
quiet = on
dir_prefix = ./
progress = bar
"@ | Set-Content -Path $wgetrcPath -Force
|
性能优化
1
2
3
4
5
|
# 设置 wget 并发连接数
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/
# 使用 aria2 加速下载(如已安装)
choco install aria2 -y
|
安全配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# 创建 Chocolatey 安装验证脚本
$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
|
# 下载官方 wget for Windows
$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
|
# 安装 Scoop
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
# 使用 Scoop 安装 wget
scoop install wget
# 验证 Scoop 安装
scoop list
|
方法三:使用 Winget(Windows 官方包管理器)
1
2
3
4
5
6
7
8
|
# 检查 Winget 是否可用
if (Get-Command winget -ErrorAction SilentlyContinue) {
# 使用 Winget 安装 wget
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 和已安装的软件包: