# \`cargo install --locked\` or not locked middle ground?

**URL:** <https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893>\
**Category:** cargo\
**Created:** [January 3, 2026, 5:21pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893 "2026-01-03T17:21:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [January 3, 2026, 5:21pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/1 "2026-01-03T17:21:52Z")

</div>

`cargo install crate-cli` has a dilemma:

- Respecting the crate's lockfile makes dependencies more predictable, match what the crate author has tested with, and less likely to break due to semver violations in dependency updates.

- Ignoring the crate's lockfile makes dependencies more up-to-date, possibly include security fixes, and less likely to break due outdated dependencies that became incompatible with newer compiler or operating system releases.

Different developers value/judge the stability vs risk issues differently, so there are strong opinions in favor of either option (e.g. having future security fixes may be more important than any trouble from updated packages, or that the released binary should keep working forever).

End users can choose the behavior with the `--locked` flag, but the default behavior is important — novice users may not know about the flag or its tradeoffs. Developers may be annoyed they need to instruct end users to add the flag (and another group of devs could be annoyed if the other option was the default and a different flag was needed for the other behavior).

Can `cargo install` have best of both somehow? Some ideas (assume every one of them can still have its own flag/config/opt-out):

- run `install` without a lockfile, but if the build fails, retry with the lockfile. IMHO that would have best of both in the majority of cases (except an edge case where two different dependencies need opposite strategies at the same time), but at a cost of sometimes much longer `cargo install` time. It should be pretty easy to implement.
- use the lockfile, but update yanked dependencies (perform equivalent of `cargo generate-lockfile` before `install`). This would depend on authors yanking broken crate versions (unfortunately some authors are unresponsive or prefer to keep all versions available in case anybody used them anyway). It should be relatively easy to implement too.
- allow registries to explicitly mark releases that are security updates and update only these dependencies (IMHO insecure versions should be yanked, but some crate authors think that's too harsh, so a softer yank could solve it). This might even be integrated with rustsec or other vuln databases. It won't help with compiler compatibility issues.
- Update locked dependencies' patch versions only (treating every locked version as `x.y.*` requirement), which would hopefully avoid updating to bigger breaking releases, but still allow crate authors to release bug/compatibility fixes. Currently the crates-io ecosystem doesn't really pay attention to patch releases for minor versions, but if Cargo had such behavior, there would be a motivation to support it.

---

<div class="post-metadata">

**Author:** ![pitaj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pitaj/32/11262_2.png) [@pitaj](https://internals.rust-lang.org/u/pitaj)\
**Post date:** [January 3, 2026, 6:40pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/2 "2026-01-03T18:40:19Z")

</div>

What about allowing authors to specify the default for their crate? A configuration in Cargo.toml that says "use the lock file when installing this".

---

<div class="post-metadata">

**Author:** ![IndianBoy42](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/indianboy42/32/7138_2.png) [@IndianBoy42](https://internals.rust-lang.org/u/IndianBoy42)\
**Post date:** [January 4, 2026, 2:51am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/3 "2026-01-04T02:51:57Z")

</div>

> run install without a lockfile, but if the build fails, retry with the lockfile. IMHO that would have best of both in the majority of cases (except an edge case where two different dependencies need opposite strategies at the same time), but at a cost of sometimes much longer cargo install time. It should be pretty easy to implement.

Idea that's probably too hard to implement: What about run without the lockfile and for every dependency that fails (or somehow causes compilation to file) downgrade just that crate to the lockfile version and recompile that crate (and it's dependents) only. Saves a bit to a lot of time depending on the dependency

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [January 4, 2026, 5:20am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/4 "2026-01-04T05:20:18Z")

</div>

If it is a shared dependency, you might have to find some intermediate minimal version to satisfy it. Or downgrade other packages.

Imagine:

- A -\> B
- A -\> C
- B -\> C

A's lockfile says B 1.1 and C 1.0. Latest is B 1.3 and C 1.4, but C 1.4 fails for whatever reason, you can't use the lockfile because B 1.3 says it needs C 1.2 (say, for a new API). So you need to do a full solve again for this.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [January 5, 2026, 11:11am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/5 "2026-01-05T11:11:56Z")

</div>

`cargo update -p --precise` already has ability to partially update the dependencies. The bigger problem may be in identifying which crates are at fault, because the crate that fails to compile may not be the crate that caused the problem, and `cargo` doesn't have insight into the code to understand root cause of errors. Imagine if `serde` made a breaking API change: everything other than `serde` would have a problem. Trying to find working deps one by one by trial and error could make it much slower, since everything downstream from a changed dependency will need to be rebuilt.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [January 5, 2026, 1:50pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/6 "2026-01-05T13:50:54Z")

</div>

Personally, I think I would prefer we just went with `--locked` always and required application authors to re-release when a security update is needed.

- The lack of `--locked` only helps when installing. Most packages that I've `cargo install`ed were installed years ago.
- Most applications likely have to re-release anyways for pre-built binaries
- `cargo install` isn't and (imo) shouldn't be treated as a general purpose installation tool, so having limitations is sufficient.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [January 5, 2026, 3:29pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/7 "2026-01-05T15:29:09Z")

</div>

I've had `cargo update -p --precise` do nothing because of unsatisfiability problems. Alas, logging of why it failed to do anything is missing (no, I've not filed an issue about it; it is always already a sidequest to my actual goal and tacking more on is a great way to lose track of what that goal is).

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [January 5, 2026, 11:36pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/8 "2026-01-05T23:36:40Z")

</div>

I'd be thrilled with this, personally, as long as projects systematically updated and published regularly.

In _principle_, packages should always work with newer versions of crates, and `cargo update` should always work. In practice, there are things that break this. Most commonly _not_ from crates that break API without a major semver break, but rather from dependency stunts (e.g. crates in the dependency graph that think an `=` or `~` or `<` dependency is a good idea).

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [January 6, 2026, 12:35am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/9 "2026-01-06T00:35:41Z")

</div>

There's one crate I maintain that recommends `=` dependencies, but that's because it binds to another API that may make changes that are Rust-incompatible. If usage is exposed, it is recommended to `pub` the crate again so that transitive users can use it without having to figure out a dependency version themselves. We _have_ since figured out a pattern that is much more robust to Rust's idea of API stability, but the deprecation cycle for the definitely-not-API-stable patterns continues.

---

<div class="post-metadata">

**Author:** ![threefold3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/threefold3/32/10541_2.png) [@threefold3](https://internals.rust-lang.org/u/threefold3)\
**Post date:** [January 6, 2026, 6:51am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/10 "2026-01-06T06:51:09Z")

</div>

Indeed I have found that `cargo install` has sometimes inconsistent behaviour. When I want to try a tool and the README says `cargo install xxx` and it fails with a compilation error, my first thought is : oh, ok this tool is not ready for production, forget it.

I learn by this discussion that it is not necessarily a negligence in developing the crate, but comes from tooling. So +1 for this discussion and finding a solution where when you release a crate, users can rely on reproductible installation steps.

---

<div class="post-metadata">

**Author:** ![threefold3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/threefold3/32/10541_2.png) [@threefold3](https://internals.rust-lang.org/u/threefold3)\
**Post date:** [January 6, 2026, 6:55am UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/11 "2026-01-06T06:55:31Z")

</div>

> [@epage](#):
>
> `cargo install` isn't and (imo) shouldn't be treated as a general purpose installation tool, so having limitations is sufficient.

Hasn't it become the defacto default ? Except for rustup installed components, I don't recall other means of installation recommended by default by crate authors. It is systematically cargo install.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [January 6, 2026, 4:09pm UTC](https://internals.rust-lang.org/t/cargo-install-locked-or-not-locked-middle-ground/23893/12 "2026-01-06T16:09:25Z")

</div>

`cargo install` is the one and only _Rust executable_ installation tool that works on all platforms where Rust toolchains can be run. So, it is generally suitable for installing command-line tools that are used for developing Rust programs, and that is why it is the default for _that_ purpose. But:

- It cannot install manual pages, Linux `.desktop` files, or data files that should accompany a program.
- It cannot perform any build steps that would _generate_ such accompanying files, if they are not already in the Cargo package, or perform steps which would modify or wrap the executable, such as macOS `.app` bundle creation.
- It cannot create file associations or otherwise register the program with the OS or desktop environment.
- It cannot integrate with existing application package management.

Therefore, there are many kinds of applications it cannot correctly install.
