Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/conda/conda/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The conda env update command updates an existing conda environment based on an environment definition file. This is useful for adding new packages or updating existing ones while preserving the environment.

Syntax

conda env update [options]
By default, conda env update uses environment.yml in the current directory and updates the currently active environment.

Target Environment Specification

-n, --name
string
Name of environment to update. If not specified, conda will:
  1. Use the name from the environment file
  2. Fall back to the currently active environment (CONDA_DEFAULT_ENV)
-p, --prefix
string
Full path to environment location (i.e. prefix).

File Options

-f, --file
string
default:"environment.yml"
Environment definition file containing the packages to install or update.Supported formats:
  • YAML environment files (environment.yml)
  • Requirements.txt files
  • Any format supported by environment specifier plugins

Update Behavior Options

--prune
boolean
default:false
Remove installed packages not defined in environment.yml. This makes the environment match the specification file exactly.
Using --prune will remove any packages not listed in the environment file. This includes packages you may have manually installed.

Environment Specifier Options

--environment-specifier
string
Specify which environment specifier plugin to use for parsing the environment file.

Frozen Environment Options

--override-frozen
boolean
DANGEROUS. Use at your own risk. Ignore protections if the environment is frozen.
Frozen environments are typically protected for a reason. Only use this flag if you understand the implications.

Solver Options

--solver
string
Choose which solver backend to use.

Output and Prompt Options

--json
boolean
Report all output as JSON. Suitable for using conda programmatically.
-v, --verbose
boolean
Can be used multiple times. Once for INFO, twice for DEBUG, three times for TRACE.
-q, --quiet
boolean
Do not display progress bar.

Examples

Update current environment

conda activate myenv
conda env update
Updates the active environment using environment.yml in the current directory.

Update specific environment

conda env update -n myenv -f environment.yml
Updates myenv environment with packages from the specified file.

Update with pruning

conda env update --prune
Updates the environment and removes packages not listed in environment.yml.

Update from specific file

conda env update -f /path/to/environment.yml
Updates using a file from a specific location.

Update from requirements.txt

conda env update -f requirements.txt -n myenv
Updates environment using a pip requirements file.

Update with verbose output

conda env update -v
Shows detailed information during the update process.

Common Use Cases

Update your environment.yml and apply changes:
  1. Edit environment.yml:
name: myproject
dependencies:
  - python=3.11
  - numpy
  - pandas  # newly added
  1. Update the environment:
conda env update
Team members can update their environments to match the project specification:
git pull  # Get latest environment.yml
conda env update --prune  # Match exactly
Change version constraints in environment.yml:
dependencies:
  - python=3.11
  - pandas>=2.0  # Updated from pandas>=1.5
conda env update
Update environment variables without recreating:
name: myenv
dependencies:
  - python=3.11
variables:
  NEW_VAR: value  # Newly added
conda env update
Without --prune (additive):
conda env update
# Adds/updates packages, keeps extra packages
With --prune (exact match):
conda env update --prune
# Makes environment match file exactly

Update Behavior

Without —prune (Default)

  • Packages in the file are installed or updated
  • Existing packages not in the file are kept
  • Dependencies are resolved and may be updated
Example: Current environment: python=3.11, numpy=1.24, pandas=1.5, matplotlib=3.7 Environment file:
dependencies:
  - python=3.11
  - numpy=1.26
  - pandas=2.0
Result: python=3.11, numpy=1.26, pandas=2.0, matplotlib=3.7 (matplotlib kept)

With —prune

  • Packages in the file are installed or updated
  • Packages not in the file are removed
  • Environment matches the file exactly
Example: Current environment: python=3.11, numpy=1.24, pandas=1.5, matplotlib=3.7 Environment file:
dependencies:
  - python=3.11
  - numpy=1.26
  - pandas=2.0
Result: python=3.11, numpy=1.26, pandas=2.0 (matplotlib removed)

Differences from conda env create

Featureconda env createconda env update
TargetCreates new environmentUpdates existing environment
Existing packagesN/APreserved by default
—prune flagN/ACan remove unlisted packages
Use caseInitial setupOngoing maintenance

Troubleshooting

Provide an explicit environment name:
conda env update -n myenv -f environment.yml
Or activate the environment first:
conda activate myenv
conda env update
If you get a frozen environment error:
conda env update --override-frozen
Only use this if you’re sure about modifying a frozen environment.
If packages conflict after update, try:
  1. Use --prune for a clean state:
conda env update --prune
  1. Or recreate the environment:
conda env remove -n myenv
conda env create -f environment.yml
Ensure the file exists:
ls -l environment.yml
conda env update -f ./environment.yml

Best Practices

Use Version Control

Keep environment.yml in version control to track changes and coordinate with team members.

Test Before Pruning

Test conda env update without --prune first to ensure the update works as expected.

Document Changes

Add comments to environment.yml explaining why packages are included or version-pinned.

Regular Updates

Periodically update environments to get security patches and bug fixes.