如何更新 TeX Live

1. 缘起

今天,在使用 tlmgr 打算安装一个工具的时候,突然遇到系统提示,

tlmgr: Local TeX Live (2023) is older than remote repository (2024).
Cross release updates are only supported with
  update-tlmgr-latest(.sh/.exe) --update
See https://tug.org/texlive/upgrade.html for details.

记得上次出现这样的提示还在去年,当时一顿操作猛如虎,导致出现的 bug 到最近才修复完成,而且当时的过程完全没有记录下,导致现在又要升级了,感觉像是,“辛辛苦苦几十年,一下回到解放前”,为了吸取上次的教训,这次打算把整个 \(\TeX{}\ \text{Live}\)​​ 升级的过程做个完整的记录,以备不时之需。

2. TeX Live 更新的两种方案

官方提供了提供了两种方案去升级 \(\TeX{}\ \text{Live}\),

  • 直接安装最新的 \(\TeX{}\ \text{Live}\) (默认方案
  • 在原有 \(\TeX{}\ \text{Live}\) 基础之上进行升级

两种方案对比起来,默认方案比较简单,但是如果在当前的 \(\TeX{}\ \text{Live}\) 中进行过一些特殊的设置,这种方案并不会保留这些设置;相比之下,第二种方案就会保留这些设置,但是操作起来会更麻烦,需要熟悉 \(\TeX{}\ \text{Live}\)。

本文主要是采用第二种方案对 \(\TeX{}\ \text{Live}\) 进行更新,如果想直接安装最新的 \(\TeX{}\ \text{Live}\) 可以直接参照文章提供的关于默认方案的链接进行相关操作即可。

注:上述两种方案是针对 Unix,如果使用的是 Windows 则没有第二种可选方案,需要直接安装最新版本。

3. 在原有 TeX Live 基础上升级

3.1 拷贝当前的 TeX Live

  1. 首先,找到当前 \(\TeX{}\ \text{Live}\) 的安装目录,默认为 /usr/local/texlive

    $ cd /usr/local/texlive
    
  2. 对整个 2023 目录进行完整拷贝,保留目录中的符号链接

    $ cp -a 2023 2024
    

    为了节省空间,可以考虑删除 tlpkg/backups/* 下的备份文件,

    $ rm -rf 2024/tlpkg/backups/*
    

3.2 修改 PATH 中 TeX Live 的指向

  1. 根据需要,调整启动文件(比如:.bashrc)中的 PATH 以指向 .../2024/bin/*platform*

    # 修改前
    # Set Tex Live's MANPATH, INFOPATH and PATH
    export MANPATH=$MANPATH/usr/local/texlive/2023/texmf-dist/doc/man
    export INFOPATH=$INFOPATH/usr/local/texlive/2023/texmf-dist/doc/info
    export PATH=$PATH:/usr/local/texlive/2023/bin/x86_64-linux
       
    # 修改后
    # Set Tex Live's MANPATH, INFOPATH and PATH
    export MANPATH=$MANPATH/usr/local/texlive/2024/texmf-dist/doc/man
    export INFOPATH=$INFOPATH/usr/local/texlive/2024/texmf-dist/doc/info
    export PATH=$PATH:/usr/local/texlive/2024/bin/x86_64-linux
    
  2. 修改完成后,注销并登录,并确认 PATH 现在具有 2024 目录

    $ echo $PATH | grep -i texlive/2024
    

    注:这里最好注销在登录,而不是直接使用 source 去重新加载启动文件,因为这样在 PATH 中可能还是会出现 texlive/2023,并且极有可能出现在 texlive/2024 前面。

3.3 升级 TeX Live

  1. 回到顶级 .../2024 目录

    $ cd /usr/local/texlive/2024
    
  2. 下载最新的 update-tlmgr-latest.sh

    $ wget https://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh
    
  3. 运行 update-tlmgr-latest.sh 更新 \(\TeX{}\ \text{Live}\)

    $ sh update-tlmgr-latest.sh -- --upgrade
    

    如果输出了以下信息说明升级成功,

    # Outputs
    Verifying archive integrity...  100%   MD5 checksums are OK. All good.
    Uncompressing TeX Live Manager Updater  100%
    ./runme.sh: updating in /usr/local/texlive/2024...
    ./runme.sh: tlmgr version says this is TeX Live 2023,
    ./runme.sh: and this updater script created: Sat Mar 16 14:47:04 CET 2024.
    ./runme.sh: ok, doing full release upgrade  from 2023 to 2024.
    ./runme.sh: updating /usr/local/texlive/2024/bin/x86_64-linux ...
    ./runme.sh: /usr/local/texlive/2024/bin/x86_64-linux/tlmgr including objects: master/tlpkg/tlpobj/texlive.infra.tlpobj master/tlpkg/tlpobj/texlive.infra.x86_64-linux.tlpobj
    D:tlmgr version 70080 (2024-02-23 00:13:07 +0100)
    D:maintree=/usr/local/texlive/2024
    D:appending to package log file: /usr/local/texlive/2024/texmf-var/web2c/tlmgr.log
    D:appending to command log file: /usr/local/texlive/2024/texmf-var/web2c/tlmgr-commands.log
    D:Setting env var HTTPS_CA_FILE to /usr/local/texlive/2024/tlpkg/installer/curl/curl-ca-bundle.crt
    D:tlmgr:main: ::tldownload_server hash:: {enabled:1,errorcount:0,initcount:1,ua:LWP::UserAgent=HASH(0x558e8481d790)}
    D:setup_programs: preferring system versions
    D:program df found in path
    D:program curl found in path
    D:program wget found in path
    D:TLUtils::setup_programs: checking for ssl enabled wget
    D:TLUtils::setup_programs: wget has ssl, final wget args: --no-check-certificate --user-agent=texlive/wget --tries=4 --timeout=30 -q -O
    D:program lz4 not usable from path
    D:(unix) trying to set up lz4, default /usr/local/texlive/2024/tlpkg/installer/lz4/lz4.x86_64-linux, arg --version
    D: Using shipped /usr/local/texlive/2024/tlpkg/installer/lz4/lz4.x86_64-linux for lz4 (tested).
    D:program gzip found in path
    D:program xz found in path
    ./runme.sh: done.
    

    如果出现以下提示,

    # Outputs
    Verifying archive integrity... All good.
    Uncompressing TeX Live Manager Updater  100%  
    ./runme.sh: Cannot find TeX Live root using kpsewhich --var-value=SELFAUTOPARENT.
    ./runme.sh: (no tlpkg/texlive.tlpdb and/or tlpkg/tlpobj/.)
    ./runme.sh: Please set your PATH as needed, otherwise it's hopeless.
    

    首先,确认 kpsewhich 所在的位置,

    $ which kpsewhich
    

    如果正确指向 .../2024/bin/*platform*,则参考这篇文章解决。否则,重新检查 PATH 设置,让 kpsewhich 能指向正确位置。

  4. 重置存储库(repository)以更新 CTAN

    $ tlmgr option repository ctan
    tlmgr: setting default package repository to https://mirror.ctan.org/systems/texlive/tlnet
    tlmgr: updating /usr/local/texlive/2024/tlpkg/texlive.tlpdb
    
  5. 更新 tlmgr 下载所有新材料

    $ tlmgr update --self --all
    

至此,\(\TeX{}\ \text{Live}\) 更新完毕,成功从 2023 更新到 2024。如果新的 \(\TeX{}\ \text{Live}\) 使用起来没有什么问题的话,可以考虑运行 .../2023/.../tlmgr uninstall(详见,完整的 tlmgr 文档)来删除旧版的 \(\TeX{}\ \text{Live}\)​,但是最好先保留,因为新版本的东西总是在适配性上会出现问题。

4. 写在最后

回顾整个升级的过程可以发现,第二种升级 \(\TeX{}\ \text{Live}\) 的方式还是比较复杂的,如果没有什么特别的理由的话,还是建议选择第一种默认升级方案,就像 \(\TeX{}\ \text{Live}\) 官方也在反复强调的一样,“To reiterate from the top, don’t do any of this if it doesn’t make sense to you. Just do a fresh installation”,当然如果你和我一样有着不得不那么做的理由,那么希望这篇文章能对你有所帮助。

标签:

分类:

更新时间:

留下评论