Where do I place my own .sty or .cls files, to make them available to all my .tex files?

You could create a folder below your TeX home directory and put your .sty file therein. Use this command at the command prompt to find out where:

kpsewhich -var-value=TEXMFHOME

On my computer it shows

C:/Users/stefan/texmf

but it might also be ~/texmf/ on a Linux or Unix computer.

Following the TeX directory structure, you should place your file in a subdirectory like ~/texmf/tex/latex/commonstuff/, according to Arthur's comment below. This has the advantage that it is not necessary to update the package database as TeX searches your personal texmf tree directly. If there is an ls-R file in your home texmf tree you can safely delete it as TeX will not use it anyway. (Note: this assumes your personal tree is on a local file system: users with remotely-mounted home folders may still need to hash.)

Regarding MiKTeX, have a look at the section "Installing sty or cls files" in the answer to the question How can I manually install a package on MikTex (Windows).

You can then verify what file will be used with:

kpsewhich filename.sty

This will show the path to the file picked up by the TeX implementation.


All of the other answers cover things quite well, but I thought a slightly different version might be helpful.

There are two parts to telling TeX about a new .sty file. First, you have to put it in the 'right' place and second you need to update the database TeX uses to find files. The place to put the file depends on your operating system. Assuming you have a standard installation, this will probably be:

  • Windows 10 (and miktex)
    C:\Users\<user name>\Appdata\Local\MikTex\<number>\tex\latex\local\
  • Windows Vista/7 C:\Users\<user name>\texmf\tex\latex\local\
  • Windows XP C:\Documents and Settings\<user name>\texmf\tex\latex\local\
  • Linux ~/texmf/tex/latex/local/
  • Mac OS X /Users/<user name>/Library/texmf/tex/latex/local/

Note: the local/ folder might not exist; in this case, go ahead and create it.

A few of notes on that. First, on Windows the 'Users' part of the location is language dependent. Second, I've represented your home/user folder as '<user name>': this will obviously be dependent on your system. The folder I've indicated may well not exist: you may just have the texmf part, bits within that or nothing at all. The file location is important, and although you could just put your file inside texmf/tex/latex is is usual to keep things organised by package. The local folder is reserved for stuff installed on individual machines.

Letting TeX 'know' about the file means running a program that builds a database of file locations. There are graphical interfaces to do this, but the way that works on all operating systems is to use the Command Prompt/Terminal and type texhash. This will build the databases for your tree (the one that is in your home folder). Once the 'hash' is created TeX should be able to find your file. For recent TeXLive distributions, this step is not necessary for files in the local folder.


As already mentioned by Arthur, .sty or .cls files must be in some subdirectory of tex\latex which can be in any directory of any drive.

See the following screenshot, it shows how the path to my packages and classes is.

enter image description here

I will explain two cases, registering to MikTeX and registering to TeX Live.

Registering to MikTeX

Open Settings (Admin), select Roots tab, and add my path E:\A\My LaTeX\MyLibrary.

Note that the trailing \tex\latex\misc must not be included !

enter image description here

Afterwards, select General tab and press Refresh FNDB button.

enter image description here

If you cant find MiKTeX Options (Admin) you may have a newer installation that instead uses MiKTex Console. For this version, simply go to the Packages tab and click the database icon.

Registering to TeX Live

See How to register my own packages or classes in a separate drive to TeX Live installation?