Newer Version Available

This content describes an older version of this product. View Latest

Install Packages with the CLI

If you’re working with the Salesforce CLI, you can use the force:package:install command to install packages in a scratch org or target subscriber org.

Before you install a package to a scratch org, run this command to list all the packages and locate the ID or package alias.

1sfdx force:package:version:list

Identify the version you want to install. Enter this command, supplying the package alias or package ID (starts with 04t).

1sfdx force:package:install --package "Expense Manager@1.2.0-12" --targetusername jdoe@example.com

If you’ve already set the scratch org with a default username, enter just the package version ID.

1sfdx force:package:install --package "Expense Manager@1.2.0-12"

If you’ve defined an alias (with the -a parameter), you can specify the alias instead of the username for --targetusername.

Note

The CLI displays status messages regarding the installation.

1Waiting for the subscriber package version install request to get processed. Status = InProgress Successfully installed the subscriber package version: 04txx0000000FIuAAM.

Control Package Installation Timeouts

When you issue a force:package:install command, it takes a few minutes for a package version to become available in the target org and for installation to complete. To allow sufficient time for a successful install, use these parameters that represent mutually exclusive timers.

  • --publishwait defines the maximum number of minutes that the command waits for the package version to be available in the target org. The default is 0. If the package is not available in the target org in this time frame, the install is terminated.

    Setting --publishwait is useful when you create a new package version and then immediately try to install it to target orgs.

    If --publishwait is set to 0, the package installation immediately fails, unless the package version is already available in the target org.

    Note

  • --wait defines the maximum number of minutes that the command waits for the installation to complete after the package is available. The default is 0. When the --waitinterval ends, the install command completes, but the installation continues until it either fails or succeeds. You can poll the status of the installation using sfdx force:package:install:report.

    The --wait timer takes effect after the time specified by --publishwait has elapsed. If the --publishwait interval times out before the package is available in the target org, the --wait interval never starts.

    Note

For example, consider a package called Expense Manager that takes five minutes to become available on the target org, and 11 minutes to install. The following command has publishwait set to three minutes and wait set to 10 minutes. Because Expense Manager requires more time than the set publishwait interval, the installation is aborted at the end of the three minute publishwait interval.
1sfdx force:package:install --package "Expense Manager@1.2.0-12" --publishwait 3 --wait 10
The following command has publishwait set to six minutes and wait set to 10 minutes. If not already available, Expense Manager takes five minutes to become available on the target org. The clock then starts ticking for the 10 minute wait time. At the end of 10 minutes, the command completes because the wait time interval has elapsed, although the installation is not yet complete. At this point, package:install:report indicates that the installation is in progress. After one more minute, the installation completes and package:install:report indicates a successful installation.
1sfdx force:package:install --package "Expense Manager@1.2.0-12" --publishwait 6 --wait 10