cargo publish: Usage, Options & Common CI Errors
Package and upload your crate to a registry.
cargo publish builds a .crate package, verifies it compiles, and uploads it to crates.io (or another registry). Publishing is permanent - a version cannot be overwritten.
What it does
Runs the equivalent of cargo package, compiles the packaged crate to verify it, then uploads it to the registry using your auth token. Required metadata (license, description) must be present.
Common usage
cargo publish --dry-run # validate without uploading
cargo publish # publish to crates.io
cargo publish --token "${CARGO_REGISTRY_TOKEN}"
cargo publish --no-verify # skip the compile checkCommon CI error: version already exists
A release re-run fails with "error: crate version 1.2.3 is already uploaded." crates.io is immutable, so you cannot republish a version. Fix: bump the version in Cargo.toml. For missing metadata, "error: missing field license" means you must set license or license-file in [package].
Options
| Flag | Effect |
|---|---|
| --dry-run | Validate, do not upload |
| --token <t> | Registry auth token |
| --no-verify | Skip the build verification |
| --allow-dirty | Publish with uncommitted changes |