axum tokio version compatibility
How to align axum and tokio crate versions and feature flags so your Axum project compiles and runs without dependency errors.
Why axum and tokio must work together
When you add axum to your Rust project, you are not just adding one piece of software. Axum depends on a whole set of other crates. The most important one for running an Axum server is tokio. Tokio is an asynchronous runtime for Rust. It provides the machinery that lets your async fn handlers actually execute, and it gives you the TcpListener that listens for incoming HTTP connections.
Axum is built specifically to work with tokio. The official documentation for axum states that axum is "designed to work with tokio and hyper." That means if you try to use a version of tokio that axum does not support, your code will not compile, or it will behave incorrectly at runtime. This page explains how to choose compatible versions and features, how to verify that everything lines up, and what to do when it does not.
What is a crate?:
In Rust, a "crate" is simply a package of code that you can use as a dependency. Axum and tokio are both crates. When you add them to your project, you list them in the Cargo.toml file under [dependencies].
Understanding version numbers in Cargo.toml
Before we talk about axum and tokio specifically, you need to understand how Rust versions dependencies. Every crate has a version number like 1.54.1 or 0.8.9. This number is split into three parts: major version, minor version, and patch version.
For a version like 1.54.1:
- Major version =
1 - Minor version =
54 - Patch version =
1
Rust follows a rule called semantic versioning, often shortened to semver. The rule says:
- If a new version changes something that could break existing code, the major version number must increase.
- If a new version adds features but stays backward compatible, the minor version increases.
- If a new version only fixes bugs without changing behavior, the patch version increases.
When you write a dependency in Cargo.toml, you usually use a caret requirement like tokio = "1". This means "any version of tokio that has major version 1, and is at least as new as the version specified, but not a major version 2 or higher." So "1" allows 1.0.0, 1.54.1, 1.99.9, but not 2.0.0.
Why major versions matter:
A crate with major version 0, like axum's 0.8.9, is still considered unstable. Rust treats 0.x versions differently: changing from 0.8 to 0.9 can include breaking changes. So when you write axum = "0.8", you are saying "any 0.8.x version." If axum releases 0.9.0, it will not be selected automatically, because that is a different minor version in the 0.x series.
What versions of axum and tokio are compatible right now
As of this writing, the latest stable axum version is 0.8.9, and the latest stable tokio version is 1.54.1 (released 21 October 2026). Axum 0.8.x depends on tokio 1.x. That means your project should use tokio 1.x.
If you accidentally specify tokio 0.2 or some other old major version, axum's internal code will expect types and functions from tokio 1.x, but your project will have a different tokio. Cargo may even build both versions side by side, but when your code uses #[tokio::main] and tokio::net::TcpListener, those types will come from the wrong version, and you will get confusing compile errors.
Don't mix tokio major versions:
Do not write tokio = "0.2" in your Cargo.toml when using axum 0.8. That will almost certainly fail to compile. Always use a 1.x version of tokio.
Adding axum and tokio to your project
The fastest way to add both crates with the correct features is to use cargo add from the command line. This command edits your Cargo.toml for you and picks the latest compatible versions.
Open a terminal in your project directory (the my-axum-app folder you created earlier). Then run:
cargo add axum@0.8
cargo add tokio@1 --features full
The first command adds axum version 0.8.x (the latest patch release). The second command adds tokio version 1.x and enables the full feature, which turns on all of tokio's optional modules, including the ones needed for #[tokio::main] and multi-threaded runtime.
If you prefer to edit Cargo.toml by hand, it should look like this after the commands:
[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }
Let's break down the second line. tokio is the crate name. version = "1" means any 1.x version. features = ["full"] enables the full feature, which is a shorthand for enabling most of tokio's features at once.
What does the full feature include?:
Tokio has many optional features because not every project needs every part. The full feature enables macros, rt-multi-thread, net, time, sync, and many more. For an axum starter project, full is convenient and avoids missing-feature errors.
A minimal working example
Now that the dependencies are set, let's create a complete main.rs that uses axum and tokio together. This is the same Hello World from the axum documentation, but we will explain every line in the context of version compatibility.
Create or replace src/main.rs with:
use axum::{
routing::get,
Router,
};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}
Here is what each piece does:
use axum::{routing::get, Router};brings in axum's router and thegetrouting function.#[tokio::main]is a macro that turns yourasync fn maininto a regularfn mainand starts a tokio runtime inside it. This macro only works if themacrosandrt-multi-threadfeatures of tokio are enabled (orfull).- Inside
main, we build an axumRouterand add one route forGET /. tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap()creates a TCP listener. This listener comes from tokio, not from axum, so your code directly depends on tokio'snetfeature.axum::serve(listener, app)passes the tokio listener to axum, which runs the server on top of hyper (axum's underlying HTTP library).
If you did not have tokio in your Cargo.toml, you would not be able to use #[tokio::main] or TcpListener. If you had an incompatible tokio version, the types would not match.
Running the example and checking the output
Now run the project:
cargo run
You should see output similar to:
Compiling my-axum-app v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 2.45s
Running `target/debug/my-axum-app`
The server is now listening. Open a second terminal and run:
curl http://127.0.0.1:3000/
You should get the response:
Hello, World!
If this works, your axum and tokio versions are compatible and your features are correct.
Everything is aligned:
Seeing Hello, World! from curl confirms that the tokio runtime started correctly, the listener bound to the port, and axum served the route. Your dependency alignment is working.
Why tokio features matter for version compatibility
Sometimes people confuse "version" with "features". You can have the correct version 1.x of tokio, but if you forget to enable macros and rt-multi-thread, the #[tokio::main] macro will not be available. This is not a version incompatibility, but it will produce a compile error that looks like version trouble.
The axum documentation explicitly says: "Note using #[tokio::main] requires you enable tokio's macros and rt-multi-thread features or just full to enable all features."
Here is an example of a Cargo.toml that has the right version but missing features:
[dependencies]
axum = "0.8"
tokio = "1"
This will fail when you try to compile the #[tokio::main] attribute. The macro itself still resolves - axum enables tokio's macros feature for you - but the default runtime flavor is multi-threaded, so you get this error instead:
error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled.
To fix it, either enable the two specific features:
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Or enable full:
tokio = { version = "1", features = ["full"] }
For a beginner, full is easier because you do not have to remember which individual features you need. Later, when you understand your application's needs, you can trim down features to reduce compile time and binary size.
Missing features can look like version errors:
If you see an error like The default runtime flavor is 'multi_thread', but the 'rt-multi-thread' feature is disabled, first check that you have enabled the tokio features. Many new users think their version is wrong when really they just forgot full.
Checking the actual version cargo selected
Sometimes you edit Cargo.toml but you are not sure which version cargo actually resolved. You can use cargo tree to inspect the dependency graph.
Run:
cargo tree
This will list all crates in your project and their versions. Look for tokio and axum entries. For example:
my-axum-app v0.1.0
├── axum v0.8.9
│ ├── axum-core v0.5.6
│ ├── tokio v1.54.1
│ └── ...
└── tokio v1.54.1
Notice that both axum and your own project depend on the same version of tokio (1.54.1). That is what you want.
If you see two different versions of tokio listed, like tokio v1.54.1 and tokio v0.2.25, that is a sign of a version conflict. Cargo can build multiple versions of the same crate, but then your #[tokio::main] code might be using the wrong one.
To see why a particular version is selected, use:
cargo tree -i tokio
The -i flag stands for "invert". It shows which crates depend on tokio and which version they request. This helps you find the source of a version conflict.
How to think about cargo tree:
Think of cargo tree as a map of all the crates your project pulls in. When you see a conflict, it is not a bug in your code; it is a mismatch in the dependency declarations of different crates. Usually fixing your own Cargo.toml to request a compatible version resolves it.
Common version compatibility errors and how to fix them
Below are three common situations beginners encounter, with the error messages and the fix.
Error 1: Different major version of tokio
Symptom: You see compile errors about tokio::main not matching, or about TcpListener not being the same type as what axum expects.
Cause: Your Cargo.toml says something like tokio = "0.2" while axum requires 1.x.
Fix: Change your Cargo.toml to use tokio = "1" or tokio = { version = "1", features = ["full"] }. Then run cargo update and cargo build again.
Error 2: Missing tokio features
Symptom: The #[tokio::main] macro fails to compile with an error about the runtime flavor, like error: The default runtime flavor is 'multi_thread', but the 'rt-multi-thread' feature is disabled.
Cause: You have the right version but no features enabled. This is easy to misread as a version problem, because the macro itself still resolves - axum enables tokio's macros feature for your project, so the #[tokio::main] attribute is found. What is actually missing is the rt-multi-thread feature that the macro's default multi-threaded runtime needs. (In a project without axum at all, the same missing features show up differently, as error[E0433]: cannot find 'main' in 'tokio' and error[E0752]: 'main' function is not allowed to be 'async'.)
Fix: Add features = ["macros", "rt-multi-thread"] or just features = ["full"].
Error 3: Axum version too old for the tokio version
Symptom: Axum itself fails to compile, citing trait bounds from tokio that are not satisfied.
Cause: You are using a very old axum version (like 0.5) with a very new tokio 1.54. Although axum 0.5 also works with tokio 1.x, it might not support the newest tokio features, or it might have different internal requirements. This is rare, but it can happen if you pin an old axum.
Fix: Upgrade axum to the latest 0.8.x by changing axum = "0.5" to axum = "0.8" in Cargo.toml and running cargo update.
Always start with the latest stable versions:
Unless you have a specific reason to pin old versions, use the latest stable axum and tokio. The Rust ecosystem moves quickly, and old versions may lack important fixes.
Using exact versions for reproducibility
Sometimes you want to make sure everyone on your team uses the exact same versions. You can pin exact versions with = in Cargo.toml:
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
However, for a beginner, using caret requirements like "0.8" and "1" is usually better because you automatically receive patch updates that fix bugs. The Cargo.lock file that cargo generates already pins exact versions for reproducible builds. So even with caret requirements, your project will not suddenly jump to a new major version.
Cargo.lock is your friend:
When you run cargo build or cargo run, cargo creates a Cargo.lock file that records the exact version of every dependency that was resolved. This file is committed to version control, so your project will use the same versions on every machine. You do not need to pin exact versions manually unless you have a special requirement.
Adding axum and tokio with a single command
You can add both dependencies in one command by listing them:
cargo add axum@0.8 tokio@1 --features tokio@1/full
This adds axum 0.8 and tokio 1 with the full feature enabled on tokio. (The feature must be qualified with the package it belongs to - tokio@1/full. Writing just tokio/full fails with an error saying the feature was activated for a crate that was not specified.) After running this command, your Cargo.toml will automatically be updated to:
[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }
Using cargo add is the recommended way for beginners because it avoids typos and picks the latest compatible versions.
What happens if you use a newer tokio than axum supports
Axum 0.8.x is tested against tokio 1.x. The 1 in tokio's version means it is stable and backwards compatible within major version 1. So tokio 1.54 will not break axum 0.8.9, even if axum was released before tokio 1.54. That is the promise of semver: minor and patch updates do not break existing code.
So you can safely update tokio to the latest 1.x without worrying about axum compatibility. The same is true in reverse: if axum releases 0.8.10, it will still work with tokio 1.54.
Only when a crate bumps its major version do you need to pay attention. For axum, the next major version will be 0.9. At that point, the axum team may require a newer tokio, but they will announce it clearly in the changelog.
Semver protects you:
Because both axum and tokio follow semantic versioning, as long as you stay within the major versions that the axum documentation recommends, you can update to newer patch and minor versions without fear.
Verifying compatibility with cargo check
Instead of running the full server to test, you can quickly check that your project compiles with:
cargo check
This command compiles the project without producing a final binary, which is faster. If there are any version conflicts or missing features, cargo check will report them just like cargo build.
For our example, after adding the dependencies and main.rs, run:
cargo check
You should see:
Checking my-axum-app v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 0.52s
No errors means your dependency alignment is correct.
Aligning axum and tokio feature flags
Axum itself has features that you can enable. For example, axum has a json feature for JSON support, a ws feature for WebSockets, and a multipart feature for file uploads. These features are unrelated to tokio features, but sometimes beginners confuse them.
Tokio's features control what parts of tokio are available: net for networking, time for timers, sync for synchronization primitives, macros for the #[tokio::main] attribute, and rt-multi-thread for the multi-threaded runtime. Axum's features control what axum-specific functionality is available.
For a basic axum server, you only need tokio's macros and rt-multi-thread (or full), and axum's default features (which include routing and serving). You do not need to enable axum's json feature just to serve a plain string response. The net feature, which TcpListener::bind needs, comes along automatically, because axum's own default features enable it for you - so the lean list below really is enough.
Here is a complete Cargo.toml for a minimal project with only the necessary features:
[package]
name = "my-axum-app"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
This is the lean version. It will compile faster than using full because it only includes what is needed for this simple server.
Do not enable unnecessary features without reason:
While full is convenient, enabling all tokio features increases compile time and binary size. For a learning project it does not matter much, but for a production application, you should enable only the features you actually use.
Upgrading axum and tokio together
When a new major version of axum is released (for example, 0.9.0), you will need to check its documentation for any changes to tokio requirements. Usually the axum team states the minimum supported tokio version in the release notes.
To upgrade, you can change your Cargo.toml:
axum = "0.9"
tokio = { version = "1", features = ["full"] }
Then run:
cargo update
cargo check
If everything compiles, you are aligned.
Read the axum changelog:
The axum GitHub repository has a CHANGELOG.md file that describes every version change. Before upgrading to a new major version, read the changelog to understand breaking changes.
Summary of best practices for axum-tokio compatibility
You now know how to choose compatible versions of axum and tokio, how to enable the right features, and how to verify everything works. The key takeaways are:
- Use axum
0.8.x(or the latest stable) and tokio1.x. - Enable tokio features
macrosandrt-multi-threadat minimum, or usefullfor convenience. - Add dependencies with
cargo addto avoid mistakes. - Use
cargo treeandcargo checkto verify alignment. - When in doubt, read the official axum documentation and changelog.
The most important habit is to keep your dependencies up to date within their major versions and to read error messages carefully. Most axum-tokio issues are solved by fixing a missing feature or correcting a version number, not by complex debugging.
As a decision rule: if the error names a tokio feature or a runtime flavor, fix the feature list first. If it names two different versions of the same crate, fix the version requirement in Cargo.toml and run cargo update. If the project compiles and the curl check returns your handler's response, the versions are aligned, whatever the numbers happen to be.