本文以安装黑体simhei.ttf为例,简单演示如何在Linux下安装中文字体。

环境信息介绍

[root@thatsit ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@thatsit ~]# [root@thatsit ~]# uname -r
3.10.0-229.el7.x86_64
[root@thatsit ~]# [root@thatsit ~]# echo $LANG
en_US.UTF-8
[root@thatsit ~]# cat /etc/locale.conf
LANG="zh_CN.UTF-8"
[root@thatsit ~]# [root@thatsit ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
[root@thatsit ~]#

依赖的命令

操作依赖几个命令,如果系统中不存在需要手动安装下。

  • fc-list:列举可用的字体
  • fc-cache:生成字体信息的缓存

这两个命令包含在fontconfig包里,可以通过下面的命令进行安装。

yum install fontconfig
  • mkfontscale:生成字体索引

这个命令属于xorg-x11-font-utils工具包,可以通过下面的命令进行安装。

yum install mkfontscale

操作步骤

  • 创建一个用于存放中文字体的目录
mkdir /usr/share/fonts/zh_CN

PS: /usr/share/fonts/这个目录会在安装fontconfig包之后自动创建

  • 上传字体simhei.ttf到上述目录中

  • 构建字体索引和缓存

# cd /usr/share/fonts/zh_CN # 需要进到这个目录
mkfontscale
mkfontdir
fc-cache -fv

执行上述命令之后,在目录下可以看到一个fonts.dir和一个fonts.scale文件

[root@thatsit zh_CN]# pwd
/usr/share/fonts/zh_CN
[root@thatsit zh_CN]# ll
total 9532
-rw-r--r-- 1 root root 66 Sep 4 11:39 fonts.dir
-rw-r--r-- 1 root root 66 Sep 4 11:39 fonts.scale
-rwxrw-rw- 1 root root 9751960 Sep 4 11:38 simhei.ttf
[root@thatsit zh_CN]#

文件内容

[root@thatsit zh_CN]# cat fonts.dir
1
simhei.ttf -misc-simhei-medium-r-normal--0-0-0-0-p-0-iso10646-1
[root@thatsit zh_CN]# cat fonts.scale
1
simhei.ttf -misc-simhei-medium-r-normal--0-0-0-0-p-0-iso10646-1
[root@thatsit zh_CN]#
  • 查看字体
# 查看所有可用字体
[root@thatsit zh_CN]# fc-list
/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/zh_CN/simhei.ttf: SimHei:style=Regular,Normal
/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
/usr/share/fonts/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight
/usr/share/fonts/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
/usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique
/usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique
[root@thatsit zh_CN]# # 只查看中文字体,SimHei字体安装成功。
[root@thatsit zh_CN]# fc-list :lang=zh
/usr/share/fonts/zh_CN/simhei.ttf: SimHei:style=Regular,Normal
[root@thatsit zh_CN]#

dir和scale文件生成的详细过程

[root@thatsit zh_CN]# ls
simhei.ttf
[root@thatsit zh_CN]#
[root@thatsit zh_CN]#
[root@thatsit zh_CN]# mkfontscale
[root@thatsit zh_CN]# ls
fonts.scale simhei.ttf
[root@thatsit zh_CN]# mkfontdir
[root@thatsit zh_CN]# ls
fonts.dir fonts.scale simhei.ttf
[root@thatsit zh_CN]# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 3 dirs
/usr/share/fonts/default: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/default/Type1: caching, new cache contents: 35 fonts, 0 dirs
/usr/share/fonts/default/ghostscript: caching, new cache contents: 4 fonts, 0 dirs
/usr/share/fonts/dejavu: caching, new cache contents: 13 fonts, 0 dirs
/usr/share/fonts/zh_CN: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/X11/fonts/Type1: caching, new cache contents: 13 fonts, 0 dirs
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts/default: skipping, looped directory detected
/usr/share/fonts/dejavu: skipping, looped directory detected
/usr/share/fonts/zh_CN: skipping, looped directory detected
/usr/share/fonts/default/Type1: skipping, looped directory detected
/usr/share/fonts/default/ghostscript: skipping, looped directory detected
/usr/lib/fontconfig/cache: cleaning cache directory
/root/.cache/fontconfig: not cleaning non-existent cache directory
/root/.fontconfig: not cleaning non-existent cache directory
/usr/bin/fc-cache-64: succeeded
[root@thatsit zh_CN]# ls
fonts.dir fonts.scale simhei.ttf
[root@thatsit zh_CN]#

Linux 下安装中文字体的更多相关文章

  1. Linux下安装中文字体

    目录 一.Centos系列 二.Ubuntu系列 一.Centos系列 1.安装字体库 yum -y install fontconfig 2.添加中文字体,建立存储中文字体的文件夹 mkdir /u ...

  2. Linux 下安装中文 ctex 指南

    大家在用 $\LaTeX$ 进行中文排版时相信会遇到不少问题,而$\textbf{ctex}$套装的出现则有效的解决了这一问题,只要安装了$\textbf{ctex}$那么在文中不用进行引用设置就可以 ...

  3. CentOS 7.6环境下安装中文字体库

    JAVA画图时常用到Font 类对象 这样的对象依赖于本地的字段.新装的linux没有安装字段库,和相应的字体. 1.fc-list查看字体库 2.yum -y install fontconfig安 ...

  4. Centos6下安装中文字体

    先安装字体管理软件 [root@localhost ~]# yum install fontconfig 将需要安装的字体放到/usr/share/fonts/chinese/目录下 如果不存在这个目 ...

  5. Linux(Centos)安装中文字体库(文档中文字符不显示)

    yum -y install fontconfig 在/usr/shared/fonts目录下新建一个目录chinese 然后打开windows本地的字体库 将这里面的所有文件上传到centos里我们 ...

  6. Linux下JDK中文字体乱码

    java生成图片的时候用到字体,但是liunx系统没有这些字体需要把C:\Windows\Fonts 上传到/usr/local/jdk1.8.0_171/jre/lib/fonts 重启tomcat ...

  7. Linux下安装中文宋体

    1,#cd /usr/share/fonts/default 2,mkdir -p ./truetype/simsun 3,取得simsun.ttc文件:如果网上下载不到则在windows (c:/w ...

  8. Linux安装中文字体(已验证)

    1.安装字体命令 sudo apt install -y fontconfig 2.查看已安装的字体 (1)查看linux已安装字体 fc-list (2)查看linux已安装中文字体 fc-list ...

  9. 解决Linux下sqlplus中文乱码问题

    错误现象:在windows下用其他工具访问oracle,确认中文正常显示.在Linux下使用sqlplus查询数据表中文内容出现乱码. 分析及解决:因为windows下正常,所以问题应出现在Linux ...

随机推荐

  1. Linux小记 -- [已解决]Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings

    问题描述 操作系统:Ubuntu Server 18.04 LTS Ubuntu每次启动时产生如下motd(message of today)输出 Failed to connect to https ...

  2. 3,、maven修改jar包下载为国内镜像下载地址

    maven 默认的中央仓库是在国外的服务器,下载速度慢,有时候稍不注意就下载出错 通常我将maven的中央仓库修改为阿里云的地址,下载速度很快体验非常好 修改conf下的setting.xml文件 在 ...

  3. C# 无焦点获取扫码枪扫码信息

    代码网上有的是,多是需要窗体焦点直接show出扫码信息(usb,模拟键盘,hook) 怎样才能真的无焦点获取? 用串口方式 usb转串口 以接收串口通讯消息的方式获取扫码信息

  4. zabbix添加主机后无法显示解决

    第一次添加主机后显示正常,后来删除了主机,重新添加了一下主机再也无法显示主机,很苦恼,原来需要点击重设,

  5. vue启动流程

    继上一篇vue环境的搭建(在D盘新建文件夹vue_cli,把(我已经上传到了文件下)资料下tpls解压完后的所有文件都复制到D盘vue_cli下) 目录如图: 1.webstorm设置为了提高webS ...

  6. [Git] 014 远程仓库篇 第一话

    0. 前言 在 [Git] 001 初识 Git 与 GitHub 之新建仓库 中,我在 GitHub 上建了一个仓库 "interesting" 这回的任务 把远程的 " ...

  7. [转帖]IDC发布2018下半年中国公有云市场报告

    IDC发布2018下半年中国公有云市场报告:AWS以6.4%的份额名列第四 http://www.itpub.net/2019/05/06/1793/ 电信的公有云 好像是用的 华为的技术. AWS在 ...

  8. Python3 AES加解密(AES/ECB/PKCS5Padding)

    class AesEncry(object): key = "wwwwwwwwwwwwwwww" # aes秘钥 def encrypt(self, data): data = j ...

  9. spring boot @Transactional的一个小坑

    同一个类Service下,有两个函数 method_1和 method_2,且method_1内部调用了method_2,那么希望method_2内部意外时,数据库回滚,那么一定要在method_1上 ...

  10. 认识 JVM

    1 什么是JVM?  JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范.比如 对Class文件类型,运行时数据,帧栈 ,指令集等的规范 ,Hot ...