Switching to Linux can be a liberating experience, offering a highly customizable and secure environment. However, there are some tasks that can be a bit tedious, especially if you're coming from Windows, where things are often automated. One such task is installing fonts. Imagine you've set up your Linux system just the way you like it, and you're about to download and install some new fonts. You find a collection of beautiful Nerd Fonts, but the process of downloading, unzipping, and installing each font individually is time-consuming. With over 40 fonts in a single zip folder, it can feel like a daunting task.
I recently faced this exact situation when I switched to Linux Mint and decided to ditch Windows. After some frustration, I found a clever way to install fonts directly from a URL, saving a lot of time and hassle. Here's how I did it, and you can too!
A Simple Bash Script to Install Fonts
To streamline the process, I created a simple bash script that allows you to install fonts directly from a URL. The script automates the download, extraction, and installation of fonts, making the process quick and painless.
Here's the script:
#!/bin/bash
# Check if the URL is provided
if [ -z "$1" ]; then
echo "Please provide a URL to a font zip file."
exit 1
fi
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
# Download the font zip file
wget -O "$TEMP_DIR/font.zip" "$1"
# Unzip the font file
unzip "$TEMP_DIR/font.zip" -d "$TEMP_DIR"
# Move the font files to the system fonts directory
sudo mv "$TEMP_DIR"/*.{ttf,otf} /usr/local/share/fonts/
# Update the font cache
fc-cache -f -v
# Clean up
rm -rf "$TEMP_DIR"
echo "Fonts installed successfully!"
That's it, now you can save it as install.sh
and run it to install bunch of fonts easily.
How to use this script
1) Save the Script: Save the script above as install-font.sh anywhere on your Linux system.
2) Make the Script Executable: Before running the script, you need to change its permissions to make it executable. You can do this by running the following command in your terminal:
chmod +x /path/to/install-font.sh
3) Run the Script: Now, you're ready to install fonts! Open your terminal and run the script with the URL to the font zip file. For example:
./install-font.sh https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/Hack.zip
The script will download, extract, and install the fonts for you automatically.
NOTE: You can install any fonts not just nerd fonts.
Another Approach
Alternatively, there's another script by dDeedev that can make it even more easy for you! You can find the script here!
Where to Find More Nerd Fonts
You can find more Nerd Fonts to install from the official Nerd Fonts website. Simply copy the URL of the font zip file you want and use the script to install it.
Conclusion
I hope this script makes your Linux experience a bit smoother. Bash scripting is a powerful tool that can help automate repetitive tasks and save you time. Whether you're a Linux newbie or a seasoned pro, small scripts like this can make a big difference in your workflow. Do let me know your favourite fonts in the comments below.
Top comments (0)