Method 1--(Preferred Method)
Install the latest TeX Live
This is for if the package is in TeX Live and you want to or are using 'vanilla' TeXLive.
If you haven't yet installed TeX Live, follow the instructions at How to install "vanilla" TeXLive on Debian or Ubuntu? (these instructions apply to Linux systems in general, not just Debian-based ones).
How you install a package via TeX Live depends on whether you installed TeX Live as a single user or you installed it system-wide. If the first, try:
tlmgr install <package>
If the second, you will have a small problem in that
tlmgr might not be in the path that
sudo automatically searches. So you need to locate it first and use
sudo to call it with the full path. If your shell has the
which builtin, you can find
tlmgr using the command
which tlmgr. Thus:
sudo /path/to/tlmgr install <package>
If your shell allows you to use the output of a command as a sort of variable, you can use the following command to condense the above (where we exploit the fact that
which returns a single instance of the command regardless of how many times it appears on the path):
sudo $(which tlmgr) install <package>
(You can test your shell with the less risky
echo $(which tlmgr): this should produce the same as
Find and install the package through your package manager.
This is for if you are using the version of TeX that came with your distribution and you don't mind particularly which version of the package you install.
Linux distributions tend to include TeX as a collection of packages, but it isn't usually on as fine a level as one TeX package equals one Linux package. You therefore need to find the right distribution package containing the TeX package that you want and install it. Different package managers have different methods of searching, if all else fails there is often a website where you can search for a specific file:
In this situation, you have two options: to install system-wide (all users on your system) or to install just for you. System-wide means that any user on your system will be able to use it, just for you means just that: it will only be installed for your account. The difference between the two is the base location:
- System-wide: type
kpsewhich -var-value TEXMFLOCAL in the Terminal to find the right directory
- Just for you: type
kpsewhich -var-value TEXMFHOME in the Terminal to find the right directory
One thing to note here is that in the case of a 'package clash', i.e., the same file is found in multiple places (such as the 'system' location, the 'local' location, and/or the 'individual user' location), only the first instance of the file will be used. In this case, the order of precedence is usually: individual user (
TEXMFHOME) > local (
TEXMFLOCAL) > system. The full list (in the right order) can be determined by running
kpsewhich --var-value TEXINPUTS.
What happens now depends a bit on the package. If it is distributed in TDS then you are in luck. Go to the directory reported by
kpsewhich, and into the
tex subdirectory (or create it if it does not exist). Then extract the TDS file (remember to use
sudo if globally, and check that your
umask is set to
022). Note check the TDS file first to ensure that it will extract into the right place: you may need to move up or down a directory to get it to match.
If it is not distributed in TDS, then there are two options: If the package is available from TeX Live, you can get the TDS packaged version from http://mirror.ctan.org/systems/texlive/tlnet/archive/.tar.xz, and unpack it into a temporary directory. In most cases it will contain subdirectories like tex, fonts, etc. Copy these to the TEXMF tree as decided above. In case it contains a directory texmf-dist or similar, it is a package that also ships some scripts or different things outside the texmf hierarchy, in this case it is the best to contact an expert. Finally, you can also download the package from CTAN or the original distribution channel, unpack it and then there might be instructions - in which case follow them - but the general pattern is pretty similar. If it is a LaTeX package, create a directory in
<base dir>/tex/latex/<package name> for it and extract the files (
.sty plus perhaps
.cls, etc.) there. Documentation files go in
<base dir>/doc/latex/<package name>.
If you installed it globally, you will now need to run
mktexlsr (or equivalently
mktexlsr is not in the path that
sudo searches, you will need to locate it. You can do:
Or if your shell allows it:
sudo $(which mktexlsr)
This isn't necessary for local installations.
Point to it
This is for the case where you have a
.cls file which you don't want to install centrally, for one reason or another. For example, it may be specific to a particular project (for example an unusual journal style file), or it may be known to clash with other packages, or you may wish to keep it alongside the source files in a repository.
As described above, the TeX family of programs consult a path when looking for input files, including
.cls files. You can override this with the
TEXINPUTS environment variable, which (on unix) consists of a sequence of directories separated by colons; TeX searches each of these directories in turn. Thus, if you had a
.sty file in a subdirectory
would cause TeX to search for the file in that directory first.
On Windows, you may need to use
; instead of
Note the trailing colon: this is followed by an empty path element, which causes TeX to insert the standard search path in that position. Thus
TEXINPUTS=:styles would cause TeX to search the standard path before the subdirectory
As above, you can use
kpsewhich to check things are configured correctly.
% ls styles
% kpsewhich myfancypackage.sty # doesn't find anything
% export TEXINPUTS=styles:
% kpsewhich myfancypackage.sty
styles/myfancypackage.sty # found it!
Notes and Supplementary
When you add TeX Live to your path, it will not normally be added to the path for the root user, so will not be visible using
sudo. The methods above use
which to find
tlmgr , etc., from the 'normal user' path and pass the correct instruction to
sudo. This works with the
zsh shells: if you use another shell you may need to provide the full path to
sudo, the environment used is a mixture of the superuser's and the local user's. As well as the path mentioned above, it is important to ensure that the
umask setting is sufficiently lax: a user should have a
077 but root of
umask controls the default permissions of newly created files: with
077 only root would be able to read (and thus use) them. With
022, everyone can read (and possibly execute) them.
If your system does not have
sudo installed by default, it probably has it in its package repository. If not, see How universal is sudo? for alternatives.
To speed up its searching, the
kpathsea library uses caches in the form of files called
ls-R in various directories. These contain all the files that
kpathsea would find if it searched properly in that directory (obeying any recursive search directives). The files are recreated by the
mktexlsr command (which is short for "Make TeX's ls-R files") which has to be run manually (by someone with write access to the directory, usually root - see the note on sudo) if it is needed. This command used to be called
texhash and that is still an alias for this command (technically, a symlink).
TeX uses the
kpathsea library for finding its files. Where this looks depends on various variable which can be set in configuration files or by the user's shell. The list of directories that
kpathsea searches in can be displayed by typing
kpsewhich --var-value TEXINPUTS. The output is a little condensed. The following attempts to clarify it a little:
- Paths are separated by colons (as in environment variables such as
- If a path begins with
!! it means that the
ls-R file will be consulted instead of the filesystem.
- If a path ends with
// it will be searched recursively.
- Paths or parts of paths can be grouped using braces.
/usr/local/texlive/2012/texmf-var will both be searched, in that order. Both will actually use the cache which is stored in
ls-R in the base of the search (thus
/usr/local/texlive/2012/texmf-dist/ls-R, for example). And both searches will be recursive.
Testing the Installation
The simplest way to check that the installed file is being found is to run
<package_name> includes the extension). If this lists the newly installed file, all should be fine. If it doesn't but does display something then it may be that there is another version of this package installed which is being found first. If that is the case, then
kpsewhich --all <package_name>
will list all of the matching names so you can test to see if it is finding it at all.
If it did find it but isn't using it, you will either have to choose a location which is searched earlier than the version that is being found or remove the version(s) that are being found first.
If it did not find it at all, there are some possible reasons.
If you did a full installation of TeX Live, is the
kpsewhich command from the new installation? Try
which kpsewhich to find out. If not, adjust your
$PATH and try again. (If your path is correct, it might be that your shell hasn't noticed it: try
rehash to correct this (Bourne-Again Shells)).
If you only installed a package, did you put it somewhere that TeX can find it? The full list of directories in which TeX searches can be found by running
kpsewhich --var-value TEXMF
These are searched recursively.
- If it is in a directory that TeX searches, and that directory is prepended in the list by
!! then it is one where TeX consults the cache, not the actual files on the disc. To recreate the cache, run
texhash as super-user.
If you do not use the package manager to install TeX or one of its packages (i.e., you didn't use Method 1), then the package manager will not know that what you have just installed is installed. This means that installing system packages that depend on these manually installed packages will try to install them again. The simplest solution is to let them do so as it is usually the case that your manually installed things are found before the system ones. If space is tight, many distributions have "dummy" packages that can be installed to trick the package manager. See How to install "vanilla" TeXLive on Debian or Ubuntu? for more details.