<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% !TeX root = ../install-latex-guide-zh-cn.tex

\chapter{æœ‰å…³ Ubuntu å’Œ WSL çš„è¡¥å……}\label{chp:appendix:addition}

\section{æ›´æ¢ Ubuntu 24.04 æº}\label{sec:addition:source}

é‰´äºŽå¤§é™†ç½‘ç»œçŽ°çŠ¶,
å»ºè®®æ›´æ¢ Ubuntu 24.04 æºè‡³å›½å†…,
ä¾‹å¦‚æ›´æ¢è‡³æ¸…åŽå¤§å­¦.
åœ¨ \textsf{Terminal} ä¸­æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = apt]
  sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
\end{lstlisting}
å¤‡ä»½ \texttt{sources.list} æ–‡ä»¶.
æŽ¥ä¸‹æ¥æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = apt]
  sudo gedit /etc/apt/sources.list
\end{lstlisting}
å°†æ–‡ä»¶æ›¿æ¢ä¸ºä»¥ä¸‹å†…å®¹%
\footnote{æœ¬æ®µæ–‡å­—å¯è‡³%
  \href{https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/}{æ¸…åŽå¤§å­¦é•œåƒç½‘ç«™}%
  èŽ·å–}
\begin{lstlisting}[
  morekeywords = {deb, noble, noble-updates, noble-backports, noble-security},
  alsoletter = -]
  # é»˜è®¤æ³¨é‡Šäº†æºç&nbsp;é•œåƒä»¥æé«˜ apt update é€Ÿåº¦, å¦‚æœ‰éœ€è¦å¯è‡ªè¡Œå–æ¶ˆæ³¨é‡Š
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
  # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
  # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
  # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse

  # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
  # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse

  deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
  # deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse

  # é¢„å‘å¸ƒè½¯ä»¶æº, ä¸å»ºè®®å¯ç”¨
  # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
  # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
\end{lstlisting}
ä¿å­˜é€€å‡º.
å†æ‰§è¡Œ
\begin{lstlisting}
  sudo apt update &amp;&amp; sudo apt upgrade
\end{lstlisting}
æ¢æºå¹¶æ›´æ–°.
è‹¥æ›´æ”¹é”™è¯¯,
å¯æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = apt]
  sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
\end{lstlisting}
æ¢å¤æ–‡ä»¶.

\section{å®‰è£…å­—ä½“}\label{sec:addition:font}

æœ‰ç”¨æˆ·æŒ‡å‡º,
Ubuntu ä¸­å®‰è£…å­—ä½“æ¯”è¾ƒéº»çƒ¦.
è¿™é‡Œç»™å‡ºä¸€ä¸ªæ–¹æ³•.

åœ¨å®‰è£…å­—ä½“å‰å…ˆä¿è¯ "fontconfig" å’Œ "xfonts-utils" å·²å®‰è£…
\begin{lstlisting}
  sudo apt install fontconfig xfonts-utils
\end{lstlisting}
èŽ·å–éœ€è¦å®‰è£…çš„å­—ä½“æ–‡ä»¶,
å‡è®¾æ–‡ä»¶ä¿å­˜åœ¨ \path{~/myfonts/},
WSL ç”¨æˆ·ç”šè‡³å¯ä»¥ä¿å­˜åœ¨ä¸»ç³»ç»Ÿè·¯å¾„ä¸­.
ç„¶åŽå°†å…¶é“¾æŽ¥åˆ° \path{/usr/share/fonts/} æ–‡ä»¶å¤¹
\begin{lstlisting}
  sudo ln -s ~/myfonts /usr/share/fonts
\end{lstlisting}
æœ€åŽå»ºç«‹å­—ä½“ç¼“å­˜
\begin{lstlisting}
  mkfontscale
  mkfontdir
  fc-cache -fv
\end{lstlisting}
è¿™æ—¶æ‰§è¡Œ
\begin{lstlisting}
  fc-list
\end{lstlisting}
å³å¯è§åˆ°ç›®å‰å¯ç”¨çš„å­—ä½“.
è‹¥è¦åˆ&nbsp;é™¤åˆšåˆšå®‰è£…çš„å­—ä½“,
åªéœ€è¦ç›´æŽ¥åˆ&nbsp;é™¤
\begin{lstlisting}
  sudo rm /usr/share/fonts/myfonts
\end{lstlisting}

