<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>setlocale &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/setlocale/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Sat, 07 Nov 2020 15:16:55 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>setlocale &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</title>
		<link>https://noter.tw/396/ubuntu-16-04-%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%aa%9e%e8%a8%80%e7%b7%a8%e7%a2%bc%ef%bc%8c%e8%ae%93%e4%b8%ad%e6%96%87%e5%8f%af%e4%bb%a5%e6%ad%a3%e5%b8%b8%e9%a1%af%e7%a4%ba/</link>
					<comments>https://noter.tw/396/ubuntu-16-04-%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%aa%9e%e8%a8%80%e7%b7%a8%e7%a2%bc%ef%bc%8c%e8%ae%93%e4%b8%ad%e6%96%87%e5%8f%af%e4%bb%a5%e6%ad%a3%e5%b8%b8%e9%a1%af%e7%a4%ba/#comments</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sat, 01 Dec 2018 07:57:13 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[中文亂碼]]></category>
		<category><![CDATA[.bashrc]]></category>
		<category><![CDATA[setlocale]]></category>
		<category><![CDATA[locale-gen]]></category>
		<category><![CDATA[update-locale]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=396</guid>

					<description><![CDATA[<p>有了自己的域名，申請了 VPS，在 VPS 中安裝了 Ubuntu 之後，就來開始進行設定，小蛙用比較久的版本是 Ubuntu 16.04 (64 bit)，可以發現除了早期有 Ubuntu 12.0&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/396/ubuntu-16-04-%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%aa%9e%e8%a8%80%e7%b7%a8%e7%a2%bc%ef%bc%8c%e8%ae%93%e4%b8%ad%e6%96%87%e5%8f%af%e4%bb%a5%e6%ad%a3%e5%b8%b8%e9%a1%af%e7%a4%ba/" data-wpel-link="internal">Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>

有了自己的域名，申請了 VPS，在 VPS 中安裝了 Ubuntu 之後，就來開始進行設定，小蛙用比較久的版本是 Ubuntu 16.04 (64 bit)，可以發現除了早期有 Ubuntu 12.04 或是一些其他狀況需要碰到 CentOS，不然大多使用自己熟悉的 Ubuntu 16.04。

</p>



<span id="more-396"></span>



<script type="application/ld+json">{    "@context": "http://schema.org",        "@type": "VideoObject",    "name": "【 Ubuntu 相關 】Ubuntu 16 04 設定環境語言編碼，讓中文可以正常顯示",    "description": "請開啟 CC 字幕  完整文章內容請參考：https://noter.tw/396 （記下來 - 專業偽筆記）",    "thumbnailUrl": "https://img.youtube.com/vi/6HOw_BMuKxc/sddefault.jpg",    "uploadDate": "2018-12-06T09:36:19Z",    "duration": "PT1M26S",    "contentUrl": "https://www.youtube.com/watch?v=0blDh7s62Pw"}</script>




<div class="wp-block-image"><figure class="aligncenter"><img fetchpriority="high" decoding="async" width="673" height="380" src="https://noter.tw/wp-content/uploads/vim_garbled.png" alt="vim garbled Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示" class="wp-image-425" title="Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示" srcset="https://noter.tw/wp-content/uploads/vim_garbled.png 673w, https://noter.tw/wp-content/uploads/vim_garbled-300x169.png 300w" sizes="(max-width: 673px) 100vw, 673px" /></figure></div>



<p>

預設安裝好 Ubuntu 16.04 後的編碼應該是 en_US，所以如果透過 Pietty SSH 進去主機會發現很多中文的部份沒辦法正確呈現，甚至嚴重一點的會讓 vim 沒辦法正常使用，這篇記錄一下怎麼解決的這個問題。

</p>



<h2 class="para wp-block-heading">手動設定 .bashrc</h2>



<p>

.bashrc 這檔案會在每個使用者的家目錄中，如：<code>/root/.bashrc</code>、<code>/home/xxxx/.bashrc</code>，每次只要有 ssh 遠端登入時，就會載入該使用者家目錄下的 .bashrc。

</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">############## 顯示中文問題 ##################
// 編輯自己家目錄下的 bash 環境
vim .bashrc
// 在最下面加入這些設定
export LANGUAGE="zh_TW.UTF-8"
export LANG="zh_TW.UTF-8"
export LC_ALL="zh_TW.UTF-8"
// 使用 source 讓設定檔生效時，發生以下錯誤
source .bashrc
-bash: warning: setlocale: LC_ALL: cannot change locale (zh_TW.UTF-8)
// 透過 locale-gen 產生 zh_TW.UTF-8 的語系
sudo locale-gen zh_TW.UTF-8
sudo update-locale LANG=zh_TW.UTF-8
// 完成後重新登入即可</pre>



<h2 class="para wp-block-heading">使用腳本自動設定 .bashrc</h2>



<p>

也可以直接把上面的功能寫成一個腳本

</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">#!/bin/bash
apt-get update
apt-get install -y locales
locale-gen zh_TW.UTF-8
echo 'export LANGUAGE="zh_TW.UTF-8"' &gt;&gt; /root/.bashrc
echo 'export LANG="zh_TW.UTF-8"' &gt;&gt; /root/.bashrc
echo 'export LC_ALL="zh_TW.UTF-8"' &gt;&gt; /root/.bashrc
update-locale LANG=zh_TW.UTF-8</pre>



<p>

複製上面的內容存成 setLang.sh，接著

</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">chmod +x setLang.sh
./setLang.sh  
source /root/.bashrc</pre>



<p> 等他跑完就可以正常顯示中文囉！附上影片，小蛙的 <a rel="noreferrer noopener nofollow external" href="https://www.youtube.com/channel/UCy6ZklcNv5fmqy6USd2FgQg/" target="_blank" data-wpel-link="external" class="wpel-icon-right">YouTube 頻道 &#8211; 記下來<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 還有更多不同主題的影片，有興趣可以過去看看！ </p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="video-container"><iframe title="Ubuntu 設定環境語言編碼，讓中文可以正常顯示 | 記下來" width="500" height="375" src="https://www.youtube.com/embed/6HOw_BMuKxc?feature=oembed&#038;wmode=opaque" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>



<p><strong>網站架設系列文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/10151/%e7%9b%a4%e9%bb%9e%e9%82%a3%e4%ba%9b%e6%9b%be%e7%b6%93%e9%99%aa%e4%bc%b4%e9%81%8e%e5%b0%8f%e8%9b%99%e7%9a%84-vps-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f/" data-wpel-link="internal">盤點那些曾經陪伴過小蛙的 VPS 虛擬主機</a></li><li><a href="https://noter.tw/176/%e5%a6%82%e4%bd%95%e6%8c%91%e9%81%b8-vps-%e6%9c%80%e5%88%92%e7%ae%97%e7%9a%84%e8%b2%b7%e6%b3%95/" data-wpel-link="internal">如何挑選 VPS + 最划算的買法</a></li><li><a href="https://noter.tw/406/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E5%A6%82%E4%BD%95%E8%B3%BC%E8%B2%B7-vps/" data-wpel-link="internal">手把手教你如何購買 VPS</a></li><li><a href="https://noter.tw/4463/第一次買-kvm-虛擬主機/" data-wpel-link="internal">第一次買 KVM 虛擬主機</a></li><li><a href="https://noter.tw/4242/%e8%a1%80%e7%9a%84%e6%95%99%e8%a8%93-hiformance-%e8%b7%91%e8%b7%af%e4%ba%86/" data-wpel-link="internal">血的教訓 &#8211; HiFormance 跑路了 &#8230;</a></li><li><a href="https://noter.tw/196/%e7%82%ba%e8%87%aa%e5%b7%b1%e7%94%b3%e8%ab%8b%e4%b8%80%e5%80%8b%e5%9f%9f%e5%90%8d-hinet-%e7%82%ba%e4%be%8b/" data-wpel-link="internal">為自己申請一個域名 – HiNet 為例</a></li><li><a href="https://noter.tw/117/cloudflare-%E8%B6%85%E5%BC%B7%E5%A4%A7%E7%9A%84%E5%85%8D%E8%B2%BB-cdn/" data-wpel-link="internal">Cloudflare – 超強大的免費 CDN (?)</a></li><li><a href="https://noter.tw/195/%e4%bd%bf%e7%94%a8-cloudflare-%e4%bb%a3%e7%ae%a1%e4%bd%a0%e7%9a%84%e5%9f%9f%e5%90%8d/" data-wpel-link="internal">使用 Cloudflare 代管你的域名</a></li><li><a href="https://noter.tw/396/ubuntu-16-04-設定環境語言編碼，讓中文可以正常顯示/" data-wpel-link="internal">Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</a></li><li><a href="https://noter.tw/255/ubuntu-16-04-%e5%ae%89%e8%a3%9d-fail2ban/" data-wpel-link="internal">Ubuntu 16.04 安裝 fail2ban</a></li><li><a href="https://noter.tw/436/%E4%B8%80%E5%80%8B%E8%85%B3%E6%9C%AC%E6%AF%8F%E5%A4%A9%E8%87%AA%E5%8B%95%E5%82%99%E4%BB%BD/" data-wpel-link="internal">一個腳本每天自動備份</a></li><li><a href="https://noter.tw/32/linux-tar-%E5%AE%8C%E6%95%B4%E5%82%99%E4%BB%BD%E3%80%81%E5%A2%9E%E9%87%8F%E5%82%99%E4%BB%BD%E5%8F%8A%E5%B7%AE%E7%95%B0%E5%82%99%E4%BB%BD%E6%AF%94%E8%BC%83/" data-wpel-link="internal">Linux tar 完整備份、增量備份及差異備份比較</a></li><li><a href="https://noter.tw/3704/nginx-ssl-certificate-%E8%AE%93-http-%E8%AE%8A%E8%BA%AB%E6%88%90%E7%82%BA-https/" data-wpel-link="internal">nginx + SSL Certificate – 讓 http 變身成為 https</a></li><li><a href="https://noter.tw/3695/ssl-for-free-%E5%85%8D%E8%B2%BB%E5%8F%88%E6%9C%89%E7%B6%A0%E8%89%B2%E9%8E%96%E9%A0%AD%E7%9A%84-ssl-certificates/" data-wpel-link="internal">SSL For Free – 免費又有綠色鎖頭的 SSL Certificates</a></li><li><a href="https://noter.tw/8596/certbot-error/" data-wpel-link="internal">Certbot 申請 SSL certificate 錯誤問題</a></li><li><a href="https://noter.tw/9107/certbot-error-acmev1-is-deprecated/" data-wpel-link="internal">Certbot 錯誤：ACMEv1 is deprecated and you can …</a></li><li><a href="https://noter.tw/5967/ubuntu-18-04-%e5%ae%89%e8%a3%9d-awstats-%e4%be%86%e7%b5%b1%e8%a8%88%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f/" data-wpel-link="internal">Ubuntu 18.04 安裝 AWStats 來統計網站流量</a></li><li><a href="https://noter.tw/9287/pchome-%e8%b2%b7%e7%b6%b2%e5%9d%80%e7%ba%8c%e7%b4%84%e6%b5%81%e7%a8%8b/" data-wpel-link="internal">PCHome 買網址續約流程</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/396/ubuntu-16-04-%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%aa%9e%e8%a8%80%e7%b7%a8%e7%a2%bc%ef%bc%8c%e8%ae%93%e4%b8%ad%e6%96%87%e5%8f%af%e4%bb%a5%e6%ad%a3%e5%b8%b8%e9%a1%af%e7%a4%ba/" data-wpel-link="internal">Ubuntu 16.04 設定環境語言編碼，讓中文可以正常顯示</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/396/ubuntu-16-04-%e8%a8%ad%e5%ae%9a%e7%92%b0%e5%a2%83%e8%aa%9e%e8%a8%80%e7%b7%a8%e7%a2%bc%ef%bc%8c%e8%ae%93%e4%b8%ad%e6%96%87%e5%8f%af%e4%bb%a5%e6%ad%a3%e5%b8%b8%e9%a1%af%e7%a4%ba/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
