How to Use Private Registries with Cargo

Configure a private registry in Cargo config and specify it in Cargo.toml dependencies to fetch internal crates.

Configure your private registry in ~/.cargo/config.toml (or .cargo/config.toml in your project) and add the registry name to your Cargo.toml dependencies.

  1. Add your registry configuration to ~/.cargo/config.toml with your registry URL and authentication token.
[registries.my-private-registry]
index = "https://github.com/my-org/my-registry-index.git"

[registry.my-private-registry]
token = "YOUR_AUTH_TOKEN"
  1. Specify the registry in your Cargo.toml file for the specific crate you want to pull from it.
[dependencies]
my-private-crate = { version = "1.0", registry = "my-private-registry" }
  1. Run cargo build to fetch the crate from your configured private registry.
cargo build