Last modified: Jun 06, 2026
Install Ruff in Python: Quick Guide
Ruff is a fast Python linter and formatter. It is written in Rust. It replaces tools like Flake8, isort, and Black. This guide shows you how to install Ruff in Python. You will learn multiple methods. We cover pip, uv, and virtual environments. Let's get started.
Why Use Ruff?
Ruff is extremely fast. It can lint and format thousands of files in seconds. It supports Python 3.7 and above. It has over 700 built-in rules. It also supports plugins. Ruff is a single binary. No dependencies are needed. This makes it easy to install.
Ruff integrates with editors like VS Code and PyCharm. It also works with pre-commit hooks. Many projects now use Ruff. It simplifies tooling. You only need one tool for linting and formatting.
Prerequisites
Before you install Ruff, check your Python version. Ruff requires Python 3.7 or newer. Open your terminal and run:
python --version
If you see Python 3.7+, you are ready. If not, update Python first. You also need pip installed. Pip is the Python package manager. Most Python installations include it.
Method 1: Install Ruff with pip
The easiest way is using pip. Run this command in your terminal:
pip install ruff
This installs the latest Ruff version. You can verify the installation:
ruff --version
You should see output like:
ruff 0.6.0
If you use Python 3, use pip3 instead:
pip3 install ruff
This works on Windows, macOS, and Linux.
Method 2: Install Ruff in a Virtual Environment
It is best practice to use virtual environments. This avoids conflicts with other projects. Create a virtual environment first:
python -m venv myenv
Activate it:
# On Windows:
myenv\Scripts\activate
# On macOS/Linux:
source myenv/bin/activate
Now install Ruff inside the environment:
pip install ruff
Your project stays clean. Ruff is only available when the environment is active.
Method 3: Install Ruff with uv
uv is a fast Python package manager. It is written in Rust too. It installs packages much faster than pip. First, install uv:
pip install uv
Then use uv to install Ruff:
uv pip install ruff
uv also creates virtual environments quickly:
uv venv
source .venv/bin/activate
uv pip install ruff
This method is great for speed. It is perfect for large projects.
Method 4: Install Ruff from Source
You can also build Ruff from source. This requires Rust installed. First, install Rust from rustup.rs. Then clone the Ruff repository:
git clone https://github.com/astral-sh/ruff.git
cd ruff
cargo build --release
The binary is in target/release/ruff. Copy it to your PATH. This method is for advanced users. Most people prefer pip or uv.
Verify Ruff Installation
After installation, test Ruff on a Python file. Create a file called test.py:
# test.py
def add(a,b):
return a+b
result=add(1,2)
print(result)
Now lint it with Ruff:
ruff check test.py
You might see output like:
test.py:1:1: E302 expected 2 blank lines after class or function definition
test.py:1:11: E231 missing whitespace after ','
test.py:4:1: E305 expected 2 blank lines after class or function definition
test.py:4:8: E225 missing whitespace around operator
Ruff found style issues. Now format the file:
ruff format test.py
Check the file again. It should be cleaner. Ruff fixed the spacing and blank lines.
Use Ruff with pre-commit
You can add Ruff to your pre-commit hooks. This ensures every commit is linted. Create a .pre-commit-config.yaml file:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.0
hooks:
- id: ruff
- id: ruff-format
Install pre-commit:
pip install pre-commit
pre-commit install
Now Ruff runs automatically before each commit. This keeps your codebase consistent.
Configure Ruff
Ruff uses a pyproject.toml file for configuration. Create it in your project root:
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I", "N"]
ignore = ["E501"]
This sets line length to 88. It selects common rules. It ignores line-too-long errors. You can customize it further. Ruff supports many options.
Common Issues and Fixes
Issue:ruff: command not found
Fix: Ensure the virtual environment is active. Or install Ruff globally with pip install --user ruff.
Issue: Permission denied on Linux/macOS
Fix: Use sudo pip install ruff or install in a virtual environment.
Issue: Ruff is slow on large projects
Fix: Use ruff check --no-cache to disable caching. Or upgrade to the latest version.
Conclusion
You now know how to install Ruff in Python. Use pip for simplicity. Use uv for speed. Use virtual environments for safety. Ruff improves your code quality. It catches errors and enforces style. Start using Ruff today. Your future self will thank you.