Skip to content

Installing TinyTeX globally for all users on Linux server / RStudio Server #415

@salim-b

Description

@salim-b

Goal

I want to install TinyTeX system-wide to be used by all users of an RStudio Server instance.

So far

To accomplish that goal, I've ran the following steps on a root terminal session on the RStudio Server:

# install TinyTex for the root user
bash -c 'wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh'

# move TinyTex installation from root home dir to `/opt/tinytex` and update the necessary config and symlinks
tlmgr path remove \
  && mv ~/.TinyTeX /opt/tinytex \
  && /opt/tinytex/bin/*/tlmgr option sys_bin /usr/local/bin \
  && /opt/tinytex/bin/*/tlmgr path add

# change group ownership to `staff` of whole TinyTex dir (all users are members of staff)
chown -R root:staff /opt/tinytex

# make whole TinyTex dir group-writable
chmod -R g+w /opt/tinytex \
  && chmod -R g+wx /opt/tinytex/bin

# set GID bit on all folders of TinyTex dir, cf. https://en.wikipedia.org/wiki/Setuid#When_set_on_a_directory
find /opt/tinytex -type d -exec chmod g+s {} +

# pretend all `texlive*` DEB packages have been installed, cf. https://yihui.org/tinytex/faq/#faq-7
wget "https://travis-bin.yihui.org/texlive-local.deb" \
  && apt-get install ./texlive-local.deb \
  && rm texlive-local.deb

# make `/usr/local/bin` owned by group `staff` and group-writable, so that `tlmgr path add` succeeds without root privileges
# NOTE: as per Debian wiki, this is the intended behaviour: https://wiki.debian.org/SystemGroups#Other_System_Groups
chown :staff /usr/local/bin \
    && chmod g+w /usr/local/bin

With the above, non-root users (which are member of group staff) can read the shared TinyTeX installation as well as generate the necessary symlinks for the TeX executables via tlmgr path add or tinytex::tlmgr_path(action = "add") . Automatically installing additional TeX packages during knitting as well as manual installation via tlmgr install <PKG> or tinytex::tlmgr_install() also works for non-root users, but the latter prints some messages about failed permission changes to /opt/tinytex/tlpkg/texlive.tlpdb like

chmod(420,/opt/tinytex/tlpkg/texlive.tlpdb) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.

The same message is also printed when a non-root user removes a package via tlmgr remove <PKG> or tinytex::tlmgr_remove() (since in both cases the texlive.tlpdb gets updated). The message is a bit cryptic to me since chmod 420 is not what /opt/tinytex/tlpkg/texlive.tlpdb) should have (and also not what it does have after the root user runs the same commands; instead it becomes chmod 644). 420 is the decimal representation of the octal 644 mask, as @norbusan pointed out.

The output of tinytex::tlmgr_conf() after the above is for any user

