# UV

`uv` 是一个用 Rust 编写的超快 Python 包安装器和解析器，兼容 `pip`、`pip-tools` 和 `virtualenv` 等工具。

{% tabs %}
{% tab title="macos/Linux" %}

```shell
curl -LsSf https://astral.sh/uv/install.sh | sh
# 或使用 wget
wget -qO- https://astral.sh/uv/install.sh | sh
# 指定版本（例如 0.8.17）
curl -LsSf https://astral.sh/uv/0.8.17/install.sh | sh
```

{% endtab %}

{% tab title="Windows" %}

```shellscript
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# 指定版本
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/0.8.17/install.ps1 | iex"
```

{% endtab %}
{% endtabs %}

## Shell 自动补全

要为 uv 命令启用 shell 自动补全，请运行以下命令之一：

{% tabs %}
{% tab title="Bash" %}

```shellscript
echo 'eval "$(uv generate-shell-completion bash)"' >> ~/.bashrc
```

{% endtab %}

{% tab title="Zsh" %}

```shellscript
echo 'eval "$(uv generate-shell-completion zsh)"' >> ~/.zshrc
```

{% endtab %}

{% tab title="fish" %}

```shellscript
uv generate-shell-completion fish | source > ~/.config/fish/completions/uv.fish
```

{% endtab %}

{% tab title="Elvish" %}

```shellscript
echo 'eval (uv generate-shell-completion elvish | slurp)' >> ~/.elvish/rc.elv
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}
Add-Content -Path $PROFILE -Value '(& uv generate-shell-completion powershell) | Out-String | Invoke-Expression'
```

{% endtab %}
{% endtabs %}

要为 uvx 命令启用 shell 自动补全，请运行以下命令之一：

{% tabs %}
{% tab title="Bash" %}

```shell
echo 'eval "$(uvx --generate-shell-completion bash)"' >> ~/.bashrc
```

{% endtab %}

{% tab title="Zsh" %}

```shell
echo 'eval "$(uvx --generate-shell-completion zsh)"' >> ~/.zshrc
```

{% endtab %}

{% tab title="fish" %}

```
echo 'uvx --generate-shell-completion fish | source' > ~/.config/fish/completions/uvx.fish
```

{% endtab %}

{% tab title="Elvish" %}

```shell
echo 'eval (uvx --generate-shell-completion elvish | slurp)' >> ~/.elvish/rc.elv
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}
Add-Content -Path $PROFILE -Value '(& uvx --generate-shell-completion powershell) | Out-String | Invoke-Expression'
```

{% endtab %}
{% endtabs %}

## 卸载

1. 清理已存储的数据（可选）：

```shellscript
uv cache clean
rm -r "$(uv python dir)"
rm -r "$(uv tool dir)"
```

2. 删除 uv、uvx、uvw 二进制文件。

{% tabs %}
{% tab title="macOS/Linux" %}

```
rm ~/.local/bin/uv ~/.local/bin/uvx
```

{% endtab %}

{% tab title="Windows" %}

```
rm $HOME\.local\bin\uv.exe
rm $HOME\.local\bin\uvx.exe
rm $HOME\.local\bin\uvw.exe
```

{% endtab %}
{% endtabs %}
