Sub topic 9
Installing a Package Version into an Org
This chapter assumes you can run sf commands against a Dev Hub and an org, and that you have already created a package version. It covers how to install that version, what happens during the install, and the errors you are most likely to see.
What an install needs
Every package version has a subscriber package version ID that starts with 04t. The install command takes this ID, or an alias from packageAliases that maps to it. The target org must be able to accept the version. Two conditions apply.
- A beta version installs only into scratch orgs and sandboxes. A production org needs a released version.
- If the version has an installation key, you must supply it. Versions created with
--installation-key-bypassneed none.
Installing with the sf CLI
Use sf package install and name the version by alias or by ID.
sf package install --package "[email protected]" --target-org myOrg --wait 10 --no-promptUseful flags:
| Flag | Purpose |
|---|---|
| `--package` | Alias or `04t` ID of the version to install |
| `--target-org` | The org that receives the package |
| `--wait` | Minutes to wait before the command returns |
| `--installation-key` | Key for a protected version |
| `--security-type` | Who gets access: `AdminsOnly` or `AllUsers` |
| `--upgrade-type` | For unlocked packages: `Mixed` or `DeprecateOnly`, or `Delete` to remove components that the new version no longer contains |
Without --wait, the command starts the install and returns at once. You can then check progress with sf package install report --request-id <id>.
What happens during an install
The platform checks the request in order. It confirms that the version is installable in this org, then that every dependency is already present at an acceptable version. Only then does it deploy the components.
The diagram below shows the sequence.
If any step fails, nothing is installed. The install is all or nothing.
Installing dependencies first
A package that depends on another does not pull the other one in for you when you use sf package install. Install the dependency first, then the dependent package.
sf package install --package "[email protected]" --target-org myOrg --wait 10 --no-prompt
sf package install --package "Sales [email protected]" --target-org myOrg --wait 10 --no-promptThe installed Utils version must satisfy what Sales App asked for. If Sales App needs 1.1.0.LATEST and the org holds 1.0.0, the second command fails.
In a scratch org, sf project deploy start and the scratch org creation flow can resolve the dependencies in sfdx-project.json for you. For all other orgs, ordering the installs yourself is the safe approach. The next chapter covers ordering in more detail.
Checking what is installed
List the packages in an org to confirm versions before and after an install.
sf package installed list --target-org myOrgThe output shows each package's name, version number, and 04t ID. Compare it with your packageAliases entries when a dependency check fails.
Common failures
- Version not released. Installing a beta into production fails. Promote the version first with
sf package version promote. - Missing dependency. The error names the package or version that is absent. Install it, then retry.
- Dependency too old. The org holds a lower version than the dependent package requires. Upgrade the dependency first.
- Wrong or missing key. Supply the correct
--installation-key. - Timeout. The install may still be running. Check it with
sf package install reportbefore you retry.
Exercise
Sales App 2.0.0-1 requires Utils 1.1.0.LATEST. Your target sandbox has Utils 1.0.0-3 installed. You run sf package install --package "Sales [email protected]". What happens, and what do you do?
Show answer
The install fails during the dependency check, because the installed Utils version is lower than the 1.1.0 that Sales App requires. Install a Utils 1.1.0 version first, for example sf package install --package "[email protected]", then run the Sales App install again.