AlpineLinx添加中文支持
alpine默认是没有语言环境的,没有中文对于我们查看中文文档或者软件的中文帮助文档带来了一定麻烦。座椅下面的步骤将针对alpine的系统添加中文支持。
查看当前语言环境
localhost:~# echo $LANG
C.UTF-8
使用locale命令查看当前系统语言包时,也会发现,没有locale命令
localhost:~# locale -a
-sh: locale: not found
网上世界找到关于locales命令的解决方案都是apk add locales软件包安装,但我使用3.20版本安装时,提升仓库没有这个包。Linux世界解决问题的方法不存在唯一性,所以我找了别的方式来配置中文支持,下面就是这种方法的步骤:
安装中文字体以支持中文显示
在配置中文支持之前,先安装中文字体和做一下字体的配置,以便后面添加了中文支持的配置后,可以把中文显示出来。
localhost:~# apk add ttf-dejavu fontconfig
fetch http://mirrors.ustc.edu.cn/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.ustc.edu.cn/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
(1/1) Installing font-dejavu (2.37-r5)
Executing fontconfig-2.15.0-r1.trigger
Executing mkfontscale-1.2.2-r6.trigger
OK: 3413 MiB in 1051 packages
配置字体缓存,生成字体缓存,以便系统可以正确显示中文字体。
localhost:~# mkfontscale && mkfontdir && fc-cache
安装认证工具和wget下载工具并下载安装glibc软件包
先安装公私钥的认证工具和wget这个下载工具
localhost:~# apk --no-cache add ca-certificates wget
fetch http://mirrors.ustc.edu.cn/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.ustc.edu.cn/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
(1/1) Installing wget (1.24.5-r0)
Executing busybox-1.36.1-r29.trigger
OK: 3414 MiB in 1052 packages
安装完成就先下载公钥,用于后面咱们下载三个glibc的软件包时校验使用
localhost:~# wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
下载三个glibc的软件包,我们先进入到home目录,以免下载软件包乱放,不好管理。
localhost:~# cd ~
localhost:~# wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk
--2024-10-17 21:06:13-- https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-8e08-71fbbd012f31?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T130613Z&X-Amz-Expires=300&X-Amz-Signature=bd1db5fc82fe44be1ef830529ef8e369e03bf151de108c438e8aa414c7f50523&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive [following]
--2024-10-17 21:06:13-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-8e08-71fbbd012f31?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T130613Z&X-Amz-Expires=300&X-Amz-Signature=bd1db5fc82fe44be1ef830529ef8e369e03bf151de108c438e8aa414c7f50523&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4451131 (4.2M) [application/vnd.android.package-archive]
Saving to: 'glibc-2.33-r0.apk'glibc-2.33-r0.apk 100%[===========================================>] 4.24M 33.4KB/s in 1m 53s2024-10-17 21:08:08 (38.3 KB/s) - 'glibc-2.33-r0.apk' saved [4451131/4451131]localhost:~#
localhost:~# wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-bin-2.33-r0.apk
--2024-10-17 21:08:08-- https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-bin-2.33-r0.apk
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-964b-dba165a6f6bd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T130808Z&X-Amz-Expires=300&X-Amz-Signature=9131192a4e87c7a55dd3fa328f6cceea2f3e941d9bfed1283f1d704c4dfe20fd&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-bin-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive [following]
--2024-10-17 21:08:09-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-964b-dba165a6f6bd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T130808Z&X-Amz-Expires=300&X-Amz-Signature=9131192a4e87c7a55dd3fa328f6cceea2f3e941d9bfed1283f1d704c4dfe20fd&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-bin-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.109.133, 185.199.108.133, 185.199.111.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1035706 (1011K) [application/vnd.android.package-archive]
Saving to: 'glibc-bin-2.33-r0.apk'glibc-bin-2.33-r0.apk 100%[===========================================>] 1011K 581KB/s in 1.7s2024-10-17 21:08:11 (581 KB/s) - 'glibc-bin-2.33-r0.apk' saved [1035706/1035706]localhost:~# wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-i18n-2.33-r0.apk
--2024-10-17 21:10:47-- https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-i18n-2.33-r0.apk
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.localhost:~#
localhost:~# wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-i18n-2.33-r0.apk
--2024-10-17 21:10:47-- https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-i18n-2.33-r0.apk
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-9ca6-b5e70d242afb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T131457Z&X-Amz-Expires=300&X-Amz-Signature=41e85034170fefd2eb4335f2103f371acd95aec6d9f0917d76f4d1c4643d3df0&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-i18n-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive [following]
--2024-10-17 21:14:57-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/33333969/f3f01680-75f4-11eb-9ca6-b5e70d242afb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T131457Z&X-Amz-Expires=300&X-Amz-Signature=41e85034170fefd2eb4335f2103f371acd95aec6d9f0917d76f4d1c4643d3df0&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dglibc-i18n-2.33-r0.apk&response-content-type=application%2Fvnd.android.package-archive
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7761375 (7.4M) [application/vnd.android.package-archive]
Saving to: 'glibc-i18n-2.33-r0.apk'glibc-i18n-2.33-r0.apk 100%[===========================================>] 7.40M 33.5KB/s in 3m 52s2024-10-17 21:18:50 (32.7 KB/s) - 'glibc-i18n-2.33-r0.apk' saved [7761375/7761375]
三个软件包下载完成后就可以用apk命令进行安装了
localhost:~# apk add glibc-2.33-r0.apk glibc-bin-2.33-r0.apk glibc-i18n-2.33-r0.apk
(1/3) Installing glibc (2.33-r0)
ERROR: glibc-2.33-r0: trying to overwrite etc/nsswitch.conf owned by alpine-baselayout-data-3.6.5-r0.
(2/3) Installing glibc-bin (2.33-r0)
(3/3) Installing glibc-i18n (2.33-r0)
Executing glibc-bin-2.33-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/glibc-compat/lib/ld-linux-x86-64.so.2 is not a symbolic link/usr/glibc-compat/sbin/ldconfig: /usr/lib/libstemmer.so.2 is not a symbolic link1 error; 3451 MiB in 1055 packages
这里有一个报错,可以不用理会,如果有兴趣可以自己去了解一些关于/etc/nsswitch.conf的问题。
配置语言环境
先执行下面的命令,用刚安装好的glibc设置语言环境
localhost:~# /usr/glibc-compat/bin/localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
设置完再把export LANG=zh_CN.UTF-8的内容添加到环境变量里面,并使其生效
localhost:~# vim /etc/profile
localhost:~# source /etc/profile
这样就配置完成了,可以显示中文了,下面是上面那个glibc里面的localedef命令的帮助文档,可以正常显示中文

xfce4桌面也可以正常的显示中文
但是这个中文没有把桌面完整的汉化,上面的操作主要还是为咱们在系统中使用中文的文件显示中文提供显示的支持,对于系统软件的帮助文档等并没有将其汉化过来。