mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
14 lines
49 KiB
JavaScript
14 lines
49 KiB
JavaScript
import{_ as i,c as a,a2 as e,o as t}from"./chunks/framework.C9NVOr0y.js";const c=JSON.parse('{"title":"快速入门","description":"","frontmatter":{},"headers":[],"relativePath":"zh-hans/guide/getting-started.md","filePath":"zh-hans/guide/getting-started.md","lastUpdated":1724080713000}'),l={name:"zh-hans/guide/getting-started.md"};function h(n,s,p,d,o,k){return t(),a("div",null,s[0]||(s[0]=[e(`<h1 id="快速入门" tabindex="-1">快速入门 <a class="header-anchor" href="#快速入门" aria-label="Permalink to "快速入门""></a></h1><p><code>asdf</code> 安装过程包括:</p><ol><li>安装依赖</li><li>下载 <code>asdf</code> 核心</li><li>安装 <code>asdf</code></li><li>为每一个你想要管理的工具/运行环境安装插件</li><li>安装工具/运行环境的一个版本</li><li>通过 <code>.tool-versions</code> 配置文件设置全局和项目版本</li></ol><h2 id="_1-安装依赖" tabindex="-1">1. 安装依赖 <a class="header-anchor" href="#_1-安装依赖" aria-label="Permalink to "1. 安装依赖""></a></h2><p>asdf primarily requires <code>git</code> & <code>curl</code>. Here is a <em>non-exhaustive</em> list of commands to run for <em>your</em> package manager (some might automatically install these tools in later steps).</p><table tabindex="0"><thead><tr><th>OS</th><th>Package Manager</th><th>Command</th></tr></thead><tbody><tr><td>linux</td><td>Aptitude</td><td><code>apt install curl git</code></td></tr><tr><td>linux</td><td>DNF</td><td><code>dnf install curl git</code></td></tr><tr><td>linux</td><td>Pacman</td><td><code>pacman -S curl git</code></td></tr><tr><td>linux</td><td>Zypper</td><td><code>zypper install curl git</code></td></tr><tr><td>macOS</td><td>Homebrew</td><td><code>brew install coreutils curl git</code></td></tr><tr><td>macOS</td><td>Spack</td><td><code>spack install coreutils curl git</code></td></tr></tbody></table><div class="tip custom-block"><p class="custom-block-title">Note</p><p><code>sudo</code> may be required depending on your system configuration.</p></div><h2 id="_2-下载-asdf" tabindex="-1">2. 下载 asdf <a class="header-anchor" href="#_2-下载-asdf" aria-label="Permalink to "2. 下载 asdf""></a></h2><h3 id="official-download" tabindex="-1">Official Download <a class="header-anchor" href="#official-download" aria-label="Permalink to "Official Download""></a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/asdf-vm/asdf.git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.asdf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --branch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> v0.14.1</span></span></code></pre></div><h3 id="community-supported-download-methods" tabindex="-1">Community Supported Download Methods <a class="header-anchor" href="#community-supported-download-methods" aria-label="Permalink to "Community Supported Download Methods""></a></h3><p>We highly recommend using the official <code>git</code> method.</p><table tabindex="0"><thead><tr><th>Method</th><th>Command</th></tr></thead><tbody><tr><td>Homebrew</td><td><code>brew install asdf</code></td></tr><tr><td>Pacman</td><td><code>git clone https://aur.archlinux.org/asdf-vm.git && cd asdf-vm && makepkg -si</code> or use your preferred <a href="https://wiki.archlinux.org/index.php/AUR_helpers" target="_blank" rel="noreferrer">AUR helper</a></td></tr></tbody></table><h2 id="_3-安装-asdf" tabindex="-1">3. 安装 asdf <a class="header-anchor" href="#_3-安装-asdf" aria-label="Permalink to "3. 安装 asdf""></a></h2><p>根据 Shell 脚本、操作系统和安装方法的组合不同,相应的配置也会不同。展开以下与你的系统最匹配的选项:</p><details class="details custom-block"><summary>Bash & Git</summary><p>在 <code>~/.bashrc</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/asdf.sh"</span></span></code></pre></div><p>补全功能必须在 <code>.bashrc</code> 文件中加入以下内容来配置完成:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/completions/asdf.bash"</span></span></code></pre></div></details><details class="details custom-block"><summary>Bash & Git (macOS)</summary><p>如果你正在使用 <strong>macOS Catalina 或者更新的版本</strong>, 默认的 shell 已经被修改为 <strong>ZSH</strong>。除非修改回 Bash, 否则请遵循 ZSH 的说明。</p><p>在 <code>~/.bash_profile</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/asdf.sh"</span></span></code></pre></div><p>补全功能必须在 <code>.bash_profile</code> 文件中使用以下内容手动配置完成:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/completions/asdf.bash"</span></span></code></pre></div></details><details class="details custom-block"><summary>Bash & Homebrew</summary><p>使用以下命令将 <code>asdf.sh</code> 加入到 <code>~/.bashrc</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.sh</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.bashrc</span></span></code></pre></div><p>补全功能将需要 <a href="https://docs.brew.sh/Shell-Completion#configuring-completions-in-bash" target="_blank" rel="noreferrer">按照 Homebrew 的说明完成配置</a> 或者执行以下命令:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/etc/bash_completion.d/asdf.bash</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.bashrc</span></span></code></pre></div></details><details class="details custom-block"><summary>Bash & Homebrew (macOS)</summary><p>如果你正在使用 <strong>macOS Catalina 或者更新的版本</strong>, 默认的 shell 已经被修改为 <strong>ZSH</strong>。除非修改回 Bash, 否则请遵循 ZSH 的说明。</p><p>使用以下命令将 <code>asdf.sh</code> 加入到 <code>~/.bash_profile</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.sh</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.bash_profile</span></span></code></pre></div><p>补全功能将需要 <a href="https://docs.brew.sh/Shell-Completion#configuring-completions-in-bash" target="_blank" rel="noreferrer">按照 Homebrew 的说明完成配置</a> 或者执行以下命令:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/etc/bash_completion.d/asdf.bash</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.bash_profile</span></span></code></pre></div></details><details class="details custom-block"><summary>Bash & Pacman</summary><p>在 <code>~/.bashrc</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.sh</span></span></code></pre></div><p>为了让补全功能正常工作需要安装 <a href="https://wiki.archlinux.org/title/bash#Common_programs_and_options" target="_blank" rel="noreferrer"><code>bash-completion</code></a> 。</p></details><details class="details custom-block"><summary>Fish & Git</summary><p>在 <code>~/.config/fish/config.fish</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.asdf/asdf.fish</span></span></code></pre></div><p>补全功能必须按照以下命令手动配置完成:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/fish/completions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">and</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.asdf/completions/asdf.fish</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/fish/completions</span></span></code></pre></div></details><details class="details custom-block"><summary>Fish & Homebrew</summary><p>使用以下命令将 <code>asdf.fish</code> 加入到 <code>~/.config/fish/config.fish</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\nsource "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"/libexec/asdf.fish"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/fish/config.fish</span></span></code></pre></div><p>Fish shell 的补全功能可以交给 <a href="https://docs.brew.sh/Shell-Completion#configuring-completions-in-fish" target="_blank" rel="noreferrer">Homebrew 处理</a>. 很友好!</p></details><details class="details custom-block"><summary>Fish & Pacman</summary><p>在 <code>~/.config/fish/config.fish</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.fish</span></span></code></pre></div><p>补全功能将会在安装过程中由 AUR 包管理器自动配置完成。</p></details><details class="details custom-block"><summary>Elvish & Git</summary><p>使用以下命令将 <code>asdf.elv</code> 加入到 <code>~/.config/elvish/rc.elv</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.asdf/asdf.elv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/lib/asdf.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'use asdf _asdf; var asdf~ = $_asdf:asdf~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'set edit:completion:arg-completer[asdf] = $_asdf:arg-completer~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>Elvish & Homebrew</summary><p>使用以下命令将 <code>asdf.elv</code> 加入到 <code>~/.config/elvish/rc.elv</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (brew </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">--prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)/libexec/asdf.elv </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/.config/elvish/lib/asdf.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'use asdf _asdf; var asdf~ = $_asdf:asdf~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'set edit:completion:arg-completer[asdf] = $_asdf:arg-completer~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>Elvish & Pacman</summary><p>使用以下命令将 <code>asdf.elv</code> 加入到 <code>~/.config/elvish/rc.elv</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.elv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/lib/asdf.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'use asdf _asdf; var asdf~ = $_asdf:asdf~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n"'set edit:completion:arg-completer[asdf] = $_asdf:arg-completer~'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/elvish/rc.elv</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>ZSH & Git</summary><p>在 <code>~/.zshrc</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/asdf.sh"</span></span></code></pre></div><p><strong>或者</strong> 使用 ZSH 框架插件,比如 <a href="https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/asdf" target="_blank" rel="noreferrer">asdf for oh-my-zsh</a> 将会使脚本生效并安装补全功能。</p><p>补全功能会被 ZSH 框架 <code>asdf</code> 插件或者通过在 <code>.zshrc</code> 文件中加入以下内容自动配置:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># append completions to fpath</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">fpath</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(\${ASDF_DIR}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/completions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $fpath)</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># initialise completions with ZSH's compinit</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">autoload</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Uz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> compinit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">compinit</span></span></code></pre></div><ul><li>如果你正在使用自定义的 <code>compinit</code> 配置,请确保 <code>compinit</code> 在 <code>asdf.sh</code> 生效位置的下方</li><li>如果你正在使用自定义的 <code>compinit</code> 配置和 ZSH 框架,请确保 <code>compinit</code> 在框架生效位置的下方</li></ul><p><strong>警告</strong></p><p>如果你正在使用 ZSH 框架,有关的 <code>asdf</code> 插件或许需要更新才能通过 <code>fpath</code> 正确地使用最新的 ZSH 补全功能。Oh-My-ZSH asdf 插件还在更新中,请查看 <a href="https://github.com/ohmyzsh/ohmyzsh/pull/8837" target="_blank" rel="noreferrer">ohmyzsh/ohmyzsh#8837</a> 了解更多。</p></details><details class="details custom-block"><summary>ZSH & Homebrew</summary><p>使用以下命令将 <code>asdf.sh</code> 加入到 <code>~/.zshrc</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.sh"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> \${ZDOTDIR</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">~}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.zshrc</span></span></code></pre></div><p><strong>或者</strong> 使用 ZSH 框架插件,比如 <a href="https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/asdf" target="_blank" rel="noreferrer">asdf for oh-my-zsh</a> 将会使脚本生效并安装补全功能。</p><p>补全功能可以被 ZSH 框架 <code>asdf</code> 或者 <a href="https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh" target="_blank" rel="noreferrer">按照 Homebrew 的指引</a> 完成配置。如果你正在使用 ZSH 框架,有关的 <code>asdf</code> 插件或许需要更新才能通过 <code>fpath</code> 正确地使用最新的 ZSH 补全功能。Oh-My-ZSH asdf 插件还在更新中,请查看 <a href="https://github.com/ohmyzsh/ohmyzsh/pull/8837" target="_blank" rel="noreferrer">ohmyzsh/ohmyzsh#8837</a> 了解更多。</p></details><details class="details custom-block"><summary>ZSH & Pacman</summary><p>在 <code>~/.zshrc</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.sh</span></span></code></pre></div><p>补全功能会被放在一个对 ZSH 很友好的位置,但是 <a href="https://wiki.archlinux.org/index.php/zsh#Command_completion" target="_blank" rel="noreferrer">ZSH 必须使用自动补全完成配置</a>。</p></details><details class="details custom-block"><summary>PowerShell Core & Git</summary><p>在 <code>~/.config/powershell/profile.ps1</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/asdf.ps1"</span></span></code></pre></div></details><details class="details custom-block"><summary>PowerShell Core & Homebrew</summary><p>使用以下命令将 <code>asdf.ps1</code> 加入到 <code>~/.config/powershell/profile.ps1</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.ps1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.config/powershell/profile.ps1</span></span></code></pre></div></details><details class="details custom-block"><summary>PowerShell Core & Pacman</summary><p>在 <code>~/.config/powershell/profile.ps1</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.ps1</span></span></code></pre></div></details><details class="details custom-block"><summary>Nushell & Git</summary><p>使用以下命令将 <code>asdf.nu</code> 加入到 <code>~/.config/nushell/config.nu</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">"\\n</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$env</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">.ASDF_DIR = (</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$env</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">.HOME | path join '.asdf')\\n source "</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ($env.HOME </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> join</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '.asdf/asdf.nu'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> save</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --append</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $nu</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">.config-path</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>Nushell & Homebrew</summary><p>使用以下命令将 <code>asdf.nu</code> 加入到 <code>~/.config/nushell/config.nu</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">"\\n</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$env</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">.ASDF_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\\n source "</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (brew </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">--prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> str</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> trim</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> into</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> string</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> path</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> join</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'libexec/asdf.nu'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> save</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --append</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $nu</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">.config-path</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>Nushell & Pacman</summary><p>使用以下命令将 <code>asdf.nu</code> 加入到 <code>~/.config/nushell/config.nu</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">"\\n</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$env</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">.ASDF_DIR = '/opt/asdf-vm/'\\n source /opt/asdf-vm/asdf.nu"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> save</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --append</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $nu</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">.config-path</span></span></code></pre></div><p>补全功能将会自动配置。</p></details><details class="details custom-block"><summary>POSIX Shell & Git</summary><p>在 <code>~/.profile</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ASDF_DIR</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf"</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$HOME</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/.asdf/asdf.sh"</span></span></code></pre></div></details><details class="details custom-block"><summary>POSIX Shell & Homebrew</summary><p>使用以下命令将 <code>asdf.sh</code> 加入到 <code>~/.profile</code> 文件中:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\nexport ASDF_DIR=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.sh</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.profile</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "\\n. </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> asdf)/libexec/asdf.sh</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\"</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.profile</span></span></code></pre></div></details><details class="details custom-block"><summary>POSIX Shell & Pacman</summary><p>在 <code>~/.profile</code> 文件中加入以下内容:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ASDF_DIR</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"/opt/asdf-vm"</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/asdf-vm/asdf.sh</span></span></code></pre></div></details><p><code>asdf</code> 脚本需要在设置好的 <code>$PATH</code> <strong>之后</strong>和已经生效的框架(比如 oh-my-zsh 等等)<strong>之后</strong>的位置生效。</p><p>通常打开一个新的终端标签页来重启你的 shell 让 <code>PATH</code> 更改即时生效。</p><h2 id="核心安装完成" tabindex="-1">核心安装完成! <a class="header-anchor" href="#核心安装完成" aria-label="Permalink to "核心安装完成!""></a></h2><p>这样就完成了 <code>asdf</code> 核心的安装 🎉</p><p><code>asdf</code> 仅在你安装<strong>插件</strong>、<strong>工具</strong>和管理它们的<strong>版本</strong>时才开始真正发挥作用。请继续阅读下面的指南来了解这些是如何做到的。</p><h2 id="_4-安装插件" tabindex="-1">4. 安装插件 <a class="header-anchor" href="#_4-安装插件" aria-label="Permalink to "4. 安装插件""></a></h2><p>出于演示目的,我们将通过 <a href="https://github.com/asdf-vm/asdf-nodejs/" target="_blank" rel="noreferrer"><code>asdf-nodejs</code></a> 插件来安装和设置 <a href="https://nodejs.org/" target="_blank" rel="noreferrer">Node.js</a>。</p><h3 id="插件依赖" tabindex="-1">插件依赖 <a class="header-anchor" href="#插件依赖" aria-label="Permalink to "插件依赖""></a></h3><p>每个插件都有依赖,所以我们需要确认应该列举了这些依赖的插件源码。对于 <code>asdf-nodejs</code> 来说,它们是:</p><table tabindex="0"><thead><tr><th>操作系统</th><th>安装依赖</th></tr></thead><tbody><tr><td>Linux (Debian)</td><td><code>apt-get install dirmngr gpg curl gawk</code></td></tr><tr><td>macOS</td><td><code>brew install gpg gawk</code></td></tr></tbody></table><p>我们应该提前安装这些依赖,因为有些插件有 post-install 钩子。</p><h3 id="安装插件" tabindex="-1">安装插件 <a class="header-anchor" href="#安装插件" aria-label="Permalink to "安装插件""></a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">asdf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> plugin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> add</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nodejs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/asdf-vm/asdf-nodejs.git</span></span></code></pre></div><h2 id="_5-安装指定版本" tabindex="-1">5. 安装指定版本 <a class="header-anchor" href="#_5-安装指定版本" aria-label="Permalink to "5. 安装指定版本""></a></h2><p>现在我们已经有了 Node.js 插件,所以我们可以开始安装某个版本了。</p><p>我们通过 <code>asdf list all nodejs</code> 可以看到所有可用的版本或者通过 <code>asdf list all nodejs 14</code> 查看版本子集。</p><p>我们将只安装最新可用的 <code>latest</code> 版本:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">asdf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nodejs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> latest</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">注意</p><p><code>asdf</code> 强制使用准确的版本。<code>latest</code> 是一个通过 <code>asdf</code> 来解析到执行时刻的实际版本号的辅助工具。</p></div><h2 id="_6-设置默认版本" tabindex="-1">6. 设置默认版本 <a class="header-anchor" href="#_6-设置默认版本" aria-label="Permalink to "6. 设置默认版本""></a></h2><p><code>asdf</code> 在从当前工作目录一直到 <code>$HOME</code> 目录的所有 <code>.tool-versions</code> 文件中进行工具的版本查找。查找在执行 <code>asdf</code> 管理的工具时实时发生。</p><div class="warning custom-block"><p class="custom-block-title">警告</p><p>如果没有为工具找到指定的版本,则会出现<strong>错误</strong>。<code>asdf current</code> 将显示当前目录中的工具和版本解析结果,或者不存在,以便你可以观察哪些工具将无法执行。</p></div><h3 id="全局" tabindex="-1">全局 <a class="header-anchor" href="#全局" aria-label="Permalink to "全局""></a></h3><p>全局默认配置在 <code>$HOME/.tool-versions</code> 文件中进行管理。使用以下命令可以设置一个全局版本:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">asdf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> global</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nodejs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> latest</span></span></code></pre></div><p><code>$HOME/.tool-versions</code> 文件内容将会如下所示:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>nodejs 16.5.0</span></span></code></pre></div><p>某些操作系统已经有一些由系统而非 <code>asdf</code> 安装和管理的工具了,<code>python</code> 就是一个常见的例子。你需要告诉 <code>asdf</code> 将管理权还给系统。<a href="/zh-hans/manage/versions.html">版本参考部分</a> 将会引导你。</p><h3 id="本地" tabindex="-1">本地 <a class="header-anchor" href="#本地" aria-label="Permalink to "本地""></a></h3><p>本地版本被定义在 <code>$PWD/.tool-versions</code> 文件中(当前工作目录)。通常,这将会是一个项目的 Git 存储库。当在你想要的目录执行:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">asdf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> local</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nodejs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> latest</span></span></code></pre></div><p><code>$PWD/.tool-versions</code> 文件内容将会如下所示:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>nodejs 16.5.0</span></span></code></pre></div><h3 id="使用现有工具版本文件" tabindex="-1">使用现有工具版本文件 <a class="header-anchor" href="#使用现有工具版本文件" aria-label="Permalink to "使用现有工具版本文件""></a></h3><p><code>asdf</code> 支持从其他版本管理器的现有版本文件中迁移过来,比如 <code>rbenv</code> 的 <code>.ruby-version</code> 文件。这在每个插件中都原生支持。</p><p><a href="https://github.com/asdf-vm/asdf-nodejs/" target="_blank" rel="noreferrer"><code>asdf-nodejs</code></a> 支持从 <code>.nvmrc</code> 和 <code>.node-version</code> 文件进行迁移。为了启用此功能,请在 <code>asdf</code> 配置文件 <code>$HOME/.asdfrc</code> 中加入以下内容:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>legacy_version_file = yes</span></span></code></pre></div><p>请查看 <a href="/zh-hans/manage/configuration.html">配置</a> 参考页面可以了解更多配置选项。</p><h2 id="完成指南" tabindex="-1">完成指南! <a class="header-anchor" href="#完成指南" aria-label="Permalink to "完成指南!""></a></h2><p>恭喜你完成了 <code>asdf</code> 的快速上手 🎉 你现在可以管理你的项目的 <code>nodejs</code> 版本了。对于项目中的其他工具类型可以执行类似步骤即可!</p><p><code>asdf</code> 还有更多命令需要熟悉,你可以通过运行 <code>asdf --help</code> 或者 <code>asdf</code> 来查看它们。命令主要分为三类:</p><ul><li><a href="/zh-hans/manage/core.html"><code>asdf</code> 核心</a></li><li><a href="/zh-hans/manage/plugins.html">插件</a></li><li><a href="/zh-hans/manage/versions.html">(工具的)版本</a></li></ul>`,80)]))}const g=i(l,[["render",h]]);export{c as __pageData,g as default};
|