Main Content

Find and Install Packages

You can use the MATLAB® Package Manager to find and install packages. This example shows how to find an install a package with tools related to astronomy.

Find Package

You can search for packages in the list of known repositories by using the mpmsearch function. (To learn more about how to add a repository to this list, see Distribute Packages Using Folder-Based Repositories.)

For example, find packages that might be related to astronomy by searching with the keyword "astro".

mpmsearch("astro")
           Name            Version    Summary
    ___________________    _______    _______

    "astrology"            "1.2.4"      "Predict astrological sign based on date"   
    "astronomy"            "2.1.0"      "An astronomy toolbox"   
    "astrophysics"         "3.4.1"      "A set of functions for astrophysical calculations"   
    "FastRotationModel"    "1.0.0"      "A model of rotational systems"   

Install Package

Once you find the package you want, you can install it using the mpminstall function. The function displays a confirmation prompt before installing the package.

For example, after identifying the astronomy package in the search results as the package you want, install it.

mpminstall("astronomy")
The following packages will be installed:
    astronomy@2.1.0
        astrophysics@3.4.1
        physics@10.1.0
        LinearAlgebra@2.4.2

Do you want to continue? [YES/no]:

The prompt lists more than one package to be installed because the astronomy package depends on three additional packages: astrophysics, physics, and LinearAlgebra. Respond YES to the prompt to confirm the installation of astronomy and its required dependencies.

Copying physics@2.1.0 package...Done.
Copying astrophysics@3.4.1 package...Done.
Copying astronomy@10.1.0 package...Done.
Copying LinearAlgebra@2.4.2 package...Done.

Successfully added the following packages to the path:
    astronomy  (help)
    physics  (help)
    astrophysics  (help)
    LinearAlgebra  (help)

Installation complete.

Then display the currently installed packages by using the mpmlist function.

mpmlist
         Name          Version    Editable    InstalledAsDependency
    _______________    _______    ________    _____________________

    "astronomy"        "2.1.0"     false              false        
    "astrophysics"     "3.4.1"     false              true         
    "LinearAlgebra"    "10.1.0"    false              true         
    "physics"          "2.4.2"     false              true  

Package Resolution During Installation

When installing a package, the MATLAB Package Manager determines if a package matching the specified package ID and a version in the specified version range is already installed or on the list of packages to be installed. If not, then MATLAB searches the known repositories for available packages that meet all the following conditions:

  • The package identifier matches the specified package name or ID. Package names are matched case-insensitively.

  • The version is compatible with the specified version range.

  • The ReleaseCompatibility property value is compatible with the MATLAB release being used.

MATLAB searches each repository on the known repository list in order. If a repository has multiple packages that meet these conditions, then MATLAB selects the package with the latest semantic version. Once a package that meets the conditions has been found, other repositories on the list of known repositories are not searched.

When installing a package, MATLAB determines required dependencies to install as well.

For each required dependency, MATLAB determines if a package matching the dependency package ID and a version compatible with the package version range is already installed or on the install list. If so, MATLAB skips the dependency and advances to the next required dependency. If not, MATLAB searches the known repositories for the dependency package following the same process as for the original package.

If installed dependencies have their own dependencies, MATLAB follows the same process recursively until it finds and installs all required packages.

Package Installation Location

Once the MATLAB Package Manager has identified all the packages to install, MATLAB copies the files from the source to the installation area. The default installation area is the same as the add-ons installation folder. For additional information and see Default Add-On Installation Folder.

During package installation, MATLAB creates a folder in the installation area named for the package name, version, and ID. The folder name can be truncated or modified to comply with the naming conventions of the local file system.

If the package source is a folder and the package InPlace property is true, then MATLAB does not copy the package.

Package Registration and the MATLAB Path

After copying packages to the installation area, MATLAB registers the packages and their dependencies and adds the package root folder and all subfolders to the MATLAB path. During package registration, MATLAB adds the package root folder and all subfolders to the MATLAB path based on the PathPosition property.

See Also

Objects

Functions

Related Topics