Ubuntu 17.10终端语言乱码问题求解(不修改系统主语言)
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:
If the output isn’techo $LANGen_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 (.bashrcfor bash,.zshrcfor 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:
Useiconvfor command-line conversion:
Or use Vim to convert and save:iconv -f EUC-KR -t UTF-8 old_file.py > new_file.py- Open the file in Vim:
vim your_code_file.ext - Set encoding to UTF-8:
:set fileencoding=utf-8 - Save and exit:
:wq
- Open the file in Vim:
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-rflag 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

