Introduction and Installation Guide of ohpm-repo Private Repository in HarmonyOS Next

As a seasoned veteran in the field of HarmonyOS development for many years, today I'd like to share with you ohpm-repo, a very practical tool for setting up a private repository in HarmonyOS Next development. It's like a private treasure trove in our development process, bringing great convenience to project management. Concept and Application Scenarios of the ohpm-repo Private Repository Before we officially start, let's talk about why we need a private repository. During the development of HarmonyOS Next, we often use various third-party libraries, just like building a skyscraper requires many different types of building materials. Sometimes, these third-party libraries are developed internally by the company, containing some sensitive information or specific business logic, and are not suitable for public sharing. There are also some libraries that are publicly available, but during the usage process, we may have made some customized modifications to them, and these modified versions also need a secure place for storage and management. This is where the private repository comes in handy. ohpm-repo is such a lightweight tool specifically designed for HarmonyOS Next development to set up a private repository, and it is perfectly compatible with the ohpm package manager. Imagine that a team is developing a large HarmonyOS application, involving multiple modules and functions, and each module may rely on different third-party libraries. Without a unified private repository to manage these libraries, developers may use different versions of the libraries respectively, leading to compatibility issues in the project. However, ohpm-repo can cache all dependencies as needed, just like building a materials warehouse next to the project. Developers can pick up the required "materials" from it at any time, greatly accelerating the installation process in the private network, ensuring that the entire team uses the same version of the libraries, and improving development efficiency. In addition, in some development scenarios with high requirements for security and privacy, such as financial application development, the third-party libraries we use may contain sensitive encryption algorithms or user data processing logic. Through the private repository set up by ohpm-repo, we can strictly control the access permissions of these libraries, and only authorized developers can obtain and use them, ensuring the security of the project. Environment Preparation and Installation of ohpm-repo Installing Node.js ohpm-repo depends on Node.js to run. Therefore, before installing ohpm-repo, we need to prepare the Node.js environment first. Node.js is like the "running base" of ohpm-repo, providing the necessary running environment for it. ohpm-repo supports Node.js version 18.x and above. You can go to the official Node.js website and download the corresponding installation package according to your operating system for installation. During the installation process, remember to check the option to add it to the environment variables so that the system can find the relevant commands of Node.js in subsequent usage. Downloading the ohpm-repo Toolkit After installing Node.js, the next step is to download the ohpm-repo toolkit. We can find the latest ohpm-repo toolkit in the download center of the Huawei Developer Official Website. After downloading, don't forget to conduct integrity verification according to the toolkit integrity guidelines on the download center page. This step is as important as checking whether a newly purchased product is damaged, ensuring that the toolkit we downloaded is intact. Configuring Environment Variables After downloading the toolkit, we need to unzip it. After unzipping, we will see several directories such as bin, conf, and libs inside. At this time, we need to configure the path of the bin directory into the system environment variable path. This operation is a bit like marking an important location on a map, so that the system knows where to find the relevant commands of ohpm-repo. After the configuration is completed, open the terminal and execute the ohpm-repo -v command. If the version number (such as 2.0.0) can be output, it means that the installation package unzipping and environment variable configuration are both okay. If you encounter an error, don't panic. There are detailed solutions in the FAQ section of the documentation, and you can refer to them. It should be noted that for Linux and Mac systems, it is recommended to use bash or zsh as the command-line interface. If other types of shells are used, when writing the environment variable of the ohpm-repo deployment root directory deploy_root, it will be written into the .bashrc file by default. Verifying the Successful Installation and Basic Usage Verifying the Installation Previously, we executed the ohpm-repo -v command to preliminarily verify the correc

Mar 12, 2025 - 10:19
 0
Introduction and Installation Guide of ohpm-repo Private Repository in HarmonyOS Next

As a seasoned veteran in the field of HarmonyOS development for many years, today I'd like to share with you ohpm-repo, a very practical tool for setting up a private repository in HarmonyOS Next development. It's like a private treasure trove in our development process, bringing great convenience to project management.

Concept and Application Scenarios of the ohpm-repo Private Repository

Before we officially start, let's talk about why we need a private repository. During the development of HarmonyOS Next, we often use various third-party libraries, just like building a skyscraper requires many different types of building materials. Sometimes, these third-party libraries are developed internally by the company, containing some sensitive information or specific business logic, and are not suitable for public sharing. There are also some libraries that are publicly available, but during the usage process, we may have made some customized modifications to them, and these modified versions also need a secure place for storage and management. This is where the private repository comes in handy.

