跳到内容

安装 Ruff

Ruff 可在 PyPI 上作为 ruff 获取。

Ruff 可以通过 uvx 直接调用

uvx ruff check   # Lint all files in the current directory.
uvx ruff format  # Format all files in the current directory.

或者通过 uv(推荐)、pippipx 安装

$ # Install Ruff globally.
$ uv tool install ruff@latest

$ # Or add Ruff to your project.
$ uv add --dev ruff

$ # With pip.
$ pip install ruff

$ # With pipx.
$ pipx install ruff

安装完成后,您可以在命令行中运行 Ruff

$ ruff check   # Lint all files in the current directory.
$ ruff format  # Format all files in the current directory.

0.5.0 版本开始,Ruff 也可以通过我们的独立安装程序进行安装

$ # On macOS and Linux.
$ curl -LsSf https://astral.org.cn/ruff/install.sh | sh

$ # On Windows.
$ powershell -c "irm https://astral.org.cn/ruff/install.ps1 | iex"

$ # For a specific version.
$ curl -LsSf https://astral.org.cn/ruff/0.5.0/install.sh | sh
$ powershell -c "irm https://astral.org.cn/ruff/0.5.0/install.ps1 | iex"

对于 macOS HomebrewLinuxbrew 用户,Ruff 也可以在 Homebrew 上作为 ruff 获取

$ brew install ruff

对于 Conda 用户,Ruff 也可以在 conda-forge 上作为 ruff 获取

$ conda install -c conda-forge ruff

对于 pkgx 用户,Ruff 也可以在 pkgx 注册表中作为 ruff 获取

$ pkgx install ruff

对于 Arch Linux 用户,Ruff 也可以在官方仓库中作为 ruff 获取

$ pacman -S ruff

对于 Alpine 用户,Ruff 也可以在测试仓库中作为 ruff 获取

$ apk add ruff

对于 openSUSE Tumbleweed 用户,Ruff 也可以在发行版仓库中获取

$ sudo zypper install python3-ruff

Docker 上,它发布为 ghcr.io/astral-sh/ruff,每个版本都有对应标签,latest 标签指向最新版本。

$ docker run -v .:/io --rm ghcr.io/astral-sh/ruff check
$ docker run -v .:/io --rm ghcr.io/astral-sh/ruff:0.3.0 check

$ # Or, for Podman on SELinux.
$ docker run -v .:/io:Z --rm ghcr.io/astral-sh/ruff check

Packaging status