{"id":"a0f20d74476b0b8c","repo":"rust-lang/cargo","slug":"invalid-package-name-url-use-cargo-insta","errorCode":null,"errorMessage":"invalid package name: `{url}`\n    Use `cargo install --git {url}` if you meant to install from a git repository.","messagePattern":"invalid package name: `(.+?)`\n    Use `cargo install --git (.+?)` if you meant to install from a git repository\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/install.rs","lineNumber":163,"sourceCode":"                        return Err(\n                            anyhow::format_err!(\"{err}\\n\\n\\\n                                help: if this is meant to be a package name followed by a version, insert an `@` like `{suggested_crate_name}`\").into());\n                    }\n                }\n            }\n        }\n\n        if let Some(toolchain) = crate_name.strip_prefix(\"+\") {\n            return Err(anyhow!(\n                \"invalid character `+` in package name: `+{toolchain}`\n    Use `cargo +{toolchain} install` if you meant to use the `{toolchain}` toolchain.\"\n            )\n            .into());\n        }\n\n        if let Ok(url) = crate_name.into_url() {\n            if matches!(url.scheme(), \"http\" | \"https\") {\n                return Err(anyhow!(\n                    \"invalid package name: `{url}`\n    Use `cargo install --git {url}` if you meant to install from a git repository.\"\n                )\n                .into());\n            }\n        }\n\n        if crate_name != \".\"\n            && let Err(e) = package_name\n        {\n            return Err(anyhow::format_err!(\"{e}\").into());\n        }\n    }\n\n    let mut from_cwd = false;\n\n    let source = if let Some(url) = args.get_one::<String>(\"git\") {\n        let url = url.into_url()?;","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/install.rs#L145-L181","documentation":"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.","triggerScenarios":"`cargo install https://github.com/user/repo` instead of `cargo install --git https://github.com/user/repo`.","commonSituations":"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.","solutions":["Add the --git flag: `cargo install --git https://github.com/user/repo`.","Optionally add --branch/--tag/--rev to pin the git source.","If installing from crates.io, use the plain crate name instead of a URL."],"exampleFix":"// before\ncargo install https://github.com/BurntSushi/ripgrep\n\n// after\ncargo install --git https://github.com/BurntSushi/ripgrep","handlingStrategy":"validation","validationCode":"// Detect URL-shaped crate args and require --git\nfn needs_git_flag(crate_arg: &str) -> bool {\n    crate_arg.starts_with(\"http://\") || crate_arg.starts_with(\"https://\")\n}\n\nif needs_git_flag(arg) {\n    cmd.args([\"--git\", arg]);\n} else {\n    cmd.arg(arg);\n}","typeGuard":"fn is_http_url(s: &str) -> bool {\n    s.starts_with(\"http://\") || s.starts_with(\"https://\")\n}","tryCatchPattern":null,"preventionTips":["For git sources always pass `--git <url>` (plus --branch/--tag/--rev as needed).","For crates.io installs use the plain crate name."],"tags":["cargo","install","git","url","cli"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}