å®žé™…ä¸Šæœ‰éƒ¨åˆ†å­—ä½“å¯ç›´æŽ¥ä½¿ç”¨æºè¿›è¡Œå®‰è£…,
å¦‚å®‰è£…å­—ä½“ Noto CJK
\begin{lstlisting}
  sudo apt install fonts-noto-cjk
  sudo apt install fonts-noto-cjk-extra
\end{lstlisting}
å®‰è£… Windows ç³»ç»Ÿä¸­å¸¸è§çš„å­—ä½“ Andale Mono,
Arial Black,
Arial (Bold, Italic, Bold Italic),
Comic Sans MS (Bold),
Courier New (Bold, Italic, Bold Italic),
Georgia (Bold, Italic, Bold Italic),
Impact,
Times New Roman (Bold, Italic, Bold Italic),
Trebuchet (Bold, Italic, Bold Italic),
Verdana (Bold, Italic, Bold Italic),
Webdings
\begin{lstlisting}
  sudo apt install ttf-mscorefonts-installer
\end{lstlisting}
å®‰è£…å­—ä½“æ–‡æ³‰é©¿æ­£é»‘,
æ–‡æ³‰é©¿å¾®ç±³é»‘,
æ–‡æ³‰é©¿ç­‰å®½å¾®ç±³é»‘,
æ–‡æ³‰é©¿ç‚¹é˜µå®‹ä½“,
æ–‡æ³‰é©¿ç‚¹é˜µæ¥·ä½“
\begin{lstlisting}
  sudo apt install ttf-wqy-zenhei
\end{lstlisting}

\section{åå‘ä»£ç† PPA}\label{sec:addition:proxy}

