How to Fix LaTeX “File `.sty` Not Found” Errors
At a glance
- 1. Identify the package
Read the missing filename in the error and determine whether it is a standard package or a local file.
- 2. Check your TeX setup
Confirm which TeX distribution and compiler your editor is actually using.
- 3. Install or locate it
Use the distribution’s package manager, or place a custom package in a searched folder.
- 4. Test the lookup
Run kpsewhich with the exact .sty filename to see whether TeX can find it.
When LaTeX reports File 'something.sty' not found, it has reached a \usepackage{something} command (or another command that loads a package) but cannot find the corresponding file. The fix depends on whether the file is a standard package, a custom file supplied with a project, or a file that exists but is outside the active TeX installation’s search paths.
1. Read the exact missing filename
Look at the first relevant error in the log. For example:
! LaTeX Error: File `booktabs.sty' not found.
The missing file is booktabs.sty; the package is usually loaded as \usepackage{booktabs}. The file name and package name often match, but not always. Search for the exact .sty filename in the project documentation or package’s installation instructions before guessing a package-manager name.
Also check for typos in the \usepackage command and for capitalization differences. File-name matching can be case-sensitive, especially on Linux.
2. Make sure you are using the intended TeX installation
An editor can use a different LaTeX engine or TeX distribution from the one you updated. This is common when multiple installations exist, or when a TeX distribution was installed after an editor was configured.
From a terminal, check which engine is being run:
which pdflatex
pdflatex --version
On Windows, where pdflatex can show which executable is selected. In an editor, check the configured compiler or build command as well. Installing a package into one TeX distribution will not make it available to a different distribution that your editor actually runs.
To test whether TeX can find the file, run:
kpsewhich booktabs.sty
If it prints a path, the file is visible to that TeX setup. If it prints nothing, that setup cannot find it.
3. Install a standard package
Use the package manager for the distribution that runs your document:
- TeX Live, including MacTeX: use TeX Live’s package manager,
tlmgr, or a graphical front end such as TeX Live Utility on macOS. For example,tlmgr install booktabsinstalls the package namedbooktabswhentlmgris available and configured for that installation. - MiKTeX: open MiKTeX Console and install the package there. Depending on your settings, MiKTeX may also offer to install missing packages during compilation.
- Linux distribution packages: if TeX was installed through your operating system’s package manager, install the package through that manager. Package names can differ from CTAN names, and some systems group many LaTeX packages into larger bundles.
For a small, fully worked example, suppose your document contains \usepackage{booktabs} and compilation reports that booktabs.sty is missing. First run kpsewhich booktabs.sty. If there is no output and you use TeX Live, install booktabs with the TeX Live package manager. Then run kpsewhich booktabs.sty again; it should print the installed file’s path. Recompile the document using the same engine and distribution.
Some TeX Live installations are managed by an operating system or institution. In that case, tlmgr may be disabled or may not be the right way to update packages. Use the installation’s supported package manager instead. You may need administrator privileges to install system-wide packages.
4. Handle a custom or project-supplied .sty file
A package written specifically for a project may not be available through a standard package manager. Check the project’s instructions and make sure the .sty file is actually present. If it is part of the project, put it in the same directory as the main .tex file; TeX normally searches the current working directory.
For reuse across projects, put it in a local TEXMF tree. The correct personal tree varies by system and installation. You can ask TeX Live where its personal tree is with:
kpsewhich -var-value=TEXMFHOME
Place the file under a suitable subfolder such as tex/latex/mypackage/ within that tree. If the file still is not found, refresh the filename database where appropriate, then test again with kpsewhich. Avoid copying files into TeX’s installation directories by hand: package-manager updates can overwrite or remove such changes.
Common mistakes
- Installing into the wrong distribution. A machine can have more than one TeX installation. Check the compiler selected by your editor and use that installation’s package manager.
- Confusing a package name with a file name. The name used by the package manager may not exactly match the
.styfilename. Look up the package rather than relying on a guess. - Assuming the editor is the package manager. TeXstudio, TeXworks, and other editors generally run a TeX distribution; installing an editor does not necessarily install every LaTeX package.
- Ignoring project files. If a template requires a custom
.styfile, installing unrelated standard packages will not supply it. Obtain the file from the template’s source. - Continuing after the first error. Later messages in the log may be consequences of the missing file. Fix the first missing-file error and compile again before diagnosing later errors.
If kpsewhich finds the file but the editor still reports it missing, the editor is probably using a different engine, working directory, or TeX installation than the terminal command. Align those settings and try again.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.