一、下載ohpm命令行工具
https://developer.harmonyos.com/cn/develop/deveco-studio#download_cli

image.png
二、安裝ohpm
1、下載后修改文件夾名稱放到/Users/xxx目錄下

image.png
2、打開(kāi)命令行工具cd到/Users/xx/Huawei/ohpm/bin
運(yùn)行如下命令:
cd /Users/xx/Huawei/ohpm/bin
./init
3、打開(kāi)終端配置環(huán)境變量
export OHPM_HOME=/Users/xx/Huawei/ohpm/bin
export PATH=${PATH}:${OHPM_HOME}/bin
4、配置.zshrc及.bash_profile
我看官網(wǎng)文檔教程沒(méi)有介紹這塊,導(dǎo)致全局根本引用不到ohpm
zsh:
1. touch ~/.zshrc
2. open ~/.zshrc
3. 把 export OHPM_HOME=/Users/xx/Huawei/ohpm
export PATH=${PATH}:${OHPM_HOME}/bin
粘貼進(jìn)去,保存即可
4. source ~/.zshrc

.zshrc
bash:
1. touch ~/.bash_profile
2. open ~/.bash_profile
3. 把 export OHPM_HOME=/Users/xx/Huawei/ohpm
export PATH=${PATH}:${OHPM_HOME}/bin
粘貼進(jìn)去,保存即可
4. source ~/.bash_profile

.bash_profile
4、全局運(yùn)行ohpm -v成功

image.png