Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A bash script to install all Google Fonts, system wide, on debian based systems (ex. Ubuntu)
#!/bin/sh
# Written by: Keefer Rourke <https://krourke.org>
# Based on AUR package <https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=ttf-google-fonts-git>
# dependancies: fonts-cantarell, ttf-ubuntu-font-family, git
sudo apt-get install fonts-cantarell ttf-ubuntu-font-family git
srcdir="/tmp/google-fonts"
pkgdir="/usr/share/fonts/truetype/google-fonts"
giturl="git://github.com/google/fonts.git"
mkdir $srcdir
cd $srcdir
echo "Cloning Git repository..."
git clone $giturl
echo "Installing fonts..."
sudo mkdir -p $pkgdir
sudo find $srcdir -type f -name "*.ttf" -exec install -Dm644 {} $pkgdir \;
echo "Cleaning up..."
sudo find $pkgdir -type f -name "Cantarell-*.ttf" -delete \;
sudo find $pkgdir -type f -name "Ubuntu-*.ttf" -delete \;
# provides roboto
sudo apt-get --purge remove fonts-roboto
echo "Updating font-cache..."
sudo fc-cache -f > /dev/null
echo "Done!"
@codeAshu

This comment has been minimized.

Copy link

@codeAshu codeAshu commented Oct 23, 2017

Great :) Works really well!

@drinkmaker

This comment has been minimized.

Copy link

@drinkmaker drinkmaker commented Jun 24, 2018

Perfect!

@kn100

This comment has been minimized.

Copy link

@kn100 kn100 commented Aug 21, 2018

Simple and effective, thanks!

@michaelmcandrew

This comment has been minimized.

Copy link

@michaelmcandrew michaelmcandrew commented Sep 25, 2018

Here's a simpler solution. In your home directory:

mkdir .fonts
git clone git://github.com/google/fonts.git .fonts/google-fonts
fc-cache -f

There are other directories where you can store fonts, e.g. ~/.local/share/fonts or /usr/local/share/fonts if you want them to be available to all users. See https://wiki.debian.org/Fonts#Manually for more info.

PS if there are any fonts that you don't want to import (for example system fonts that you already have like google-fonts/ofl/cantarell or google-fonts/ufl/ubuntu) just delete the directories for the fonts you don't want to import before running fc-cache.

@nicola-lunghi

This comment has been minimized.

Copy link

@nicola-lunghi nicola-lunghi commented Oct 15, 2018

Some suggestion

git clone --depth=1 $giturl

also is ttf not tff :-)

sudo find $pkgdir -type f -name "Cantarell-*.ttf" -delete \;
sudo find $pkgdir -type f -name "Ubuntu-*.ttf" -delete \;

see also here
https://github.com/qrpike/Web-Font-Load/blob/master/install.sh

@DeepSeaTian

This comment has been minimized.

Copy link

@DeepSeaTian DeepSeaTian commented May 31, 2019

works like a charm!

@oleersoy

This comment has been minimized.

Copy link

@oleersoy oleersoy commented Aug 9, 2019

Awesome - Thank you so much!!

@oldman20

This comment has been minimized.

Copy link

@oldman20 oldman20 commented Dec 30, 2019

Hello, please tell me how to instal gg font with bash file? im amateur, dont know how to use this *.sh file
thanks!

@oldman20

This comment has been minimized.

Copy link

@oldman20 oldman20 commented Dec 31, 2019

Hi, is it failed:
$ sudo ./install-google-fonts.sh
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package fonts-cantarell,
E: Unable to locate package ttf-ubuntu-font-family,
Cloning Git repository...
Cloning into 'fonts'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 25176 (delta 2), reused 10 (delta 0), pack-reused 25158
Receiving objects: 100% (25176/25176), 528.05 MiB | 1.44 MiB/s, done.
Resolving deltas: 100% (13576/13576), done.
Updating files: 100% (7041/7041), done.
Installing fonts...
Cleaning up...
find: paths must precede expression: ;' find: paths must precede expression: ;'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'fonts-roboto' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded.
Updating font-cache...
Done!

@keeferrourke

This comment has been minimized.

Copy link
Owner Author

@keeferrourke keeferrourke commented Jan 6, 2020

@oldman20 I know this worked at the time that I wrote and published it, but that was a long time ago and I no longer use debian/ubuntu personally. Sorry I can't help.

@oldman20

This comment has been minimized.

Copy link

@oldman20 oldman20 commented Jan 10, 2020

thanks anyway, bad news :(

@ddanninger

This comment has been minimized.

Copy link

@ddanninger ddanninger commented Feb 28, 2020

thanks anyway, bad news :(

try that one -> https://github.com/hotice/webupd8/blob/master/install-google-fonts

@skylerwebdev

This comment has been minimized.

Copy link

@skylerwebdev skylerwebdev commented May 10, 2020

Failing due to commas in apt-get statement. Does not install Cantrell Ubuntu or Git just skips them. Also, apt-get is obsolete you could just use apt. Lastly, Personally, I would uninstall roboto before I installed anything at all.

@keeferrourke

This comment has been minimized.

Copy link
Owner Author

@keeferrourke keeferrourke commented May 11, 2020

@skylerwebdev hey, this is just a gist — I've updated the script to remove the commas, but really — it's 4 years old and probably no longer up to date. Don't use this.

@skylerwebdev

This comment has been minimized.

Copy link

@skylerwebdev skylerwebdev commented May 29, 2020

@keeferrourke I will be steailing this gist and giving you props it still works 100% and is the only gist out there that does so! I actually went thru to the git link u have posted to googlefonts and last update was 3 days ago GREAT JOB

@ctjlewis

This comment has been minimized.

Copy link

@ctjlewis ctjlewis commented Sep 7, 2020

This still works really well! The Google Fonts repo seems to be maintained @ https://github.com/google/fonts and this still seems safe to use. Even on 20.04 fonts-cantarell and fonts-roboto are still available in universe repos. Thank you for publishing this!

If anyone wants a GUI, they can check out typecatcher: https://www.omgubuntu.co.uk/2013/08/typecatcher-google-fonts-download-for-ubuntu

sudo apt-get install -y typecatcher
@protectedprofile

This comment has been minimized.

Copy link

@protectedprofile protectedprofile commented Nov 5, 2020

make the script executable, then ....

./install-google-fonts.sh

still working fine 11/05/2020

@keeferrourke

This comment has been minimized.

Copy link
Owner Author

@keeferrourke keeferrourke commented Nov 6, 2020

Glad to know it still works 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment