11

Well I did search through AskUbuntu and found some threads where people are asking about how can they install multiple fonts at once? I know the process. I have to copy-paste all the fonts, .ttf/.otf files inside of .font hidden folder and then rebuild the font cash via this command...

fc-cache -rv

This is crystal clear. I just want to know this...

I downloaded 10+ .zip font files. When I extracted the .zip folders I see within each folder there are couple of files. A readme file, a .ttf/.otf file and in some cases some variants of the fonts. Like bold.ttf, ultra_bold.ttf, semi_bold.ttf, black.ttf etc. I am not sure what these additional files are but I guess these are mainly variants of the core fonts. However my question is...

Do I need to extract all the .zip files manually and then copy only .ttf/.otf files and then paste them manually in .font folder? Or I can use a terminal command which will do everything on behalf of me. Here by the word everything I meant...

  1. Extracting the .zip files
  2. Copying only .ttf/.otf files
  3. Pasting only the .ttf/.otf files into .font folder
  4. Finally installing the .ttf/.otf files in Ubuntu

Sorry for asking a broad question. But to avoid down votes I had to make sure I am not asking anything which is asked before. And thanks in advanced for all your helps.

3 Answers3

17

This is a one-liner in a terminal. Open a terminal with Ctr+Alt+T and run the commands below. Replace <your_font_zips> with the folder name, where you have placed your zip font files.

cd <your_font_zips>
# next command extracts all TTF and OTF files into your `.fonts` folder.
unzip "*.zip" "*.ttf" "*.otf" -d ${HOME}/.fonts
# next command rebuilds font cache
sudo fc-cache -f -v

If you want to remove the fonts again, then simply delete the TTF files in your .fonts folder and rebuild the font cache.

More about fonts and Ubuntu here.


And yes, you need all TTF files.

TTF and/or OTF

I quote:

OTF is more likely to be a “better” font, as it supports more advanced typesetting features (smallcaps, alternates, ligatures and so on actually inside the font rather than in fiddly separate expert set fonts). It can also contain either spline (TTF-style) or Bezier (PostScript Type 1-style) curves, so hopefully you're getting the shapes the font was originally designed in and not a potentially-poorer-quality conversion.

Source

A.B.
  • 90,397
  • You put a different command few minutes ago! You mean I should run this one "unzip ".zip" ".ttf" "*.otf" -d ${HOME}/.fonts; sudo fc-cache -f -v" instead of the one you gave few minutes ago? – Roy Emmarson May 06 '15 at 14:46
  • 1
    Yes, this is the final tested version =) – A.B. May 06 '15 at 14:52
  • We don't need the find – A.B. May 06 '15 at 14:52
  • don't forget to change the directory – A.B. May 06 '15 at 14:53
  • sorry for the typo...

    Well I have 3 parallel questions...

    1- Lets say I want to delete some fonts from system. How can I do so? 2- I don't know much about scripting. From your words what I understand is I can open a file in the font folder and then copy paste the commands you supplied. And then I should run the file with font archives. Following this I opened a gedit file in the font folder where .zip files are then copycat your commands within the file. But now how can I run the file using font archive? I don't see any application named font archive rather an app named archive manager

    – Roy Emmarson May 06 '15 at 15:10
  • 3- Last question is if I install fonts within .fonts folder will all the user get permission to access the fonts? Or I have to install them insdie /use/share/fonts? Unfortunately I can't see any /use/share/fonts folder anywhere...

    4- One last question. When should I run sudo fc-cache -f -v this command?

    – Roy Emmarson May 06 '15 at 15:13
  • I have revised the answer. I confusing things away. – A.B. May 06 '15 at 15:20
  • hm I see you removed the script commands. Sorry for asking childish questions. In fact I have started ubuntu and even linux just 15 days ago. :) – Roy Emmarson May 06 '15 at 15:38
  • 1
    sudo fc-cache -f -v seems to load fonts from /root/.fonts not from ${HOME}/.fonts – Andrew Savinykh Jan 09 '22 at 00:24
4

Addendum to the accepted answer:

Run fc-cache -f -v without sudo.

If you use sudo, as indicated by the accepted answer, fc-cache will only process the root's fonts folder, while ignoring the user's fonts folder.

0

Not a one liner but here is slightly more robust script that works on Linux as well as OSX. Here we download codefonts and install it without overwriting existing files.

#!/bin/bash
#fail if any errors
set -e
set -o xtrace

temp_dir=~/Downloads/codefonts
wget -P ${temp_dir} https://github.com/chrissimpkins/codeface/releases/download/font-collection/codeface-fonts.zip

if test "$(uname)" = "Darwin" ; then
  # MacOS
  fonts_dir="$HOME/Library/Fonts"
else
  # Linux
  fonts_dir="$HOME/.local/share/fonts"
  mkdir -p $fonts_dir
fi

# -n option avoids overwriting
set +e
unzip -n ${temp_dir}/codeface-fonts.zip "fonts/*.ttf" "fonts/*.otf" "*fonts/.pcf.gz" -d ${temp_dir}
set -e
cp -rnv ${temp_dir}/fonts ${fonts_dir}

if test "$(uname)" = "Darwin" ; then
  # Copy SF Mono for MacOS
  cp /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/*.otf "$fonts_dir/"
fi

# Reset font cache on Linux
if which fc-cache >/dev/null 2>&1 ; then
    echo "Resetting font cache, this may take a moment..."
    fc-cache -f "$fonts_dir"
fi

echo "codefonts installed to $fonts_dir"