Installs a third-party library.
ohpm install [options] [[<@group>/]<pkg>[@<version> | @tag:<tag>]] ... ohpm install [options] <folder> ohpm install [options] <har file> alias: i
This command is used to install a specified component or all dependencies in the oh-package.json5 file. If the oh-package-lock.json5 file exists, the installation depends on the version specified in the oh-package-lock.json5 file.
ohpm install
Installs dependencies to the local oh_modules folder and writes all dependencies to the oh-package.json5 file.
ohpm install <folder>
Installs a local folder. By default, a symbolic link pointing to the folder is created.
Example:
ohpm install ../folder
ohpm install <har file>
Installs a compressed package. Pay attention to the following requirements:
Example:
ohpm install ./package.har
You can either omit parameters or append the --all or --install_all parameter to the ohpm install command to install all dependencies configured in the oh-package.json5 file for all modules in your project.
In ohpm 26.0.0.630 and later versions, if installation is not required, append --no-install_all to the command.
You can append the --save-dynamic parameter to the ohpm install command to write information about the installed third-party library to dynamicDependencies in the oh-package.json5 file.
You can append the --save-dev parameter to the ohpm install command to write information about the installed third-party library to devDependencies in the oh-package.json5 file.
You can append the --save-prod parameter to the ohpm install command to write information about the installed third-party library to dependencies in the oh-package.json5 file. This is the default behavior of ohpm.
You can append the --no-save parameter to the ohpm install command to not write information about the installed third-party library to the oh-package.json5 file. If no parameter is appended, information about the installed third-party library will be written to the oh-package.json5 file.
You can append the --prefix <string> parameter to the ohpm install command to specify the root directory of the package. The root directory must contain the oh-package.json5 file.
You can append the --pf <string> or --parameterFile <string> parameter to the ohpm install command to specify the path to the parameterization configuration file. Before running this command, ensure that parameterFile is configured in the project-level oh-package.json5 file.
You can append the --registry <registry> parameter to the ohpm install command to specify a repository address. If the repository address is not specified, the repository address is obtained from the configuration by default.
You can append the --ft <number> or --fetch_timeout <number> parameter to the ohpm install command to set the operation timeout. If the parameter is not set, the default timeout is 60000 ms.
If no parameter is appended to the ohpm install command, or the --strict_ssl or --strict_ssl true parameter is appended, HTTPS certificate verification is enabled.
In ohpm 26.0.0.630 and later versions, to disable verification, append --no-strict_ssl (recommended) or --strict_ssl false to the command.
You can append the --mc <number> or --max_concurrent <number> parameter to the ohpm install command to set the maximum number of concurrent requests (the maximum number of network requests at any time during the ohpm operation). If the parameter is not set, the default value 50 is used.
You can append the --rt <number> or --retry_times <number> parameter to the ohpm install command to set the maximum number of retry times for an operation. If the parameter is not set, the default value 1 is used.
You can append the --ri <number> or --retry_interval <number> parameter to the ohpm install command to set the retry interval. If the parameter is not set, the default value 1000 (in ms) is used.
You can append the --experimental-concurrently-safe parameter to the ohpm install command to install dependencies concurrently and securely. This is an experimental option.
You can append the --target_path <string> parameter to the ohpm install command to specify the path of the dependency configuration file (oh-package.json5) of each module in the context of a specific target product. When you run the ohpm install command, ohpm installs the dependencies in the <target_path>/<moduleName>/oh-package.json5 file first. For details, see target_path.
In ohpm 6.0.2.636 and later versions, you can append the --log_level <string> parameter to the ohpm install command to specify the log level (info, debug, warn, or error) for execution of the current command. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.
In ohpm 6.0.2.636 and later versions, you can append the --debug parameter to the command to set the log level to debug for execution of the current command. This configuration takes effect only on the current command line and does not alter the log level configured in the .ohpmrc file. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.
In ohpm 6.0.2.636 and later versions, you can append the --lockfile_stable_order parameter to the ohpm install command. This ensures that if the oh-package.json5 file is not changed, the fields in the generated oh-package-lock.json5 file remain unchanged.
In ohpm 6.0.2.636 and later versions, you can append the --odm_r2_project_root parameter to the ohpm install command. If the overrideDependencyMap configuration exists and the target configuration file contains dependencies configured with relative paths, ohpm will resolve and locate these relative paths based on the project root path. For details, see odm_r2_project_root.
In ohpm 6.0.2.636 and later versions, you can append the --enable_cross_process_lock parameter to the ohpm install command. Due to restrictions of the oh_modules directory structure, ohpm does not support the parallel execution of multiple ohpm install, ohpm update, or ohpm uninstall commands within the same project. To execute these commands in parallel for a project, set this parameter to true to have them run sequentially.
In ohpm 6.0.2.636 and later versions, you can append the --resolve_conflict_strict parameter to the ohpm install command to enable the strict mode for handling dependency version conflicts. For details, see resolve_conflict_strict.
In ohpm 6.0.2.636 and later versions, you can either omit parameters or append the --resolve_conflict parameter to the ohpm install command to have ohpm automatically resolve dependency version conflicts. For details, see resolve_conflict.
In ohpm 26.0.0.630 and later versions, if automatic conflict resolution is not required, append --no-resolve_conflict to the command.
In ohpm 6.0.2.636 and later versions, you can append the --cache <string> parameter to the ohpm install command to specify the cache path.
In ohpm 26.0.0.410 and later versions, you can append the --auto_skip_install parameter to the ohpm install command to specify whether to skip the installation. For details, see auto_skip_install.
In ohpm 26.0.0.410 and later versions, you can add the --metadata_cache parameter to the ohpm install command to set whether to read the cache metadata in the oh-install-meta.json5 file and the metadata cache file in the ~/.ohpm/cache/metadata directory. For details, see metadata_cache.
In ohpm 26.0.0.630 and later versions, you can append the --symlink_for_local_dep parameter to the ohpm install command to create symbolic links for the paths to the decompressed local HAR dependencies. For details, see symlink_for_local_dep.
Run the following command to install Lottie:
ohpm install @ohos/lottie
Below is an output example:

