You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 17.10终端语言乱码问题求解(不修改系统主语言)

Fix Korean Comment Garbling in Terminal (Without Changing System Language)

Got it, I’ve run into this exact issue before—having non-ASCII comments (like Korean) show up as gibberish in the terminal while keeping the system set to English. Here’s how to fix it step by step:

1. Verify and Adjust Terminal Encoding Settings

First, make sure your terminal is using UTF-8 (the universal encoding that supports all languages, including Korean).

For Linux/macOS (bash/zsh)

  • Check your current terminal encoding:
    echo $LANG
    
    If the output isn’t en_US.UTF-8 (or another English UTF-8 variant), that’s likely the problem.
  • Temporary fix (applies to current session only):
    export LANG=en_US.UTF-8
    
  • Permanent fix (saves for future sessions):
    Open your shell config file (.bashrc for bash, .zshrc for zsh) with a text editor, add the line above, then reload the config:
    source ~/.bashrc  # or ~/.zshrc
    

For Windows Terminal/PowerShell

  • Open Terminal Settings (press Ctrl+,), select your profile (e.g., WSL Ubuntu, PowerShell).
  • Under Appearance, set the font to a Korean-compatible one like Malgun Gothic or Noto Sans CJK KR.
  • Under Advanced, set Character encoding to UTF-8.
  • Save settings and restart the terminal.

2. Ensure Your Source File Uses UTF-8 Encoding

Sometimes the issue isn’t the terminal—it’s the file itself using an old Korean-specific encoding like EUC-KR.

  • Check the file’s encoding:
    file --mime-encoding your_code_file.ext
    
  • If it’s not UTF-8, convert it:
    Use iconv for command-line conversion:
    iconv -f EUC-KR -t UTF-8 old_file.py > new_file.py
    
    Or use Vim to convert and save:
    1. Open the file in Vim: vim your_code_file.ext
    2. Set encoding to UTF-8: :set fileencoding=utf-8
    3. Save and exit: :wq

3. Use Terminal Tools That Support Multilingual Rendering

Some basic tools might need extra flags to display non-ASCII characters correctly:

  • When using less, add the -r flag to render special characters:
    less -r your_code_file.ext
    
  • For Vim users, ensure Vim’s global encoding is set to UTF-8:
    Add this line to your ~/.vimrc (Linux/macOS) or %USERPROFILE%\_vimrc (Windows):
    set encoding=utf-8 fileencoding=utf-8
    

Quick Note

If you’re still seeing gibberish, try switching to a modern terminal emulator like iTerm2 (macOS), GNOME Terminal (Linux), or Windows Terminal—these have better out-of-the-box support for multilingual characters than older terminals.

内容的提问来源于stack exchange,提问作者Arthur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:05:06