Getting Started

How to Install LaTeX Packages on Windows, Ubuntu and by Hand

How to install LaTeX packages on Windows, Ubuntu, and by hand, including where to put a .sty file and how to find the package a missing file belongs to.

On this page
  1. Quick answer
  2. How LaTeX finds packages
  3. Find out which package you need
  4. Install on Windows
  5. Install on Ubuntu and Debian
  6. Install a .sty file by hand
  7. Overleaf: packages are already installed
  8. Troubleshooting
  9. Next steps

Quick answer

Most packages you need are already in your LaTeX distribution, so you usually install them through it. On Windows with MiKTeX, the package can install itself the first time a document needs it. On TeX Live, use tlmgr install. On Ubuntu, use apt. If you have a single .sty file, put it in the same folder as your .tex file.

How LaTeX finds packages

A package is a .sty file, sometimes with other files alongside it. Writing \usepackage{mypackage} tells LaTeX to load mypackage.sty. LaTeX looks for the file in the current folder and then in the folders of your distribution. If it can’t find the file, the compile stops with an error such as:

! LaTeX Error: File `mypackage.sty' not found.

Find out which package you need

Read the error

The file name in the error is the first clue. In most cases, the package name is the file name without .sty. A missing tikz.sty, for example, means you need the tikz package, which is part of the PGF/TikZ bundle used for drawing diagrams and flowcharts in LaTeX.

Look up the documentation

  • On TeX Live, texdoc mypackage opens the package’s documentation if it is installed.
  • CTAN is the main archive of LaTeX packages. Search for the package name to read its description and see which files it provides.

Install on Windows

MiKTeX

MiKTeX can install missing packages automatically when a document needs them. You can change this setting in the MiKTeX Console. To install a package yourself, search for it in the MiKTeX Console’s package list and install it. Then compile again.

TeX Live

Open a terminal and run:

tlmgr install mypackage

To find the package that provides a file, run this in PowerShell or Command Prompt:

tlmgr search --global --file "/mypackage.sty"

If you installed TeX Live for all users, you may need to open the terminal as administrator.

Install on Ubuntu and Debian

Install with apt

TeX Live packages on Ubuntu come from apt. Install groups of packages with names that begin with texlive-:

sudo apt update
sudo apt install texlive-latex-extra

Other groups cover specific areas. For example, texlive-pictures includes TikZ and PGF. The full list is in your package manager.

Find the package that owns a file

apt-file searches all packages, including ones you have not installed:

sudo apt install apt-file
sudo apt-file update
apt-file search mypackage.sty

Each result shows the package name and the path to the file. Install the package it names.

Install a .sty file by hand

You may get a .sty file from a colleague, a template, or a download. There are two common ways to make it available.

Put it in the project folder

Copy the file into the same folder as your .tex file. LaTeX checks the current folder first, so the package loads without any changes to your system. This is the simplest option for a single project, and it works the same way on Windows, Ubuntu, and macOS. The file also travels with the project when you share it.

Use your personal TeX folder

To use a package in every project, put it in your personal TeX tree. On TeX Live (Ubuntu, macOS), find the folder with:

kpsewhich -var-value=TEXMFHOME

This usually prints a folder such as ~/texmf. Place the file in a path that matches its type, such as:

~/texmf/tex/latex/mypackage/mypackage.sty

Then refresh LaTeX’s file index:

mktexlsr

Check that LaTeX can find the file:

kpsewhich mypackage.sty

If the command prints a path, the package is available. On Windows, MiKTeX uses a different folder layout, so check the MiKTeX documentation for its user-level folder. The project-folder option works without it.

Overleaf: packages are already installed

Overleaf includes a large set of packages on its servers. Add a \usepackage line to your project and compile. You don’t need to install anything.

Troubleshooting

  • The package is still not found after installing. Open a fresh terminal so the updated settings load, then compile again. On TeX Live, check the path with kpsewhich.
  • You have two copies of the same package. LaTeX checks the current folder first, so a copy next to your .tex file takes priority over the system copy. Remove the copy you don’t need if the results are not what you expect.
  • An apt package name doesn’t match what you expected. Use apt-file search with the .sty file name rather than guessing.
  • Errors after a large update. Update all packages with tlmgr update --all on TeX Live, or with apt upgrade on Ubuntu, then compile again.

Next steps

The complete guide to getting started

Getting Started with LaTeX: Document Preparation, Editors and Workflow
Read the guide

Keep exploring

Guides from other topics

All topics →