ohpm-repo is such a lightweight tool specifically designed for HarmonyOS Next development to set up a private repository, and it is perfectly compatible with the ohpm package manager. Imagine that a team is developing a large HarmonyOS application, involving multiple modules and functions, and each module may rely on different third-party libraries. Without a unified private repository to manage these libraries, developers may use different versions of the libraries respectively, leading to compatibility issues in the project. However, ohpm-repo can cache all dependencies as needed, just like building a materials warehouse next to the project. Developers can pick up the required "materials" from it at any time, greatly accelerating the installation process in the private network, ensuring that the entire team uses the same version of the libraries, and improving development efficiency.

In addition, in some development scenarios with high requirements for security and privacy, such as financial application development, the third-party libraries we use may contain sensitive encryption algorithms or user data processing logic. Through the private repository set up by ohpm-repo, we can strictly control the access permissions of these libraries, and only authorized developers can obtain and use them, ensuring the security of the project.

Environment Preparation and Installation of ohpm-repo

Installing Node.js

ohpm-repo depends on Node.js to run. Therefore, before installing ohpm-repo, we need to prepare the Node.js environment first. Node.js is like the "running base" of ohpm-repo, providing the necessary running environment for it. ohpm-repo supports Node.js version 18.x and above. You can go to the official Node.js website and download the corresponding installation package according to your operating system for installation. During the installation process, remember to check the option to add it to the environment variables so that the system can find the relevant commands of Node.js in subsequent usage.

Downloading the ohpm-repo Toolkit

After installing Node.js, the next step is to download the ohpm-repo toolkit. We can find the latest ohpm-repo toolkit in the download center of the Huawei Developer Official Website. After downloading, don't forget to conduct integrity verification according to the toolkit integrity guidelines on the download center page. This step is as important as checking whether a newly purchased product is damaged, ensuring that the toolkit we downloaded is intact.

Configuring Environment Variables

After downloading the toolkit, we need to unzip it. After unzipping, we will see several directories such as bin, conf, and libs inside. At this time, we need to configure the path of the bin directory into the system environment variable path. This operation is a bit like marking an important location on a map, so that the system knows where to find the relevant commands of ohpm-repo. After the configuration is completed, open the terminal and execute the ohpm-repo -v command. If the version number (such as 2.0.0) can be output, it means that the installation package unzipping and environment variable configuration are both okay. If you encounter an error, don't panic. There are detailed solutions in the FAQ section of the documentation, and you can refer to them.

It should be noted that for Linux and Mac systems, it is recommended to use bash or zsh as the command-line interface. If other types of shells are used, when writing the environment variable of the ohpm-repo deployment root directory deploy_root, it will be written into the .bashrc file by default.

Verifying the Successful Installation and Basic Usage

Verifying the Installation

Previously, we executed the ohpm-repo -v command to preliminarily verify the correctness of the installation package unzipping and environment variable configuration. But this is not enough, and we still need to further verify whether ohpm-repo can work properly.

Configuring config.yaml

Before starting ohpm-repo, we also need to make some configurations for it. Enter the conf directory of the ohpm-repo unzipped directory and open the config.yaml configuration file. The configuration items in it are like the "settings menu" of ohpm-repo, and various behaviors of it can be customized. For example, check the listen configuration. By default, it is localhost:8088, which means it only supports listening to the local address. If you want other machines to access it through the ip/domain name, you need to modify it to the ip of the machine where ohpm-repo is deployed, like this: listen: :8088.

There is also the deploy_root configuration. If it is not configured, the data will be stored in the default address, but this path cannot be the root directory where ohpm-repo is unzipped. In addition, the configurations of db and store are also very important. They are responsible for metadata storage and file storage respectively, and they cannot be randomly matched but must comply with the matching specifications stipulated in the documentation. For example, when db uses fileDB for local storage, store can only use local storage for local storage; when db uses the mysql database for storage, store can use local storage, sftp storage or custom storage custom plugin storage.

Starting ohpm-repo

After the configuration is completed, we can start ohpm-repo. Enter the bin directory under the unzipped directory of the ohpm-repo toolkit and execute the ohpm-repo start command. If the startup is successful, corresponding log information will appear, and a default administrator account will be created. However, this account needs to change the password when logging in for the first time. Remember to change the password and then log in again.

Up to here, we have completed the installation, configuration, and startup of ohpm-repo. In the subsequent development process of HarmonyOS Next, we can use this private repository to manage our third-party libraries, such as obtaining third-party libraries from the repository or publishing the third-party libraries we have developed to the repository. I hope that through this article, you can have a deeper understanding of ohpm-repo and make full use of it to improve development efficiency in development. If you have any questions during the usage process, you are welcome to communicate at any time.