windows 11 配置 UTF-8

34 阅读1分钟

windows 11 配置 UTF-8

  1. 打开控制面板,选择区域

image.png

  1. 选择 更改系统位置

image.png

  1. 勾选 UTF-8 支持

image.png

  1. 重启电脑(必须)

PowerShell 配置 UTF-8

完成 windows 11 配置 UTF-8 后检查 PowerShell对 UTF-8 的支持

检查当前代码页与编码配置

chcp          # 正常应为65001(UTF-8),乱码时可能显示936(GBK)
$OutputEncoding
[Console]::OutputEncoding
[Console]::InputEncoding

如果上述 $OutputEncoding 打印结果不是 UTF-8,创建 PowerShell 配置文件,通过加载配置文件的方式,让 PowerShell 每次启动自动设置 UTF-8 编码

  1. 以管理员身份打开 PowerShell,执行:

# 若文件不存在,先创建 
if (-not (Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force } 

# 打开配置文件
notepad $PROFILE 
  1. 添加以下内容:
#  强制PowerShell使用UTF-8编码
chcp 65001 > $null
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8

3. 允许 PowerShell 加载配置(需要管理员权限)

Set-ExecutionPolicy RemoteSigned

4. 重启 PowerShell 并验证

$OutputEncoding