Home  >  Q&A  >  body text

linux - iterm 配置utf8编码,本地终端中文不乱码,ssh远程中文乱码,咋整啊

高洛峰高洛峰2729 days ago935

reply all(4)I'll reply

  • PHPz

    PHPz2017-04-17 12:08:30

    Edit the ~/.vimrc file and add the following lines:
    set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
    set termencoding=utf-8
    set encoding=utf-8

    http://blog.icodu.com/?p=560

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 12:08:30

    I encountered the same problem, mainly because the language encoding of the remote server was inconsistent with the encoding of the terminal.

    Add the following code to the ~/.bashrc file on the remote server:

    export LANG='UTC-8'
    export LC_ALL='en_US.UTF-8'

    Then bash it and the Chinese will be displayed normally.

    The .bashrc file will run automatically next time you log in, and Chinese will still be displayed normally.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 12:08:30

    The reason why the encoding of remote terminal and local terminal does not match

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:08:30

    Question:

    The server is ubuntu, and I use Mac’s iterm2 ssh to connect to it. The terminal displays garbled Chinese characters and cannot input Chinese, but the local terminal can display and input.

    Solution:

    This situation is usually caused by the character set mismatch between the terminal and the server. The default character set under MacOSX is utf8.
    Enter locale to view the character encoding settings, but my corresponding value is empty.
    Because I replaced zsh with bash both locally and on the server, and used oh-my-zsh, and the default .zshrc is not set to utf-8 encoding, so both the local and server sides must be in .zshrc Settings, the steps are as follows, bash corresponds to .bash_profile or .bashrc files.

    1. Enter

    in the terminal
    vim ~/.zshrc

    Or use your favorite editor to edit the ~/.zshrc file
    <!--more-->

    2. Add:

    at the end of the file content
    export LC_ALL=en_US.UTF-8  
    export LANG=en_US.UTF-8

    Then restart the terminal, or enter source ~/.zshrc to make the settings take effect.

    If the setting is successful, enter locale and press Enter locally and when logging in to the server, the following content will be displayed.

    LANG="en_US.UTF-8"
    LC_COLLATE="en_US.UTF-8"
    LC_CTYPE="en_US.UTF-8"
    LC_MESSAGES="en_US.UTF-8"
    LC_MONETARY="en_US.UTF-8"
    LC_NUMERIC="en_US.UTF-8"
    LC_TIME="en_US.UTF-8"
    LC_ALL="en_US.UTF-8"

    At this time, Chinese input and display are normal.

    reply
    0
  • Cancelreply