è¿™é‡Œä»‹ç»ä¸­ç§‘å¤§çš„\href{https://mirrors.ustc.edu.cn/}{åå‘ä»£ç†},
å°†
\begin{lstlisting}[deletekeywords = apt]
  /etc/apt/sources.list.d/
\end{lstlisting}
ä¸­æ–‡ä»¶çš„å†…å®¹
\begin{lstlisting}
  http(s)://ppa.launchpad.net
\end{lstlisting}
æ”¹ä¸º
\begin{lstlisting}
  https://launchpad.proxy.ustclug.org
\end{lstlisting}
è€ŒåŽå†
\begin{lstlisting}
  sudo apt update
\end{lstlisting}
å³å®Œæˆæ¢æº.
æœ‰æ—¶åœ°å€å¤ªå¤šè€Œé€ä¸ªæ¢å¤ªéº»çƒ¦,
å¯ä»¥ç›´æŽ¥ä½¿ç”¨å¦‚ä¸‹å‘½ä»¤ç›´æŽ¥æ›¿æ¢\footnote{å‚è§ \url{https://mogeko.me/posts/zh-cn/035/}}
\begin{lstlisting}[deletekeywords = apt]
  sudo find /etc/apt/sources.list.d/ -type f -name "*.list" -exec  sed  -i.bak -r  's#deb(-src)?\s*http(s)?://ppa.launchpad.net#deb\1 https\2://launchpad.proxy.ustclug.org#ig' {} \;
\end{lstlisting}

\section{ç”¨ VS Code ä½œä¸º WSL ä¸­çš„ç¼–è¾‘å™¨}\label{sec:addition:wsl-editor}

å¾®è½¯æœ€è¿‘é¢‘ç¹æŽ¨è WSL ä½œä¸ºå¼€å‘å·¥å…·,
è¯¦æƒ…é˜…è¯»%
\href{https://learn.microsoft.com/zh-cn/windows/wsl/tutorials/wsl-vscode}{å¾®è½¯æ–‡æ¡£}.
æœ¬æ‰‹å†Œåœ¨æ­¤åŸºç¡€ä¸Š,
å€ŸåŠ© \href{https://code.visualstudio.com/download}{VS Code} çš„ \href{https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack}{Remote Development}
æ’ä»¶å®žçŽ°è‹¥å¹²åŠŸèƒ½.
è‹¥éžç‰¹åˆ«æŒ‡æ˜Ž,
ä»¥ä¸‹æ“ä½œå‡åœ¨ WSL ä¸­ç”¨ \textsf{bash} æ‰§è¡Œ.

VS Code çš„æ’ä»¶æƒé™æœ‰é™,
å½“æ›´æ”¹ \texttt{sources.list} æ—¶,
å…ˆåœ¨ \textsf{bash} ä¸­å°† \texttt{sources.list} å¤‡ä»½
\begin{lstlisting}[deletekeywords = apt]
  sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
\end{lstlisting}
å†ç”¨ VS Code æ‰“å¼€æ–‡æ¡£
\begin{lstlisting}[deletekeywords = apt, morekeywords = code]
  code /etc/apt/sources.list
\end{lstlisting}
å¹¶å¯¹å…¶ä¸­å†…å®¹è¿›è¡Œæ›´æ”¹,
å¹¶ä¸”å¦å­˜ä¸º
\begin{lstlisting}
  ~/sources.list.sav
\end{lstlisting}
æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = apt]
  sudo cp ~/sources.list.sav /etc/apt/sources.list
\end{lstlisting}
æ›¿æ¢æ–‡æ¡£.
è‹¥å‘çŽ°æ–‡æ¡£æœ‰é”™è¯¯,
æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = apt]
  sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
\end{lstlisting}
æ¢å¤æ–‡æ¡£.

æ›´æ”¹ \texttt{.bashrc} ç›¸å¯¹ç®€å•,
å°† \texttt{.bashrc} å¤‡ä»½
\begin{lstlisting}
  cp ~/.bashrc ~/.bashrc.bak
\end{lstlisting}
ç”¨ VS Code æ‰“å¼€æ–‡æ¡£
\begin{lstlisting}[morekeywords = code]
  code ~/.bashrc
\end{lstlisting}
å¹¶å¯¹å…¶ä¸­å†…å®¹è¿›è¡Œæ›´æ”¹å¹¶ä¿å­˜.
è‹¥æ›´æ”¹é”™è¯¯,
å¯ä»¥æ‰§è¡Œ
\begin{lstlisting}
  cp ~/.bashrc.bak ~/.bashrc
\end{lstlisting}
æ¢å¤æ–‡æ¡£.

åˆ©ç”¨
\href{https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop}{\LaTeX\ Workshop}
æ’ä»¶å¯ä»¥å°† VS Code ä½œä¸º \LaTeX\ ç¼–è¾‘å™¨,
éš¾ç‚¹åœ¨äºŽå¦‚ä½•è®¾ç½®.
è¿™é‡Œè¿˜æ˜¯å»ºè®®ç”¨æˆ·é˜…è¯»æ’ä»¶
\href{https://github.com/James-Yu/LaTeX-Workshop/wiki}{Wiki}
äº†è§£æ›´å¤šå†…å®¹.
ä»¥ä¸‹ VS Code è®¾ç½®çš„ \texttt{json} æ–‡ä»¶å†…å®¹ä¸ºä¸ªäººè‡ªç”¨çš„ \LaTeX\ Workshop è®¾ç½®,
ä»…ä¾›å‚è€ƒ,
å…¶ä¸­æ³¨é‡Šçš„éƒ¨åˆ†æ˜¯è°ƒç”¨å¤–éƒ¨ SumatraPDF é˜…è¯»å™¨çš„è®¾ç½®,
ç”¨æˆ·å¯é˜…è¯»
\href{https://github.com/OsbertWang/latex-editor-sumatrapdf}{\textsf{latex-editor-sumatrapdf}}
æ¥äº†è§£æ›´å¤šå†…å®¹.
\begin{lstlisting}[language = json]
  "latex-workshop.latex.tools": [
    {
      "name": "latexmkpdf",
      "command": "latexmk",
      "args":
        [
          "-synctex=1", "%DOCFILE%",
          "-halt-on-error", "-file-line-error",
          "-pdf", "-interaction=nonstopmode"
        ]
    },
    {
      "name": "latexmkxe",
      "command": "latexmk",
      "args":
        [
          "-synctex=1", "%DOCFILE%",
          "-halt-on-error", "-file-line-error", 
          "-xelatex", "-interaction=nonstopmode",
        ]
    },
  ],
  "latex-workshop.latex.recipes": [
    {
      "name": "latexmkpdf",
      "tools": [ "latexmkpdf" ]
    },
    {
      "name": "latexmkxe",
      "tools": [ "latexmkxe" ]
    }
  ],
  "latex-workshop.latex.autoBuild.run": "never",
  "latex-workshop.view.pdf.viewer": "tab"
  // "latex-workshop.view.pdf.viewer": "external",
  // "latex-workshop.view.pdf.ref.viewer": "external",
  // "latex-workshop.view.pdf.external.viewer.command": "&lt;SumatraPDFROOT&gt;/SumatraPDF.exe",
  // "latex-workshop.view.pdf.external.viewer.args": [
  //   "-inverse-search", "%PDF%",
  //   "\"&lt;VSCodeROOT&gt;/bin/code.cmd\" -r -g \"%f:%l\"",
  // ],
  // "latex-workshop.view.pdf.external.synctex.command":"&lt;SumatraPDFROOT&gt;/SumatraPDF.exe",
  // "latex-workshop.view.pdf.external.synctex.args":[
  //   "-forward-search", "%TEX%", "%LINE%", "%PDF%"
  // ],
\end{lstlisting}

å®žé™…ä½¿ç”¨æ—¶,
ç”¨æˆ·éœ€è¦ç»“åˆè‡ªèº«å®‰è£…æƒ…å†µæ›´æ¢ \path{&lt;SumatraPDFROOT&gt;} å’Œ \path{&lt;VSCodeROOT&gt;},
å³ SumatraPDF å’Œ VS Code å„è‡ªçš„å®‰è£…è·¯å¾„.

å¦å¤–éœ€è¦å£°æ˜Žçš„æ˜¯,
\LaTeX\ Workshop æ’ä»¶å¹¶ä¸å±€é™åœ¨ WSL å½“ä¸­,
å®ƒçš„é…ç½®æ˜¯å¯ä»¥é€šç”¨çš„.

\section{è¿ç§» WSL çš„å®‰è£…ä½ç½®}

è€ƒè™‘åˆ°ä¸€éƒ¨åˆ†ç”¨æˆ·çš„ç³»ç»Ÿç›˜ç©ºé—´æœ‰é™,
ä¸”æ&nbsp;¹æ®%
\href{https://learn.microsoft.com/zh-cn/windows/wsl/troubleshooting?source=recommendations#installation-issues}{å¾®è½¯å®˜æ–¹æ–‡æ¡£},
WSL åªèƒ½å®‰è£…åœ¨ç³»ç»Ÿç›˜,
å›&nbsp;æ­¤å¯ä»¥è€ƒè™‘è¿ç§» WSL çš„å®‰è£…ä½ç½®åˆ°å…¶ä»–ç›˜.
æœ¬éƒ¨åˆ†å†…å®¹æºè‡ª
\href{https://superuser.com/questions/1701175/installing-ubuntu-on-mnt-d-with-wsl}{\textsf{Stack\textbf{Exchange}}}.
æ–¹æ³•ç‰µæ‰¯åˆ°ä¸»ç³»ç»Ÿå’Œå­ç³»ç»Ÿçš„æ“ä½œ.

ç¬¬ä¸€æ­¥,
å»ºç«‹æ–°çš„ä½ç½®.
å‡è®¾æ–°ä½ç½®åœ¨ \path{X:\} ç›˜.
åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl -l
\end{lstlisting}
å¯ä»¥æŸ¥åˆ°å½“å‰å·²ç»å®‰è£…çš„ WSL åˆ†å‘,
ä¾‹å¦‚
\begin{lstlisting}
  é€‚ç”¨äºŽ Linux çš„ Windows å­ç³»ç»Ÿåˆ†å‘:
  Ubuntu (é»˜è®¤)
\end{lstlisting}
åœ¨ \textsf{bash} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  lsb_release -a
\end{lstlisting}
æŸ¥åˆ°å®žé™… WSL å†… Ubuntu çš„ç‰ˆæœ¬,
ä¾‹å¦‚
\begin{lstlisting}[language = {}]
  No LSB modules are available.
  Distributor ID: Ubuntu
  Description:    Ubuntu 24.04.2 LTS
  Release:        24.04
  Codename:       noble
\end{lstlisting}
ç„¶åŽåœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  mkdir X:\WSL\instances\ubuntu2404
  mkdir X:\WSL\images
  cd X:\WSL\images
\end{lstlisting}
%\begin{lstlisting}
%  New-Item -ItemType Directory -Path "X:\WSL\instances\Ubuntu2204" -Force
%  Set-Location (New-Item -ItemType Directory -Path "X:\WSL\images" -Force)
%\end{lstlisting}
åˆ›å»ºæ–°çš„ä½ç½®.
è¿™é‡Œèµ·å \texttt{ubuntu2404} æ˜¯å›&nbsp;ä¸º Ubuntu å®žé™…ç‰ˆæœ¬ä¸º 24.04,
ä¹Ÿå¯ä»¥èµ·å…¶ä»–åå­—.

ç¬¬äºŒæ­¥,
å¯¼å‡ºåŽŸ WSL åˆ†å‘å¹¶å¯¼å…¥æ–°ä½ç½®.
åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl --export Ubuntu ubuntu.tar
  wsl --import ubuntu2404 X:\WSL\instances\ubuntu2404 ubuntu.tar --version 2
\end{lstlisting}
ç¬¬ä¸€è¡Œçš„ \texttt{Ubuntu} æŒ‡çš„æ˜¯ç³»ç»Ÿé»˜è®¤çš„ WSL åˆ†å‘,
è¿™æ¡å‘½ä»¤å°†åŽŸæœ¬çš„åˆ†å‘å¯¼å‡ºä¸ºä¸€ä¸ªåŽ‹ç¼©åŒ….
ç¬¬äºŒè¡Œçš„ \texttt{ubuntu2404} æ˜¯æœªæ¥æŒ‡å®šçš„ WSL åˆ†å‘,
ä¹Ÿå°±æ˜¯å°†å‰é¢å¯¼å‡ºçš„åŽ‹ç¼©åŒ…å¯¼å…¥æˆæ–°çš„ WSL åˆ†å‘.

ç¬¬ä¸‰æ­¥,
å¯åŠ¨æ–°çš„åˆ†å‘å¹¶ä¸”è®¾ç½®ä¸ºé»˜è®¤.
åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl ~ -d ubuntu2404
\end{lstlisting}
è¿›å…¥ \texttt{ubuntu2404} åˆ†å‘çš„ WSL ç³»ç»Ÿ,
åœ¨å½“å‰ \textsf{bash} ä¸­æ‰§è¡Œ
\begin{lstlisting}[deletekeywords = wsl]
  sudo -e /etc/wsl.conf
\end{lstlisting}
è¾“å…¥ä»¥ä¸‹å†…å®¹
\begin{lstlisting}
  [user]
  default=&lt;your_username&gt;
\end{lstlisting}
"&lt;your_username&gt;" æ˜¯ç”¨æˆ·è‡ªå®šä¹‰çš„ WSL çš„ç”¨æˆ·å,
ä¸ªäººç”¨äº†åŽŸæœ¬ \texttt{Ubuntu} åˆ†å‘å†…çš„ç”¨æˆ·å.
ç„¶åŽä¾æ¬¡ \keys{\ctrl + X}, \keys{Y}, \keys{\enter} ä¿å­˜é€€å‡º.
é€€å‡º \textsf{bash},
åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl --terminate ubuntu2404
  wsl ~ -d ubuntu2404
\end{lstlisting}
è¿™æ—¶å¦‚æžœä¸€åˆ‡æ­£å¸¸,
å°±å¯ä»¥å°† \texttt{ubuntu2404} è®¾ç½®ä¸ºé»˜è®¤ WSL åˆ†å‘,
å³åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl --set-default ubuntu2404
\end{lstlisting}
è¿™æ—¶åœ¨ \textsf{bash} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  echo $WSL_DISTRO_NAME
\end{lstlisting}
è¿”å›žç»“æžœ
\begin{lstlisting}
  ubuntu2404
\end{lstlisting}
å°±è¡¨æ˜Žä¸€åˆ‡æ­£å¸¸.

ç¬¬å››æ­¥,
åˆ&nbsp;é™¤æ—§åˆ†å‘.
åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl --unregister Ubuntu
\end{lstlisting}
å°±å°†æ—§åˆ†å‘ \texttt{Ubuntu} åˆ&nbsp;é™¤äº†.
è¿™æ—¶åœ¨ \textsf{cmd} ä¸­æ‰§è¡Œ
\begin{lstlisting}
  wsl -l
\end{lstlisting}
å°†çœ‹åˆ°
\begin{lstlisting}
  é€‚ç”¨äºŽ Linux çš„ Windows å­ç³»ç»Ÿåˆ†å‘:
  ubuntu2404 (é»˜è®¤)
\end{lstlisting}

å®žé™…ä¸Š,
å°†æ•´ä¸ª WSL çš„å®‰è£…ä½ç½®è¿ç§»è¿˜æœ‰ä¸€ä¸ªå¥½å¤„.
æ&nbsp;¹æ®%
\href{https://learn.microsoft.com/zh-cn/windows/wsl/filesystems#file-storage-and-performance-across-file-systems}{å¾®è½¯å®˜æ–¹æ–‡æ¡£},
å°†é¡¹ç›®æ–‡ä»¶ç›´æŽ¥å­˜å‚¨åœ¨ WSL çš„é©±åŠ¨å™¨ä¸Š,
æ€§èƒ½é€Ÿåº¦ä¼šæé«˜.
</pre></body></html>