Output:
=========================== version information ==========================
tlmgr revision 66798 (2023-04-08 02:15:21 +0200)
tlmgr using installation: /opt/tinytex
TeX Live (https://tug.org/texlive) version 2023
==================== executables found by searching PATH =================
PATH: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/quarto/bin:/usr/lib/rstudio-server/bin/postback
dvipdfmx:  /usr/local/bin/dvipdfmx
dvips:     /usr/local/bin/dvips
fmtutil:   /usr/local/bin/fmtutil
kpsewhich: /usr/local/bin/kpsewhich
luatex:    /usr/local/bin/luatex
mktexpk:   /usr/local/bin/mktexpk
pdftex:    /usr/local/bin/pdftex
tex:       /usr/local/bin/tex
tlmgr:     /usr/local/bin/tlmgr
updmap:    /usr/local/bin/updmap
xetex:     /usr/local/bin/xetex
=========================== active config files ==========================
config.ps:        /opt/tinytex/texmf-dist/dvips/config/config.ps
fmtutil.cnf:      /opt/tinytex/texmf-dist/web2c/fmtutil.cnf
mktex.cnf:        /opt/tinytex/texmf-dist/web2c/mktex.cnf
pdftexconfig.tex: /opt/tinytex/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex
texmf.cnf:        /opt/tinytex/texmf.cnf
texmf.cnf:        /opt/tinytex/texmf-dist/web2c/texmf.cnf
updmap.cfg:       /opt/tinytex/texmf-dist/web2c/updmap.cfg
============================= font map files =============================
kanjix.map:  /opt/tinytex/texmf-var/fonts/map/dvipdfmx/updmap/kanjix.map
pdftex.map:  /opt/tinytex/texmf-var/fonts/map/pdftex/updmap/pdftex.map
ps2pk.map:   /opt/tinytex/texmf-var/fonts/map/dvips/updmap/ps2pk.map
psfonts.map: /opt/tinytex/texmf-var/fonts/map/dvips/updmap/psfonts.map
=========================== kpathsea variables ===========================
ENCFONTS=.:{{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}/fonts/enc//
SYSTEXMF=/opt/tinytex/texmf-var:/opt/tinytex/texmf-local:/opt/tinytex/texmf-dist
TEXCONFIG={{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}/dvips//
TEXFONTMAPS=.:{{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}/fonts/map/{kpsewhich,pdftex,dvips,}//
TEXMF={{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}
TEXMFCONFIG=/opt/tinytex/texmf-config
TEXMFDBS={!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}
TEXMFDIST=/opt/tinytex/texmf-dist
TEXMFHOME=/opt/tinytex/texmf-local
TEXMFLOCAL=/opt/tinytex/texmf-local
TEXMFMAIN=/opt/tinytex/texmf-dist
TEXMFSYSCONFIG=/opt/tinytex/texmf-config
TEXMFSYSVAR=/opt/tinytex/texmf-var
TEXMFVAR=/opt/tinytex/texmf-var
TEXPSHEADERS=.:{{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}/{dvips,fonts/{enc,type1,type42,type3}}//
VARTEXFONTS=/opt/tinytex/texmf-var/fonts
WEB2C={{}/opt/tinytex/texmf-config,/opt/tinytex/texmf-var,/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-local,!!/opt/tinytex/texmf-config,!!/opt/tinytex/texmf-var,!!/opt/tinytex/texmf-dist}/web2c
==== kpathsea variables from environment only (ok if no output here) ====

Remaining issues

  1. Removing or installing additional TeX packages via the root account changes permissions of file /opt/tinytex/tlpkg/texlive.tlpdb to not be group-writable anymore, rendering it impossible for non-root users to perform tlmgr install or tlmgr remove anymore. This is annoying but can be fixed by a simple chmod g+w /opt/tinytex/tlpkg/texlive.tlpdb. The changed group-write permission is retained when that file is updated during installation of additional packages by non-root users (since the subsequent permission modification to texlive.tlpdb fails in such case, see above) .

  2. Running fmtutil-sys --all (also via tinytex::tlmgr_update(run_fmtutil = TRUE)) the first time as non-root user prints the following (error) messages:

    chmod(420,/opt/tinytex/texmf-var/web2c/pdftex/pdftex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/xetex/xetex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/luatex/luatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/tex/tex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/luahbtex/luahbtex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/luatex/dviluatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/metafont/mf.base) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/pdftex/latex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/pdftex/pdflatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/luahbtex/lualatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/luatex/dvilualatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/pdftex/etex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/xetex/xelatex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    chmod(420,/opt/tinytex/texmf-var/web2c/pdftex/pdfetex.fmt) failed: Operation not permitted at /opt/tinytex/tlpkg/TeXLive/TLUtils.pm line 1488.
    fmtutil [ERROR]: cannot copy format pdftex.fmt to: /opt/tinytex/texmf-var/web2c/pdftex/pdftex.fmt
    fmtutil [ERROR]: cannot copy format xetex.fmt to: /opt/tinytex/texmf-var/web2c/xetex/xetex.fmt
    fmtutil [ERROR]: cannot copy format luatex.fmt to: /opt/tinytex/texmf-var/web2c/luatex/luatex.fmt
    fmtutil [ERROR]: cannot copy format tex.fmt to: /opt/tinytex/texmf-var/web2c/tex/tex.fmt
    fmtutil [ERROR]: cannot copy format luahbtex.fmt to: /opt/tinytex/texmf-var/web2c/luahbtex/luahbtex.fmt
    fmtutil [ERROR]: cannot copy format dviluatex.fmt to: /opt/tinytex/texmf-var/web2c/luatex/dviluatex.fmt
    fmtutil [ERROR]: cannot copy format mf.base to: /opt/tinytex/texmf-var/web2c/metafont/mf.base
    fmtutil [ERROR]: cannot copy format latex.fmt to: /opt/tinytex/texmf-var/web2c/pdftex/latex.fmt
    fmtutil [ERROR]: cannot copy format pdflatex.fmt to: /opt/tinytex/texmf-var/web2c/pdftex/pdflatex.fmt
    fmtutil [ERROR]: cannot copy format lualatex.fmt to: /opt/tinytex/texmf-var/web2c/luahbtex/lualatex.fmt
    fmtutil [ERROR]: cannot copy format dvilualatex.fmt to: /opt/tinytex/texmf-var/web2c/luatex/dvilualatex.fmt
    fmtutil [ERROR]: cannot copy format etex.fmt to: /opt/tinytex/texmf-var/web2c/pdftex/etex.fmt
    fmtutil [ERROR]: cannot copy format xelatex.fmt to: /opt/tinytex/texmf-var/web2c/xetex/xelatex.fmt
    fmtutil [ERROR]: cannot copy format pdfetex.fmt to: /opt/tinytex/texmf-var/web2c/pdftex/pdfetex.fmt
    

    Subsequent runs don't emit these messages anymore and successfully copy the .fmt files (but they become chmod 644, i.e. not group-writable). I have no clue what exactly is going on here.

Both of these issues seem to lie in the upstream TeX Live perl scripts and not in TinyTeX itself. Any ideas on how to fix them? The issues seem to be somewhat similar to #77 (which has eventually been fixed upstream).

Relevant documentation


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('tinytex'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/tinytex').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions