Fonts define user experience in every system, including Linux. Although every Linux system has a default set of fonts, sometimes you may need to add new fonts to customize your system. In this article, we will learn how to install new fonts in Linux. Of course, there are many third-party tools and package managers to manage system fonts but you can also do it manually if you want. We will learn how to install new fonts in Linux manually.
How to Install New Fonts in Linux
Here are the steps to install new fonts in Linux.
1. What is fontconfig
fontconfig library is a directory where font files should be installed and referred to in /etc/fonts/font.conf configuration file. It contains a list of directories that are scanned for font files. Here is a sample of font.conf file.
$ cat /etc/fonts/local.conf <!-- Font directory list --> <dir>/usr/share/fonts</dir> <dir>/usr/share/X11/fonts/Type1</dir> <dir>/usr/share/X11/fonts/TTF</dir> <dir>/usr/local/share/fonts</dir> <dir prefix="xdg">fonts</dir> <!-- the following element will be removed in the future --> <dir>~/.fonts</dir> ...
Generally, it lists the following directory locations.
/usr/share/fonts /usr/share/X11/fonts/Type1 /usr/share/X11/fonts/TTF /usr/local/share/fonts ~/.fonts
If you want to add custom settings it is advisable to create a new file /etc/fonts/local.conf with your custom settings, instead of modifying the default file since it may be overwritten by automated programs and scripts.
2. Font Utilities in Linux
fontconfig library also provides a few useful utilities to help you work with fonts. The help you re-cache font files after they are updated, or list all available font files.
You can easily re-scan directories with font files and re-create font cache using fc-cache utility. Just run it without any arguments.
If you want only specific directories to be scanned, you can specify it with -v option. Here is a command to scan /usr/share/fonts folder.
$ fc-cache -v /usr/share/fonts
Please note, in the above process, if the existing font cache is valid, then cache regeneration is skipped. To force cache regeneration, use -f option.
$ fc-cache -v -f /usr/share/fonts
If you want to get a list of all available fonts on your system, you can do so using fc-list command.
The above command will display font file location, font family and font style of each font. The above command will display details about all available fonts. If you want even more detailed output, use -v option with fc-list command.
If you want to get details only about specific font, you can mention it after fc-list command. Here is the command to get details about fonts containing the string ‘cantarell’. This is a good way to check if a font is installed on your system.
$ fc-list cantarell
You can also filter font information using other attributes such as font style. Here is a command to list fonts with font style=Light.
$ fc-list :style=Light
Similarly, you can get font information based on their language, using lang attribute. Here is an example.
$ fc-list :lang=it
3. How to Install New Font
To install a new font in Linux, you need to first download its files typically with .woff or .ttf extensions. You can download these fonts from third-party websites such as fonts.google.com
These are typically available as zip files so you will need to unzip/extract them. Once you have extracted these files, move them to ~/.fonts or ~/.local/share/fonts and then refresh the fonts cache, that’s all. Here is an example to install new JetBrains Mono font.
$ cp JetBrainsMono-Italic-VariableFont_wght.ttf ~/.local/share/fonts $ fc-cache -vf
The first command copies the font files to a directory that is scanned for fonts by Linux. The second command refreshes font cache.
Once the new font is installed, it should be available in all your applications, where required.
In this article, we have learnt how to install new font in Linux. Please remember to copy the extracted font files and not the zip file to any of the directories that is scanned for fonts. If you copy the zip file, or copy extracted files to a directory that is not scanned for fonts, it won’t work.
How to List GPG Keys in Linux
How to Find Oldest File in Directory
How to Show Disk Usage Only for Top Level Directories
How to Resolve bin/sh 1: source not
How to Reload etc/hosts in Linux