What is the closest alternative to `npm ci` in Yarn?

I’m trying to find out what command in Yarn is similar to npm’s ci command, which installs packages in a clean manner. The npm ci command is known for being quicker and stricter compared to a regular npm install. It bypasses some user-oriented features and is useful for identifying errors from incremental installations.

Despite my efforts, I’m having trouble locating a definitive answer regarding which Yarn command aligns with this functionality. Is there a direct equivalent in Yarn, or do I need to adjust specific settings with yarn install?

For reference, here’s how I typically perform a clean install using npm:

# Clean install with npm
npm ci

What should be the corresponding command in Yarn to achieve similar clean, fast, and strict installation outcomes?

honestly just use yarn install --immutable if you’re on newer yarn versions. works exactly like npm ci - fails fast if lockfile doesn’t match and won’t update anything. way cleaner than the old frozen-lockfile approach imo

Yarn v1 doesn’t have an exact npm ci equivalent, but yarn install --frozen-lockfile gets you pretty close. It stops Yarn from touching the lockfile and fails if dependencies don’t match what’s recorded - basically what npm ci does. I’ve used this in CI for two years and it’s rock solid. The --frozen-lockfile flag blocks any lockfile changes and makes installs predictable, which is perfect for automated builds. Just a heads up - if you’re on Yarn v2+ (Berry), yarn install is already immutable by default, so you don’t need the flag.

Depends on your Yarn version, but here’s what I’ve learned works best. Sure, --frozen-lockfile and --immutable do the job, but I get the closest thing to npm ci behavior by clearing the cache first, then running yarn install --pure-lockfile on older Yarn versions. The --pure-lockfile flag stops any yarn.lock updates and keeps installs reproducible. I’ve deployed tons of Node apps and this combo beats just using frozen-lockfile alone - especially when optional dependencies start acting up. With Yarn v2+, plain yarn install is usually strict enough unless you’re in CI and specifically need the immutable flag.