% !TeX root = ../install-latex-guide-zh-cn.tex \chapter{Ubuntu 22.04 系统} \section{安装 \TeX{} Live} 这里只阐述如何用镜像安装. 为使用户顺利使用 \TeX{} Live 2024, 建议用户首先卸载从源内安装的 \TeX{} Live 的相关包, 具体方法见 \ref{sec:ubuntu:uninstall}~节. 为了减少后续字体问题和文本编辑问题, 安装前在 \textsf{Terminal} 中执行 \begin{lstlisting}[language=bash] sudo apt install fontconfig gedit \end{lstlisting} 由于大陆地区网络现状, 建议在执行命令前更换 Ubuntu 源, 参考 \ref{sec:addition:source}~节. 以下未特殊声明, 均指在 \textsf{Terminal} 中执行相关命令. 下载 \href{https://mirrors.ctan.org/systems/texlive/Images/texlive2024.iso}{iso 镜像文件} 的方法见 \ref{sec:windows:install}~节. 下载完毕后, 验证 MD5 值, 即执行以下命令 \begin{lstlisting}[language = bash] cd ~/Downloads md5sum texlive2024.iso \end{lstlisting} 若显示 \begin{lstlisting} a54f5524e51267dee37e72e3b3fd31c4 texlive2024.iso \end{lstlisting} 则镜像文件下载正确. 同样可验证 SHA512 值, 执行 \begin{lstlisting}[language = bash] cd ~/Downloads sha512sum texlive2024.iso \end{lstlisting} 正确的返回结果为 \begin{lstlisting}[language=bash,literate={a}{a}{1} {b}{b}{1} {c}{c}{1} {d}{d}{1} {e}{e}{1} {f}{f}{1}] 6e3c3470ee5ca903bb5c31f436b018cd2cfbc526c4ca563ccb15959802f8b1a6c0475c58566c1afaba19dc780fd192ac5511818ef5a89828d935c66c62cfcb2a texlive2024.iso \end{lstlisting} 将下载的光盘镜像进行装载 \begin{lstlisting}[language = bash] sudo mkdir /mnt/texlive sudo mount ./texlive2024.iso /mnt/texlive \end{lstlisting} 接下来执行 \begin{lstlisting}[language = bash] sudo /mnt/texlive/install-tl \end{lstlisting} 进行安装. 在屏幕上应该能见到以下内容 \begin{lstlisting} ======================> TeX Live installation procedure <===================== ======> Letters/digits in indicate <======= ======> menu items for actions or customizations <======= = help> https://tug.org/texlive/doc/install-tl.html <======= Detected platform: GNU/Linux on x86_64 set binary platforms: 1 out of 15 set installation scheme: scheme-full set installation collections: 40 collections out of 41, disk space required: 8315 MB (free: 974100 MB) set directories: TEXDIR (the main TeX directory): /usr/local/texlive/2024 TEXMFLOCAL (directory for site-wide local files): /usr/local/texlive/texmf-local TEXMFSYSVAR (directory for variable and automatically generated data): /usr/local/texlive/2024/texmf-var TEXMFSYSCONFIG (directory for local config): /usr/local/texlive/2024/texmf-config TEXMFVAR (personal directory for variable and automatically generated data): ~/.texlive2024/texmf-var TEXMFCONFIG (personal directory for local config): ~/.texlive2024/texmf-config TEXMFHOME (directory for user-specific files): ~/texmf options: [ ] use letter size instead of A4 by default [X] allow execution of restricted list of programs via \write18 [X] create all format files [X] install macro/font doc tree [X] install macro/font source tree [ ] create symlinks to standard directories [X] after install, set CTAN as source for package updates set up for portable installation Actions: start installation to hard disk

save installation profile to 'texlive.profile' and exit quit Enter command: \end{lstlisting} 点击键盘 \keys{I} 进行默认安装. 如果用户对于 Ubuntu 系统比较了解, 可以根据提示, 更改安装设置, 如安装路径等. 为简化起见, 以下内容我们均认为用户采用默认安装. 安装完毕后, 将装载的光盘镜像弹出并删除文件夹, 即执行 \begin{lstlisting}[language = bash] sudo umount /mnt/texlive sudo rm -r /mnt/texlive \end{lstlisting} 安装完成后, 用户需要设置环境变量. 执行 \begin{lstlisting}[language = bash] gedit ~/.profile \end{lstlisting} 在打开的文件末尾添加 \begin{lstlisting} # Add TeX Live to the PATH, MANPATH, INFOPATH export PATH=/usr/local/texlive/2024/bin/x86_64-linux:$PATH export MANPATH=/usr/local/texlive/2024/texmf-dist/doc/man:$MANPATH export INFOPATH=/usr/local/texlive/2024/texmf-dist/doc/info:$INFOPATH \end{lstlisting} 并保存退出. 然后退出登录当前用户并重新登录, 再打开 \textsf{Terminal} 并执行 \begin{lstlisting}[language=bash] tex -v \end{lstlisting} 若显示 \begin{lstlisting} TeX 3.141592653 (TeX Live 2024) kpathsea version 6.4.0 Copyright 2024 D.E. Knuth. There is NO warranty. Redistribution of this software is covered by the terms of both the TeX copyright and the Lesser GNU General Public License. For more information about these matters, see the file named COPYING and the TeX source. Primary author of TeX: D.E. Knuth. \end{lstlisting} 即为安装成功. 接下来处理字体. 在 \textsf{Terminal} 中执行 \begin{lstlisting}[language=bash] sudo cp /usr/local/texlive/2024/texmf-var/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf \end{lstlisting} 将配置文件复制到系统, 然后继续执行 \begin{lstlisting}[language=bash] sudo fc-cache -fsv \end{lstlisting} 刷新字体缓存. 这样一来, \TeX{} Live 中的字体才能够被正确调用. 更多内容请参考 \href{https://www.tug.org/texlive/doc/texlive-en/texlive-en.pdf}{texlive-en}. 如果用户更改了安装路径, 要注意将 \begin{lstlisting} /usr/local/texlive/2024/ \end{lstlisting} 在各处替换. \subsection{在用户文件夹安装}\label{subsec:ubuntu-user-folder} 如果有用户打算在用户文件夹安装 \TeX{} Live, 那么可以不必调用权限, 直接执行 \begin{lstlisting}[language=bash] /mnt/texlive/install-tl \end{lstlisting} 只不过这时安装路径需要选择 \begin{lstlisting}[language=bash] ~/texlive/2024 \end{lstlisting} 安装完毕后, 继续修改环境变量为 \begin{lstlisting} # Add TeX Live to the PATH, MANPATH, INFOPATH export PATH=~/texlive/2024/bin/x86_64-linux:$PATH export MANPATH=~/texlive/2024/texmf-dist/doc/man:$MANPATH export INFOPATH=~/texlive/2024/texmf-dist/doc/info:$INFOPATH \end{lstlisting} 有关字体的处理变为\footnote{这里并未使用 \href{https://www.tug.org/texlive/doc/texlive-en/texlive-en.pdf}{texlive-en} 中建议的路径 \texttt{\~/.fonts.conf.d/}, 因为根据 \href{https://www.freedesktop.org/software/fontconfig/fontconfig-user.html}{freedesktop} 的说法, 该路径已废弃, 故此处采用新的路径, 即 \texttt{\$XDG\_CONFIG\_HOME/fontconfig/conf.d}} \begin{lstlisting}[language=bash] cp ~/texlive/2024/texmf-var/fonts/conf/texlive-fontconfig.conf $XDG_CONFIG_HOME/fontconfig/conf.d/09-texlive.conf \end{lstlisting} 然后执行 \begin{lstlisting}[language=bash] fc-cache -fv \end{lstlisting} 实际上, 无论将 \TeX{} Live 安装到哪里, 字体的配置文件都可以仿照上面只复制于用户文件夹中. \section{卸载 \TeX{} Live}\label{sec:ubuntu:uninstall} 下面提供几种卸载方法, 卸载后需注意清理环境变量. \subsection{卸载源内的版本}\label{sec:ubuntu:aptremove} 如果要卸载从源内安装的 \TeX{} Live, 个人比较推荐使用 synaptic package manager. 在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] sudo apt install synaptic \end{lstlisting} 即可安装. 安装后打开, 搜索 \textsf{texlive} 即可看到与之相关的包, 右键标记以删除即可. 当然, 用户也可以直接使用 \begin{lstlisting}[language = bash] dpkg -l | grep 'TeX Live' \end{lstlisting} 找到相应的包名 \texttt{}, 之后使用类似 \begin{lstlisting}[language = bash] sudo apt autoremove --purge \end{lstlisting} 的命令删除各个包. 通常 \begin{lstlisting}[language = bash] sudo apt autoremove --purge tex-common \end{lstlisting} 就可以删除源内版本. \subsection{手动卸载} 如果是从光盘镜像安装, 直接删除文件夹即可. 先在\textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] kpsewhich -var-value TEXMFROOT \end{lstlisting} 来查询安装路径, 进而通过 \texttt{sudo rm -rf} 命令进行删除. 默认安装的用户直接运行 \begin{lstlisting}[language = bash] sudo rm -rf /usr/local/texlive/2024 rm -rf ~/.texlive2024 \end{lstlisting} 卸载完成后, 可以进一步移除之前设置的环境变量. 在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] gedit ~/.profile \end{lstlisting} 然后移除之前在文件末尾添加的 \begin{lstlisting} # Add TeX Live to the PATH, MANPATH, INFOPATH export PATH=/usr/local/texlive/2024/bin/x86_64-linux:$PATH export MANPATH=/usr/local/texlive/2024/texmf-dist/doc/man:$MANPATH export INFOPATH=/usr/local/texlive/2024/texmf-dist/doc/info:$INFOPATH \end{lstlisting} 并保存退出. 同时在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] sudo visudo \end{lstlisting} 在 \texttt{secure\_path} 中删除 \begin{lstlisting} /usr/local/texlive/2024/bin/x86_64-linux: \end{lstlisting} 然后依次 \keys{\ctrl + X}, \keys{Y}, \keys{\enter} 保存退出. \subsection{使用 \texttt{tlmgr} 工具} 同样, 用户也可以使用 \texttt{tlmgr} 工具卸载% \footnote{\texttt{sudo tlmgr} 无法使用的情况可以参考 \ref{sec:ubuntu:update}~节 解决}, \begin{lstlisting}[language=bash] sudo tlmgr remove --all \end{lstlisting} \section{跨版本升级 \TeX{} Live}\label{sec:ubuntu:version} 在 \href{https://www.tug.org/texlive/upgrade.html}{tug.org} 网站上提供了相应的方法. 但网站也声明: 默认情况下, 请通过执行新安装来获取新版本的 \TeX{} Live% \footnote{原文是: By default, please get the new TL by doing a new installation instead of proceeding here}. \section{升级宏包}\label{sec:ubuntu:update} 首次升级前, 在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] sudo visudo \end{lstlisting} 将 \begin{lstlisting} /usr/local/texlive/2024/bin/x86_64-linux: \end{lstlisting} 添加在 \texttt{secure\_path} 中% \footnote{这里只讨论默认安装的情况}. 然后依次 \keys{\ctrl + X}, \keys{Y}, \keys{\enter} 保存退出. 接下来在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] sudo tlmgr option repository ctan \end{lstlisting} 让系统自动选择源, 同样可以使用大陆地区的源升级, 详情见附录~\ref{chp:appendix:mirror}. 执行命令 \begin{lstlisting}[language = bash] sudo tlmgr update --list \end{lstlisting} 可查看目前源上可升级的宏包都有哪些. 高级用户可以根据自己的需求选择升级特定宏包. 建议初级用户执行 \begin{lstlisting}[language = bash] sudo tlmgr update --self --all \end{lstlisting} 同时升级 \texttt{tlmgr} 本身和全部宏包. \section{安装宏包}\label{sec:ubuntu:installpackage} Ubuntu 22.04 下安装宏包的要求与 Windows 11 下没有多少区别, 只需注意权限, 例如 \begin{lstlisting}[language = bash] sudo tlmgr install mcmthesis \end{lstlisting} 即安装了 \texttt{mcmthesis} 宏包. \section{调出宏包手册}\label{sec:ubuntu:texdoc} 与 Windows 11 类似, 当正确安装后, 用户可以调出宏包手册以查阅相应内容. 例如在 \textsf{Terminal} 中执行 \begin{lstlisting}[language=bash] texdoc texlive-zh-cn texdoc lshort-zh-cn texdoc install-latex-guide-zh-cn \end{lstlisting} 就可分别调出 \texttt{texlive-zh-cn.pdf}, \texttt{lshort-zh-cn.pdf} 或本手册. \section{编译文件} 首先, 用户需要在工作路径建立一个 \texttt{tex} 文件. 在 \textsf{Terminal} 中执行 \begin{lstlisting}[language = bash] mkdir ~/Documents/work-latex cd ~/Documents/work-latex/ gedit main.tex \end{lstlisting} 在打开的文件输入一个最小示例 \begin{lstlisting}[language = {[LaTeX]TeX}] \documentclass{article} \begin{document} Hello \LaTeX{} World! \end{document} \end{lstlisting} 保存并退出. 接下来执行 \begin{lstlisting} pdflatex main \end{lstlisting} 等待系统完成编译过程. 待编译完成后, 我们即可看到在 \texttt{\~{}/Documents/work-latex} 中出现了 \texttt{main.pdf} 文件和其他同名的辅助文件 \texttt{main.aux} 与 \texttt{main.log}. 执行 \begin{lstlisting}[language=bash] evince main.pdf \end{lstlisting} 即可打开 \texttt{pdf} 文件. 对于中文文档, 可以在 \texttt{gedit} 中编写以下最小示例% \footnote{gedit 默认使用 UTF-8 编码}% \begin{lstlisting}[language={[LaTeX]TeX}] \documentclass[UTF8,fontset=fandol]{ctexart} \begin{document} 你好 \LaTeX{} 世界! \end{document} \end{lstlisting} 保存并退出. 接下来执行 \begin{lstlisting}[language=bash] xelatex main \end{lstlisting} 等待系统完成编译过程. \texttt{xelatex} 可以使用系统内安装的字体, 安装字体的方法可参考 \ref{sec:addition:font}~节. 编译命令可添加参数, 这里与 \ref{sec:windows:compile}~节中的情形一致.