Emacs, scripting and anything text oriented.

Installing custom fonts in Linux

Kaushal Modi

I’ll step through how to set custom fonts for xterm terminal. My default shell is tcsh.

  1. Create a folder .fonts in your $HOME directory.
  2. Download fonts of your choice (ttf or otf format to ~/.fonts).
  3. Refresh the fonts cache with fc-cache -fv.
  4. You can verify if your custom fonts got added to the cache using fc-list. For example, I would do fc-list -f "%{family}\n" | sort -u | grep 'Inconsolata'1 to check if my downloaded Inconsolata fonts got into the font cache.
  5. Add the below .Xdefaults snippet to your ~/.Xdefaults
  6. Add xrdb -merge $HOME/.Xdefaults to your shell init script. My shell init script is ~/.alias.
*customization: -color
XTerm*termName: xterm-256color

xterm*saveLines:        500
xterm*scrollBar:        false
xterm*cursorColor:      white
xterm*pointerColor:     white
xterm*Foreground:       white
xterm*Background:       black
xterm*c132:             true
xterm*loginShell:       false

! Fonts
! XTerm*faceName: DejaVu Sans Mono:size=11
! XTerm*faceName: Inconsolata:size=11
! XTerm*faceName: Inconsolata\\-dz:style=dz:size=11
XTerm*faceName: Inconsolata\\-g:style=g:size=11

Done! Now source your shell init script and launch xterm.

Note: In order to use font names with hyphens in them, I had to escape them by using \\. So for the Inconsolata-g font, I have XTerm*faceName: Inconsolata\\-g:style=g:size=11.

It might be helpful to add the below aliases to your tcsh init script for quick font refresh and check, using fontsrefresh; fontsavail | grep 'Inconsolata'.

alias fontsavail   'fc-list -f "%{family}\n" | sort -u'
alias fontsrefresh 'fc-cache -fv'

  1. You can download Inconsolata font from here↩︎

Webmentions
Comment by Anonymous on Mon Nov 15, 2021 21:01 EST

This was partially helpful. Except that fc-cache is ignoring my downloaded files:

/home/junkboy/.fonts: caching, new cache contents: 0 fonts, 0 dirs

This is odd since I have these:

-rw-r–r– 1 junkboy junkboy 167674 2021-11-15 17:48:47 mononoki-Regular Nerd Font Complete Mono.ttf

-rw-r–r– 1 junkboy junkboy 170437 2021-11-15 17:48:46 mononoki-Regular Nerd Font Complete Mono Windows Compatible.ttf

-rw-r–r– 1 junkboy junkboy 166837 2021-11-15 17:48:48 mononoki-Regular Nerd Font Complete.ttf

-rw-r–r– 1 junkboy junkboy 169600 2021-11-15 17:48:47 mononoki-Regular Nerd Font Complete Windows Compatible.ttf

And then there were these types of results

/usr/share/fonts/truetype/liberation: caching, new cache contents: 16 fonts, 0 dirs

/usr/share/fonts/X11: skipping, looped directory detected

Sincerely,

junkmonkey69@gmail.com