Install Fonts in Ubuntu
The management of fonts that are not packaged in Linux distributions can be performed with a handful of command line tasks. While this takes a bit more effort than font management with a GUI font manager or package manager application, the steps are simple, and an understanding of them will allow you to install and use the many unpackaged fonts that are available out there.
This article demonstrates a command line approach to install desktop fonts (i.e., the *.otf and *.ttf build varieties), clear and regenerate your font cache, and verify your font installation. I provide an example shell script that pulls all of the steps together into a single command for those who want to use it as a basis for a custom installation + upgrade script. In the final section, I demonstrate how to locate and uninstall fonts that you don’t need.
We will use our Hack fonts as released in font binary format through a Github repository to demonstrate the entire process. These steps assume that font files are accessible through HTTP GET requests and come packaged in a gzipped tar archive. Feel free to modify the paths in each step to install any set of fonts that meet these criteria.
Install Fonts on Linux
Step 1 : Pull the fonts to your system
To pull a font archive from a publicly accessible server with a HTTP GET request, navigate to a directory of your choice and use cURL:
$ curl -L -O https://github.com/source-foundry/Hack/releases/download/v3.003/Hack-v3.003-ttf.tar.gz
Step 2 : Unpack the font archive
Unpack the gzipped tar archive with tar
:
$ tar -xzvf Hack-v3.003-ttf.tar.gz
For the Hack fonts, this results in an unpacked directory path, ttf
. The fonts are contained in the root of the directory. Archives from other typeface projects may result in a different unpacked path structure. If you are installing a different set of fonts, review the font paths before you move on to the next step.
Step 3 : Install the fonts
On Linux systems, font binaries are generally installed in either the system font directory on the path /usr/share/fonts/
or in a user font directory that is frequently on one of the following paths: ~/.local/share/fonts/
or /usr/local/share/fonts
. We’ll use the ~/.local/share/fonts/
path in this example. If the directory does not exist, create it with the following command:
$ mkdir ~/.local/share/fonts
Move your font binaries to the destination directory with mv
:
$ mv ttf/Hack-Regular.ttf ~/.local/share/fonts/Hack-Regular.ttf
$ mv ttf/Hack-Italic.ttf ~/.local/share/fonts/Hack-Italic.ttf
$ mv ttf/Hack-Bold.ttf ~/.local/share/fonts/Hack-Bold.ttf
$ mv ttf/Hack-BoldItalic.ttf ~/.local/share/fonts/Hack-BoldItalic.ttf
Step 4 : Clear and regenerate your font cache
Next, clear and regenerate your font cache with the following command:
$ ==fc-cache -f -v==
You will see a stream of text as the font cache is created. This can be a lengthy body of text if you have a large number of fonts installed on your system. If you examine the text closely, you should see that your new font installs were identified during this process.
Step 5 : Verify the installation
Confirm that the fonts are installed by displaying the paths and style definitions with the fc-list
executable filtered on the font family name with grep
:
$ fc-list | grep “Hack”
On my system, the following text is displayed:
/home/chris/.local/share/fonts/Hack-BoldItalic.ttf: Hack:style=Bold Italic
/home/chris/.local/share/fonts/Hack-Italic.ttf: Hack:style=Italic
/home/chris/.local/share/fonts/Hack-Bold.ttf: Hack:style=Bold
/home/chris/.local/share/fonts/Hack-Regular.ttf: Hack:style=Regular
The fonts are now installed and ready for use.
Step 6 : Cleanup
The archive file and unpacked directory are no longer necessary. Let’s remove them:
$ rm -rf ttf && rm Hack-v3.003-ttf.tar.gz