During the execution of ohpm install, the dependencies of each module in the project are all installed in oh_modules in the module-specific root directory. All direct and indirect dependencies of the module are stored in tile mode in .ohpm in the oh_modules directory, and direct dependencies are added to the root directory of oh_modules as a symbolic link. Therefore, the same dependency is installed only once, reducing disk space usage and accelerating installation.
From ohpm client 1.4.0, the dependencies of every module in the project are all installed in oh_modules in the root directory of the project. In addition, symbolic links of the direct dependencies of a module are generated in oh_modules in the module-specific root directory. These symbolic links point to the actual storage directories in .ohpm of oh_modules in the root directory of the project.
To support customized dependencies for different build targets during the build process, Hvigor automatically generates tailored dependency configuration files (oh-package.json5) for each module based on the target build product. You can use the target_path option with the ohpm install command to specify the path for the dependency configuration files (oh-package.json5) of each module within the context of a specific target product.
ohpm gives precedence to the dependencies specified in <target_path>/moduleName/oh-package.json5. It generates a lock file named oh-package-<targetName>-lock.json5 in the <project_root>/moduleName/ directory. When target_path is specified, the automatic handling of dependency version conflicts is enabled by default. After the dependencies are installed, ohpm will create new oh-package.json5 files in the <target_path>/resolve-conflict/moduleName/ directory.
The following is an example of the target_path directory structure:
+---default // <targetName> defaults to default. | | dependencyMap.json5 // Path of the dependency configuration file of each module in a specific target context. | +---module1 // Directory for storing the dependency configuration file of a module in a specific target context. The directory name is the same as the root directory of the original module. | | oh-package.json5 // Configuration file on which a module depends in a specific target context. | +---module2 | | oh-package.json5 | | oh-package.json5 // Project-level dependency configuration file generated in a specific target context.
The following is an example of the dependencyMap.json5 file:
{
targetName: "default",
rootDependency: "./oh-package.json5",
dependencyMap: {
"module1": "./module1/oh-package.json5",
"module2": "./module2/oh-package.json5"
}
} When the ohpm install command is used with a specified target_path, the priority of dependency configurations is determined by a specific hierarchy, as follows:
1. The oh-package.json5 configured in rootDependency under <target_path>/dependencyMap.json5 takes precedence over the oh-package.json5 at the project root, that is, <project_root>/oh-package.json5.
2. The configurations specified in the project-level configuration file pointed to by projectPackageJson in the .ohpmrc file, particularly the overrides and overrideDependencyMap, have a higher priority than: (1) the corresponding configurations in the oh-package.json5 as configured by rootDependency in <target_path>/dependencyMap.json5; (2) the corresponding configurations in <project_root>/oh-package.json5.
3. <target_path>/moduleName/oh-package.json5 has a higher priority than the dependency configuration files specified in overrideDependencyMap.
4. The dependency versions specified in overrides have the higher priority than the dependency versions specified in <target_path>/moduleName/oh-package.json5.
Only if targetName in <target_path>/dependencyMap.json5 is non-empty and not equal to 'default', will the generated lock file name in <project_root>/moduleName be changed to oh-package-targetName-lock.json5.