rust-lang/cargo · error

invalid package name: `{url}` Use `cargo install --git {

Error message

invalid package name: `{url}`
    Use `cargo install --git {url}` if you meant to install from a git repository.

What it means

From install::exec (src/bin/cargo/commands/install.rs:161-169). If a crate argument parses successfully as an http/https URL, Cargo assumes you meant to install from a git repository but forgot the --git flag, and bails suggesting `cargo install --git <url>`. Plain crate names from crates.io must not be URLs.

Source

Thrown at src/bin/cargo/commands/install.rs:163

                        return Err(
                            anyhow::format_err!("{err}\n\n\
                                help: if this is meant to be a package name followed by a version, insert an `@` like `{suggested_crate_name}`").into());
                    }
                }
            }
        }

        if let Some(toolchain) = crate_name.strip_prefix("+") {
            return Err(anyhow!(
                "invalid character `+` in package name: `+{toolchain}`
    Use `cargo +{toolchain} install` if you meant to use the `{toolchain}` toolchain."
            )
            .into());
        }

        if let Ok(url) = crate_name.into_url() {
            if matches!(url.scheme(), "http" | "https") {
                return Err(anyhow!(
                    "invalid package name: `{url}`
    Use `cargo install --git {url}` if you meant to install from a git repository."
                )
                .into());
            }
        }

        if crate_name != "."
            && let Err(e) = package_name
        {
            return Err(anyhow::format_err!("{e}").into());
        }
    }

    let mut from_cwd = false;

    let source = if let Some(url) = args.get_one::<String>("git") {
        let url = url.into_url()?;

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Add the --git flag: `cargo install --git https://github.com/user/repo`.
  2. Optionally add --branch/--tag/--rev to pin the git source.
  3. If installing from crates.io, use the plain crate name instead of a URL.

Example fix

// before
cargo install https://github.com/BurntSushi/ripgrep

// after
cargo install --git https://github.com/BurntSushi/ripgrep
Defensive patterns

Strategy: validation

Validate before calling

// Detect URL-shaped crate args and require --git
fn needs_git_flag(crate_arg: &str) -> bool {
    crate_arg.starts_with("http://") || crate_arg.starts_with("https://")
}

if needs_git_flag(arg) {
    cmd.args(["--git", arg]);
} else {
    cmd.arg(arg);
}

Type guard

fn is_http_url(s: &str) -> bool {
    s.starts_with("http://") || s.starts_with("https://")
}

Prevention

When it happens

Trigger: `cargo install https://github.com/user/repo` instead of `cargo install --git https://github.com/user/repo`.

Common situations: New users expecting URL-first syntax; copy-pasting a repo URL where a crate name goes; docs that show the URL without the --git flag.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/a0f20d74476b0b8c.json. Report an issue: GitHub.