Contenido principal

Find and Distribute Code Using MATLAB Package Manager

The MATLAB® Package Manager provides a streamlined system for distributing code and includes robust dependency management. The system is composed of a set of objects and functions for creating, finding, installing, and managing MATLAB packages and their dependencies. After creating a package, you can distribute it to your end users by adding it to a package repository. End users can then find and install packages shared to repositories.

If you instead want to install MATLAB, Simulink®, or other MathWorks® products or support packages, see Install Support Packages Noninteractively.

Why Use Packages?

The MATLAB Package Manager provides a streamlined system for distributing code. Once your code is ready for distribution , you can package and upload it to a package repository. Users can search for and install packages from these package repositories. It also provides robust dependency management, so when you download a package from a repository, any required dependencies are downloaded as well. For information on making code available as a package, see Turn Your Code Into a Package.

What Is a Package?

A package is a collection of MATLAB code, related files, and a package definition file that defines the package identity and dependencies. The purpose of a package is to compartmentalize code so that it can be shared while maintaining its intended functionality. For information on making your code available as a package, see Turn Your Code Into a Package.

A package containing code and other files

A package consists of a root folder that contains the files and member folders of the package. The root folder also contains a resources folder, which contains the package definition file named mpackage.json.

The package definition file contains identifying information, descriptive information, and package properties. Identifying information can include the package name, version, and unique identifier. Descriptive information can include a summary of the package purpose, its provider, and the MATLAB release compatibility. The properties of a package can include its status, member folders, and any dependencies.

When installing a package, the MATLAB Package Manager installs all of the code, supporting files, and any other packages that it depends on. The MATLAB Package Manager also adds the root folder and all member folders to the path. For information on finding and installing packages, see Find and Install Packages.

Automatic Package Dependency Management

Some packages use code that is contained in a second package. These packages depend on the second package, and the second package is referred to as a dependency. As part of its robust dependency management, when the MATLAB Package Manager installs a package, it checks that all required dependencies are also installed. In this diagram, package A depends on package B, and package B depends on packages C and D. When the MATLAB Package Manager installs package A, it also installs packages B, C, and D if they are not already installed.

Package dependencies. Package A depends on package B. Package B depends on packages C and D

When uninstalling a package, the MATLAB Package Manager checks each of the package dependencies and uninstalls them if they are unused. A dependency is considered unused if it was not installed directly and no installed packages depend on it.

Find and Share Packages in Repositories

You can add packages that are ready for distribution to a repository, and end users can search for and install packages from the repository. A package repository is a designated location where packages are available for distribution. MATLAB keeps a list of known repositories. When you search for a package using mpmsearch or install a package using mpminstall, the MATLAB Package Manager finds packages in known repositories.

Installing a package from a package repository

View the current list of known repositories using mpmListRepositories. Add and remove repositories from the list of known repositories using mpmAddRepository and mpmRemoveRepository. For more information, see Distribute Packages Using Folder-Based Repositories.

See Also

Objects

Functions

Topics