This does feel a big thing for one person to take on and get right straight away so let's draft it here. CW for easy editing.
Question
I need to install a new TeX/LaTeX/ConTeXt package on my computer. I'm running Ubuntu/Fedora/Slackware Linux. What are the possible ways to do this?
Answer
Method 1:
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:
Method 2
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?.
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:
which tlmgr
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 which tlmgr
.)
Method 3
Install manually
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
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 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 texhash
) via sudo
. If mktexlsr
is not in the path that sudo
searches, you will need to locate it. You can do:
which mktexlsr
sudo /path/to/mktexlsr
Or if your shell allows it:
sudo $(which mktexlsr)
This isn't necessary for local installations.
Note on sudo
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 bash
and zsh
shells: if you use another shell you may need to provide the full path to tlmgr
instead.