CARGO-PUBLISH(1)
okay so you're reading the CARGO-PUBLISH(1) page from the General Commands Manual, and bestie, this one is a whole journey. Buckle up. π
β¨ NAME β¨
cargo-publish β uploads a package to the registry. that's the whole vibe. π¦
π¦ SYNOPSIS π¦
cargo publish [options]
π DESCRIPTION π
okay so here's the tea. this command creates a distributable, compressed .crate file with the source code of the package sitting in your current directory, and then it uploads that thing to a registry. the default registry is https://crates.io. slay.
here's the step-by-step, no skips:
- it does a few checks, including:
- it checks the
package.publishkey in the manifest, because that key is the one holding the restrictions on which registries you're even allowed to publish to. π
- it checks the
- it creates a
.cratefile by following the steps incargo-package(1). - it uploads the crate to the registry. heads up: the server will do additional checks on the crate, so it's not just you out here verifying things.
- the client will poll, waiting for the package to appear in the index, and it may timeout. if that happens, you'll need to check for completion manually. and listen β this timeout does not affect the upload. the upload already happened, bestie, it's fine. π
this command requires you to be authenticated, either with the --token option or by using cargo-login(1).
for more details about packaging and publishing, see the reference at https://doc.rust-lang.org/cargo/reference/publishing.html.
π₯ OPTIONS π₯
πΈ Publish Options πΈ
--dry-runβ does all the checks but doesn't upload anything. a little dress rehearsal, a little test run, no commitment. π--tokentoken β the API token to use when authenticating. this overrides the token stored in the credentials file (which is the file thatcargo-login(1)creates for you).- Cargo config environment variables (see https://doc.rust-lang.org/cargo/reference/config.html) can be used to override the tokens stored in the credentials file. the token for crates.io can be specified with the
CARGO_REGISTRY_TOKENenvironment variable. tokens for other registries can be specified with environment variables of the formCARGO_REGISTRIES_NAME_TOKEN, whereNAMEis the name of the registry in all capital letters.
- Cargo config environment variables (see https://doc.rust-lang.org/cargo/reference/config.html) can be used to override the tokens stored in the credentials file. the token for crates.io can be specified with the
--no-verifyβ don't verify the contents by building them. skipping the vibe check, risky but okay. π--allow-dirtyβ allows working directories with uncommitted VCS changes to be packaged. yes bestie, you can publish with uncommitted chaos lying around. π«Ά--indexindex β the URL of the registry index to use.--registryregistry β the name of the registry to publish to. registry names are defined in Cargo config files (see https://doc.rust-lang.org/cargo/reference/config.html). if it's not specified, and there's apackage.publishfield inCargo.toml(see https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field) with a single registry, then it'll publish to that registry. otherwise it uses the default registry, which is defined by theregistry.defaultconfig key (see https://doc.rust-lang.org/cargo/reference/config.html#registrydefault), and that defaults tocrates-io.
π Package Selection π
by default, the package in the current working directory is the chosen one. the -p flag lets you pick a different package inside a workspace. π
-pspec,--packagespec β the package to publish. seecargo-pkgid(1)for theSPECformat.
π Compilation Options π
--targettriple β publish for the given architecture. the default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>. runrustc --print target-listfor a list of supported targets. this flag may be specified multiple times.- this may also be specified with the
build.targetconfig value (see https://doc.rust-lang.org/cargo/reference/config.html). - note that specifying this flag makes Cargo run in a different mode, where the target artifacts get placed in a separate directory. see the build cache documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details.
- this may also be specified with the
--target-dirdirectory β directory for all generated artifacts and intermediate files. may also be specified with theCARGO_TARGET_DIRenvironment variable, or thebuild.target-dirconfig value (see https://doc.rust-lang.org/cargo/reference/config.html). defaults totargetin the root of the workspace.
π¦ Feature Selection π¦
the feature flags let you control which features are enabled. when no feature options are given, the default feature is activated for every selected package.
see the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options for more details.
-Ffeatures,--featuresfeatures β a space or comma separated list of features to activate. features of workspace members may be enabled withpackage-name/feature-namesyntax. this flag may be specified multiple times, which enables all specified features.--all-featuresβ activate all available features of all selected packages. all of them. the whole menu. π--no-default-featuresβ do not activate the default feature of the selected packages.
β Manifest Options β
--manifest-pathpath β path to theCargo.tomlfile. by default, Cargo searches for theCargo.tomlfile in the current directory or any parent directory.--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios arises:- the lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
it may be used in environments where deterministic builds are desired, such as in CI pipelines.
--offlineβ prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network isn't available. with this flag, Cargo will attempt to proceed without the network if possible.
beware bestie: this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. see the cargo-fetch(1) command to download dependencies before going offline. π
may also be specified with the net.offline config value (see https://doc.rust-lang.org/cargo/reference/config.html).
--frozenβ equivalent to specifying both--lockedand--offline. two for one, iconic.--lockfile-pathPATH β changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) toPATH.PATHmust end withCargo.lock(e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock). note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile fromPATH, or write a new lockfile into the providedPATHif it doesn't exist. this flag can be used to run most commands in read-only directories, writing the lockfile into the providedPATH.
this option is only available on the nightly channel (see https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #14421 at https://github.com/rust-lang/cargo/issues/14421). π§
π Miscellaneous Options π
-jN,--jobsN β number of parallel jobs to run. may also be specified with thebuild.jobsconfig value (see https://doc.rust-lang.org/cargo/reference/config.html). defaults to the number of logical CPUs. if negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus the provided value. if a stringdefaultis provided, it sets the value back to defaults. should not be0. π«--keep-goingβ build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.- for example, if the current package depends on dependencies
failsandworks, one of which fails to build,cargo publish -j1may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereascargo publish -j1 --keep-goingwould definitely run both builds, even if the one run first fails. main character energy: it refuses to give up. π
- for example, if the current package depends on dependencies
π Display Options π
-v,--verboseβ use verbose output. may be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. may also be specified with theterm.verboseconfig value (see https://doc.rust-lang.org/cargo/reference/config.html).-q,--quietβ do not print cargo log messages. may also be specified with theterm.quietconfig value (see https://doc.rust-lang.org/cargo/reference/config.html).--colorwhen β control when colored output is used. valid values:auto(default): automatically detect if color support is available on the terminal.always: always display colors.never: never display colors.
may also be specified with the term.color config value (see https://doc.rust-lang.org/cargo/reference/config.html).
π«Ά Common Options π«Ά
+toolchain β if Cargo has been installed with rustup, and the first argument tocargobegins with+, it will be interpreted as a rustup toolchain name (such as+stableor+nightly). see the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work.--configKEY=VALUE or PATH β overrides a Cargo configuration value. the argument should be in TOML syntax ofKEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times. see the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information.-CPATH β changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering.cargo/config.toml, for example. this option must appear before the command name, for examplecargo -C path/to/my-project build.
this option is only available on the nightly channel (see https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098). π§
-h,--helpβ prints help information. the classic. π-Zflag β unstable (nightly-only) flags to Cargo. runcargo -Z helpfor details.
πΈ ENVIRONMENT πΈ
see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads.
π EXIT STATUS π
0: Cargo succeeded. π101: Cargo failed to complete. π
β¨ EXAMPLES β¨
Okay bestie, real talk, this part is short and sweet because the command does the heavy lifting for you. Here's the whole vibe:
- Publish the current package:
cargo publish
That's it. That's the post. You're in the package directory, you run it, the world gets your code. Main character behaviour fr fr. π
No cap though, peep the earlier sections before you send it β publishing is one of those things you can't just take back like a risky text. π
π SEE ALSO π
Because no queen works alone, here's the little squad that hangs out with this page:
cargo(1)β the big one, the mothership, the whole reason we're here πcargo-package(1)β for when you wanna bundle it up before you yeet it out there πcargo-login(1)β so the registry actually knows it's you, iykyk π
and that's the whole page, babe. it's part of the cargo manual, footer reads CARGO-PUBLISH(1) β cargo's own docs, dated and versioned right there with it. go publish something iconic. you got this. πππ¦
π¦ where this page comes from
- ubuntu jammy: cargo-1.83 1.83.0+dfsg0ubuntu2~bpo2-0ubuntu2.22.04.1 Β· Apache-2.0 WITH LLVM exception
- ubuntu noble: cargo-1.83 1.83.0+dfsg0ubuntu1~bpo2-0ubuntu0.24.04.1 Β· Apache-2.0 WITH LLVM exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms