Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Last active April 20, 2025 02:17
Show Gist options
  • Save matthewjberger/7dd7e079f282f8138a9dc3b045ebefa0 to your computer and use it in GitHub Desktop.
Save matthewjberger/7dd7e079f282f8138a9dc3b045ebefa0 to your computer and use it in GitHub Desktop.
Install a nerd font on ubuntu

1.) Download a Nerd Font

2.) Unzip and copy to ~/.fonts

3.) Run the command fc-cache -fv to manually rebuild the font cache

@pedoc
Copy link

pedoc commented Oct 23, 2024

I made a small, but useful to me, change to @donovan code. I added code to look up the latest version of nerd fonts and download those.

#!/bin/bash

declare -a fonts=( BitstreamVeraSansMono CascadiaCode CodeNewRoman DroidSansMono FiraCode FiraMono Go-Mono Hack Hermit JetBrainsMono Meslo Noto Overpass ProggyClean RobotoMono SourceCodePro SpaceMono Ubuntu UbuntuMono )

version=$(curl -s 'api.github.com/repos/ryanoasis/nerd-fonts/releases/latest' | jq -r '.name') fonts_dir="${HOME}/.local/share/fonts"

if [[ ! -d "$fonts_dir" ]]; then mkdir -p "$fonts_dir" fi

for font in "${fonts[@]}"; do zip_file="${font}.zip" download_url="github.com/ryanoasis/nerd-fonts/releases/download/${version}/${zip_file}" echo "Downloading $download_url" wget "$download_url" unzip "$zip_file" -d "$fonts_dir" rm "$zip_file" done

find "$fonts_dir" -name 'Windows Compatible' -delete

fc-cache -fv

I made him better.

#!/bin/bash

declare -a fonts=(
BitstreamVeraSansMono
CascadiaCode
CodeNewRoman
DroidSansMono
FiraCode
FiraMono
Go-Mono
Hack
Hermit
JetBrainsMono
Meslo
Noto
Overpass
ProggyClean
RobotoMono
SourceCodePro
SpaceMono
Ubuntu
UbuntuMono
)

version=$(curl -s 'https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest' | jq -r '.name')
if [ -z "$version" ] || [ "$version" = "null" ]; then
  version="v3.2.1"
fi
echo "latest version:$version"

fonts_dir="${HOME}/.local/share/fonts"
#fonts_dir="/usr/share/fonts"

if [[ ! -d "$fonts_dir" ]]; then
mkdir -p "$fonts_dir"
fi

for font in "${fonts[@]}"; do
ls ="${font}.zip"
download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/${version}/${zip_file}"
echo "Downloading $download_url"
wget "$download_url"
unzip "$zip_file" -d "$fonts_dir"
rm "$zip_file"
done

find "$fonts_dir" -name 'Windows Compatible' -delete

fc-cache -fv

@pha5matis
Copy link

pha5matis commented Oct 27, 2024

@pedoc

You've got a typo in your script that's causing an error. On the line where you have ls ="${font}.zip", you're mistakenly using the ls command instead of assigning the zip file name to a variable. This incorrect usage leads to the script failing to locate the font file, resulting in a "No such file or directory" error when it tries to download and unzip the font. By correcting that line to zip_file="${font}.zip", you'll properly assign the zip file name to the zip_file variable, allowing the download URL to be constructed correctly and the font installation to proceed without issues.

Script below with fixes and works on 24.04

#!/bin/bash

declare -a fonts=(
  BitstreamVeraSansMono
  CascadiaCode
  CodeNewRoman
  DroidSansMono
  FiraCode
  FiraMono
  Go-Mono
  Hack
  Hermit
  JetBrainsMono
  Meslo
  Noto
  Overpass
  ProggyClean
  RobotoMono
  SourceCodePro
  SpaceMono
  Ubuntu
  UbuntuMono
)

version=$(curl -s 'https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest' | jq -r '.name')
if [ -z "$version" ] || [ "$version" = "null" ]; then
  version="v3.2.1"
fi
echo "latest version: $version"

fonts_dir="${HOME}/.local/share/fonts"
#fonts_dir="/usr/share/fonts"

if [[ ! -d "$fonts_dir" ]]; then
  mkdir -p "$fonts_dir"
fi

for font in "${fonts[@]}"; do
  zip_file="${font}.zip"
  download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/${version}/${zip_file}"
  echo "Downloading $download_url"
  wget "$download_url"
  unzip -o "$zip_file" -d "$fonts_dir"  # Added the -o option here to allow replacing
  rm "$zip_file"
done

find "$fonts_dir" -name 'Windows Compatible' -delete

fc-cache -fv

@miiiladiii244
Copy link

#!/bin/bash

declare -a fonts=(
    BitstreamVeraSansMono
    CodeNewRoman
    DroidSansMono
    FiraCode
    FiraMono
    Go-Mono
    Hack
    Hermit
    JetBrainsMono
    Meslo
    Noto
    Overpass
    ProggyClean
    RobotoMono
    SourceCodePro
    SpaceMono
    Ubuntu
    UbuntuMono
)

version='2.1.0'
fonts_dir="${HOME}/.local/share/fonts"

if [[ ! -d "$fonts_dir" ]]; then
    mkdir -p "$fonts_dir"
fi

for font in "${fonts[@]}"; do
    zip_file="${font}.zip"
    download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/${zip_file}"
    echo "Downloading $download_url"
    wget "$download_url"
    unzip "$zip_file" -d "$fonts_dir"
    rm "$zip_file"
done

find "$fonts_dir" -name '*Windows Compatible*' -delete

fc-cache -fv

Thank you so much!

@2korzhik
Copy link

2korzhik commented Apr 7, 2025

I made a small, but useful to me, change to @donovan code. I added code to look up the latest version of nerd fonts and download those.

No need to introduce dependency on curl and jq. With proper download_url wget will be automatically redirected to the latest version
download_url="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${zip_file}"

@benkenawell
Copy link

Since I just loaded Ubuntu on a new computer, had trouble and found this page, I'll add that the instructions at the top are great except unzipping didn't put them in a folder for me, so neovim/lazyvim didn't seem to load them properly. To get it to load, I had to put it into a folder inside the font folder. For example, after downloading FiraCode Nerd Font I went to my Downloads folder and ran...

mkdir -p ~/.local/share/fonts      # create folder to load fonts into
mkdir FiraCode                     # matches the name of the zip file
mv ./FiraCode.zip ./FiraCode       # move the zip into the new folder
cd FiraCode                        # change directory into the folder
unzip FiraCode.zip                 # unzip into the folder
rm FiraCode.zip                    # delete the zip file, we don't need it anymore
cd ..                              # change directory back up to Downloads
mv ./FiraCode ~/.local/share/fonts # move our new font folder into the font folder we created at the beginning
fc-cache -fv                       # reload the font-cache

Very manual, but I don't think I should need to update these very often!

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