The Direct Answer
To recover a functional environment from a known backup, you should restore the backup Manifest.toml first, then run Pkg.instantiate(). Pkg.instantiate() is the only command that guarantees an attempt to restore the exact state recorded in the Manifest. Pkg.resolve() should be avoided during initial recovery because it ignores the existing Manifest's specific version pins and attempts to calculate a new dependency graph, which may lead to different package versions than those used in your previously working state.
How the Recovery Mechanisms Differ
Understanding the distinction between these two commands is critical when dealing with a corrupted Manifest.toml:
Pkg.instantiate()
- Behavior: It treats the
Manifest.toml as the source of truth. It downloads and installs the exact versions and artifacts specified in that file.
- Safety: It will not "propagate" incompatibilities if you have restored a known-good backup Manifest. However, it will fail if the specific versions recorded in that backup are no longer available in the General Registry.
- Use Case: Use this when you have a valid Manifest and need the local disk state to match it.
Pkg.resolve()
- Behavior: It ignores the current version pins in the Manifest and re-evaluates the constraints listed in
Project.toml. It then writes a new Manifest.
- Safety: While it can bypass an "impossible" version entry by calculating a fresh compatible set, it does not guarantee a working configuration identical to your previous one. It may upgrade other packages, potentially introducing new breaking changes.
- Use Case: Use this only if your backup Manifest is lost or if the registry has evolved such that the old Manifest is no longer resolvable.
Recovery Workflow
Follow these steps to safely restore your environment (assuming Julia 1.6+):
- Restore Files: Replace the corrupted
Manifest.toml with your backup copy.
- Instantiate: Run the following in the Julia REPL:
import Pkg; Pkg.instantiate()
- Verify: Check the status to ensure no packages are missing:
Pkg.status()
Assumptions and Uncertainties
This approach assumes that the Project.toml remains unchanged and that the registry versions referenced in the backup Manifest are still hosted. If Pkg.instantiate() fails with a "version not found" error, it indicates the registry has purged those specific versions, at which point Pkg.resolve() becomes the necessary fallback to find the next best compatible versions.
Missing Diagnostic: Are you using a custom local registry or the standard General registry? If using a private registry, Pkg.instantiate() will fail unless the registry URL is correctly configured in your local environment.