---
schema_version: "1"
id: 66ab5963fac6d56207ee0fd64b20a8dcad7b502c23292187ba2d24b6d855e5ab
title: Customize Second-Generation Managed Package Installs and Uninstalls Using Scripts
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform-pkg-exchange/managed_packaging/guides/second-generation/sfdx-dev-dev2gp-customize-installs.md
canonical_url: https://developer.salesforce.com/docs/platform/pkg2-dev/guide/sfdx-dev-dev2gp-customize-installs.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 0a3c1c5fb15f85e5ef2cddec5ecf737f745813293db317a8096d48f3298b051b
products:
  - Second-Generation Managed Packaging Developer Guide
  - merged-docs
---

# Customize Second-Generation Managed Package Installs and Uninstalls Using Scripts

Customize a second-generation managed package (managed 2GP) install or upgrade by specifying an Apex post install script to run automatically after a subscriber installs or upgrades a managed 2GP package. You can also specify an Apex uninstall script to run automatically when a subscriber uninstalls a managed 2GP package.

For more information, see [Run Apex on Package Install/Upgrade](https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/apex_post_install_script.htm) and [Run Apex on Package Uninstall](https://developer.salesforce.com/docs/atlas.en-us.pkg1_dev.meta/pkg1_dev/apex_uninstall_script.htm).

Specify post install and uninstall scripts in the `sfdx-project.json` file.

```nolang
   "packageDirectories": [
      {
         "path": "expenser-schema",
         "default": true,
         "package": "Expense Schema",
         "versionName": ""ver 0.3.2"",
         "versionNumber": "0.3.2.NEXT",
         "postInstallScript": "PostInstallScript",
         "uninstallScript": "UninstallScript",
         "postInstallUrl": "https://expenser.com/post-install-instructions.html",
         "releaseNotesUrl": "https://expenser.com/winter-2020-release-notes.html"
        },
        ],
       {
         "namespace": "db_exp_manager",
         "sfdcLoginUrl": "https://login.salesforce.com",
         "sourceApiVersion": "47.0",
         "packageAliases": {
             "Expenser Schema": "0HoB00000004CzHKAU",
             "Expenser Schema@0.1.0-1": "04tB0000000719qIAA"
          }

```

You can also use the `--post-install-script` and the `--uninstall-script` Salesforce CLI parameters with the `sf package version create` command. The CLI parameters override the scripts specified in the `sfdx-project.json file`.

**note:** Include the Apex classes for your post-install and uninstall scripts with the metadata in your package.

You can designate an active Dev Hub org user to receive email notifications for Apex gacks, and install, upgrade, or uninstall failures associated with your packages. In Salesforce CLI run `sf package create --error-notification-username me@devhub.org` or `sf package update --error-notification-username me@devhub.org`. In Tooling API, use the PackageErrorUsername field on the Package2 object.
