PLEASE THINK BEFORE EDITING! Please do NOT edit this answer in ways which render it distro-specific. Although this question specifically addresses Debian/Ubuntu systems, it serves to provide information to users of GNU/Linux more generally. The way things work on your system may not be the way they work on all GNU/Linux systems - not even all Debian-based systems.
Note that upstream recommend not installing as root. Installing as root introduces a level of risk and has no benefits whatsoever.
Note that I trust the people who are in charge of TeX Live. However, I have been given reason to believe that they are fallible and fallible beings screw up however competent and however well-intentioned they are. Moreover, servers get hacked, downloads get corrupted or intercepted. Shit, basically, happens.
The crucial point is that there is zero benefit to installing with root privileges. All it gets you is an increased security risk. While it may be small, I see no reason to take it.
It is possible to install and manage the installation as your ordinary user. However, that only protects your system directories. Your home directory - where you probably keep all of your personal files and projects - remains exposed. Fortunately, it is easy to protect /home
as well.
If you want to follow upstream's advice, then, here is how I do it...
Set up a dedicated user/group and create a suitable home for it
This is the only part you need root privileges for.
The following are generic instructions which should work for most GNU/Linux distros. If you are using a Debian based system or another distro which features the adduser
script, see the note below for an easier method. Otherwise, use the useradd
command as follows.
Generic GNU/Linux distro: useradd
sudo useradd -d /usr/local/texlive -m -r -U -s /bin/sh texlive
This creates a new user, texlive
, as a member of a new group, texlive
. It creates a home directory for texlive
at /usr/local/texlive
.
If you have previously installed TeX Live from upstream, omit the -m
flag from the above command. Instead, once you have created the new user, do this:
sudo chown -Rh texlive:texlive /usr/local/texlive
Be sure to set a password:
sudo passwd texlive
You will be asked to choose and confirm a password. Note that what you type will not show up on the screen at all. Just type the password and hit enter. Then do the same to confirm.
If you wish, you can choose some other name for the user/group, so long as it is unique on your system. Suppose you want to use tladmin:tladmin
, then you need
sudo useradd -d /usr/local/texlive -m -r -U -s /bin/sh tladmin
sudo passwd tladmin
or, if you've previously installed TeX Live as another user, omit the -m
flag and add
sudo chown -Rh tladmin:tladmin /usr/local/texlive
In what follows, <username for texlive>
denotes the user name and group of texlive>
denotes the group. So, in our examples, both are texlive
or tladmin
.
Debian-based distro: adduser
If you are using Debian or a Debian derivative then, according to this question and given Andrew Cashner's experience, you should probably use adduser
rather than useradd
. According to Andrew:
sudo adduser texlive
or, if you want to use a different user name, such as tladmin
sudo adduser tladmin
is sufficient but notice that this will create an additional directory /home/texlive
or /home/tladmin
which the useradd
method does not. In this case, <username for texlive>
's home will be /home/<username for texlive>
and not /usr/local/texlive
. Moreover, <username for texlive>
's primary group will depend on the defaults for your system: you might get <username for texlive>:<username for texlive>
(e.g. texlive:texlive
or tladmin:tladmin
) or you might get <username for texlive>:staff
(e.g. texlive:staff
or tladmin:staff
) or <username for texlive>:users
(e.g. texlive:users
or tladmin:users
). You can use
groups <username for texlive>
to discover which group <username for texlive>
is assigned to. For example, use
groups texlive
if texlive
is the name of the user you added, or
groups tladmin
for tladmin
.
If the result includes <username for texlive>
(e.g. texlive
or tladmin
), use this group in what follows. Otherwise, you probably only get a single group listed e.g. users
and should use that one. In the following, I'll call this group <group of texlive>
and denote the user name you're using by <username for texlive>
. If you have not installed from upstream before:
sudo mkdir -p /usr/local/texlive
sudo chown -Rh <username for texlive>:<group of texlive> /usr/local/texlive
If you have installed from upstream before, then just:
sudo chown -Rh <username for texlive>:<group of texlive> /usr/local/texlive
Switch to the new user before installing
Now login as <username for texlive>
:
su -l <username for texlive>
Give the password and you will be in <username for texlive>
's home directory. That is, you will be in /usr/local/texlive
. (If you used the Debian method above, cd /usr/local/texlive
to move from the home directory.)
Now follow Silex's instructions but omit all occurrences of sudo
. You don't need them.
Note that this method not only protects your system directories, it also protects your home. The <username for texlive>
user cannot write to your normal home directory. So even if somebody screws up and the installer tries to delete all your documents, it will not be allowed to do so. In fact, if you were to get any permissions errors whatsoever, that would be a red flag. The installer is not supposed to touch anything outside /usr/local/texlive
at all.
Aftercare: when to use root
You will need sudo
to install the fake packages and to integrate TeX Live's fonts into the system configuration. That's because these steps involve system directories. The fake packages get installed for the system and the font configuration involves altering files in /etc
. That all necessarily requires root privileges.
Maintenance: updating your installation
When you are ready to update TeX Live, simply login as <username for texlive>
prior to running the update:
su -l <username for texlive>
# give the password
tlmgr update --all
Do not use sudo
or switch to root. The whole point is that tlmgr
runs as an unprivileged user and cannot touch your home or system directories.
In general, if you want to change anything under /usr/local/texlive
, su <username for texlive>
before you do it. If you want to do something in /etc
or under /opt
, you need root privileges (sudo
or similar).
Loosely related notes
The use of single configuration files in /etc
seems to be going out of fashion. If you find that /etc/environment
does not set your PATH
, it may be somewhere else. For example, on some systems, PATH
is set in /etc/profile
and should be extended by adding a file named something like /etc/profile.d/texmf.sh
for shells such as sh
or bash
:
# /etc/profile.d/texlive.sh
if [ $UID != 0 ]
then
[ -d "<path to binaries>" ] && export PATH="<path to binaries>:${PATH}"
fi
This avoids adding TeX Live binaries automatically to root's PATH
. In order to avoid needing to adapt this file when you install a new edition of TeX Live, you can use a system of symbolic links.
cd /usr/local/texlive
ln -s <YYYY>/bin/x86_64-linux bin.<YYYY>
ln -s <YYYY> current.<YYYY>
ln -s bin.<YYYY> bin
ln -s current.<YYYY> current
Then/etc/profile.d/texmf.sh
can contain just
# /etc/profile.d/texlive.sh
if [ $UID != 0 ]
then
[ -d "/usr/local/texlive/bin" ] && export PATH="/usr/local/texlive/bin:${PATH}"
fi
and PATH
will be set to include the current binaries automatically. When you install a new edition of TeX Live, you just add further links (2 per edition) and adjust the current
and bin
link to point to whichever edition you want to be active. This can all be done as <username for texlive>
, with no need for root privileges. (That is, the .sh
file in /etc/profile.d
must be created with root privileges, but you need not touch this file when installing or activating a new edition of TeX Live.)