How to Manually Install, Update, and Uninstall Fonts on Linux
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
All Together Now
We provide a shell script for Hack font installs that pulls these steps together into a single command for our Linux users.
The command to manually install version 3.003 of our fonts looks like this:
$ ./hack-linux-intaller.sh v3.003
To upgrade the fonts, users increment the version number in the command as new releases are pushed to the Github repository.
A Github gist of the script source follows. If you followed along above you will notice that the commands are identical to the examples in the steps that we just reviewed.
- Step 1 is on line 42
- Step 2 is on line 47
- Step 3 is on lines 61–71
- Step 4 is on line 81
- Step 5 is on line 85
- Step 6 is on lines 58 & 75
The script is MIT licensed and can be modified by typeface developers and users to support simple initial installs and upgrades for other projects that release in a similar way.
Uninstall Fonts on Linux
The process to uninstall fonts requires identification of the installation paths, removal of the font binaries, and regeneration of the font cache. The font removal step is the only new task that you need to learn if you went through the installation steps in the section above. Be aware that the removal of font binaries with rm
step eliminates the files permanently. Please consider backups if they are not readily accessible in the future and you might have a need for them again!
Step 1 : Identify the font binary paths
Use the fc-list
executable with grep
to identify the paths to the installed fonts by family name:
$ fc-list | grep "Hack"
Modify the grep search term to identify other font families.
Step 2: Remove the font binaries
Use the rm
executable to remove the installed font binaries on the paths that you identified with the command in Step 1. This permanently deletes the files. Use caution (and backup copies somewhere!) if the files are not readily accessible should you need them again.
If you used the installation steps above to install the Hack fonts, the following command will remove the fonts:
$ rm "$HOME/.local/share/fonts/Hack-*.ttf"
Step 3: Clear and regenerate the font cache
Then regenerate your font cache:
$ fc-cache
And that is a manual font management round trip on the Linux command line. Enjoy the many new typeface options that are available to you on your Linux box!
I would like to thank Paride Legovini for his technical review and feedback on this article. His input was very helpful and improved the tutorial.
Your feedback is extremely helpful to us. If you identify any errors or have suggestions for improvements to the approach that was used in this article, please submit a new issue report on our Github repository.