Find and Install Packages
You can use the MATLAB® Package Manager to find and install packages from package repositories. This example shows how to find and 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 astronomy@2.1.0 package...Done.
Copying astrophysics@3.4.1 package...Done.
Copying physics@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 DirectlyInstalled
_______________ _______ ________ _________________
"astronomy" "2.1.0" false true
"astrophysics" "3.4.1" false false
"physics" "10.1.0" false false
"LinearAlgebra" "2.4.2" false false Package Resolution During Installation
When installing a package, the MATLAB Package Manager determines if a package matching the specified package 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 optionally specified version range.
The
ReleaseCompatibilityproperty 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 a required dependency conflicts with an already installed package, installation does
not proceed and a warning is thrown. If you call the mpminstall function
with the AllowVersionReplacement name-value argument specified as
true, then the required dependency version replaces the installed
version.
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 more information, 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 might 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
When you call the mpminstall function, part of the installation
process is package registration. After copying packages to the installation area,
MATLAB registers the packages and their dependencies. During package registration,
MATLAB adds the package root folder and all subfolders to the MATLAB path based on the
PathPosition name-value argument of the mpminstall
function. By default, MATLAB adds the package root folder and its subfolders to the end of
the MATLAB path. However, you can add the package root folder and its subfolders to the
beginning of the MATLAB path by specifying PathPosition as
"beginning".
See Also
Objects
Functions
mpmcreate|mpminstall|mpmuninstall|mpmsearch|mpmlist|mpmAddRepository|mpmListRepositories|mpmRemoveRepository