Skip to main content

dfx

Reference

When invoked as dfx, dfxvm determines which version of dfx to use and dispatches execution to it.

dfx version determination

dfxvm determines which version of dfx to use by checking these criteria in order:

  1. +<version> parameter from command line
  2. DFX_VERSION environment variable
  3. dfx in the current project's dfx.json
  4. default_version in $HOME/.config/dfx/version-manager.json

Command Line

You can specify the version of dfx to use on the command line by passing +<version> as the first parameter. For example, the following will deploy using dfx 0.15.0:

dfx +0.15.0 deploy

DFX_VERSION environment variable

You can specify the version of dfx to use by setting the DFX_VERSION environment variable. For example, the following will start the replica using dfx 0.15.0:

DFX_VERSION=0.15.0 dfx start --clean --background

dfx field in the current project's dfx.json

If running dfxvm as dfx in a dfx project, and the project's dfx.json contains a top-level field "dfx", then dfxvm will use the version specified in that field.

Like dfx, dfxvm looks for dfx.json in the current directory and then in parent directories until it finds one or reaches the root directory.

For example:

{
"dfx": "0.14.4",
"canisters": { }
}

If the above dfx.json were in the current directory or any parent directory, then any dfx command would use dfx 0.14.4.

default_version in $HOME/.config/dfx/version-manager.json

If none of the above criteria are met, then dfxvm will use the version specified in $HOME/.config/dfx/version-manager.json. For example:

{
"default_version": "0.15.0"
}

To configure the default dfx version, use the dfxvm default command:

dfxvm default 0.15.1

Environment Variables

When proxying to dfx, dfxvm alters the environment in two ways:

  • Sets DFX_VERSION to the version of dfx being used.
  • Prepends the bin directory for the dfx version to PATH.