【Ubuntu22.04】repo安装方法
背景
repo是Google开发的用于基于git管理Android版本库的一个工具,管理多个Git仓库的工具,它可以帮助您在一个代码库中管理多个Git仓库的代码。其在鸿蒙操作系统中大量使用。下面我们就介绍repo在wsl中的安装部署。
安装方法
- 使用中国科技大学资源
脚本install_repo.sh:
mkdir -p ~/.bin/repo
git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo ~/.bin/repo
chmod +x ~/.bin/repo/repo
echo 'export PATH=~/.bin/repo:$PATH' >> /root/.bashrc
source ~/.bashrc
脚本执行后重开终端。验证:
root@DESKTOP-UKR8O1E:~# repo --version
<repo not installed>
repo launcher version 2.54(from /root/.bin/repo/repo)
git 2.34.1
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0]
OS Linux 5.10.16.3-microsoft-standard-WSL2 (#1 SMP Fri Apr 2 22:23:49 UTC 2021)
CPU x86_64 (x86_64)
Bug reports: https://issues.gerritcodereview.com/issues/new?component=1370071
- 使用清华大学资源
脚本install_repo.sh:
mkdir -p ~/.bin/repo
git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo ~/.bin/repo
chmod +x ~/.bin/repo/repo
echo 'export PATH=~/.bin/repo:$PATH' >> /root/.bashrc
source ~/.bashrc
脚本执行后重开终端。验证省略。
使用问题集锦
- repo init 提示“fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle“
root@DESKTOP-R500S71:/home/work# repo init -u https://gitee.com/ark-standalone-build/manifest.git -b master
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 110] Connection timed out
fatal: cloning the git-repo repository failed, will remove '.repo/repo'
原因:国内网络限制,无法访问https://gerrit.googlesource.com/git-repo/clone.bundle
解决方法:
替换脚本replace_repo_url.sh,替换REPO_URL 内容为:https://mirrors.tuna.tsinghua.edu.cn/git/git-rep
#!/bin/bash# 查找repo路径
REPO_PATH=$(which repo)if [ -z "$REPO_PATH" ]; thenecho "错误:未找到repo命令"exit 1
fi# 备份原始文件
BACKUP_PATH="${REPO_PATH}.bak"
echo "备份原始文件到 ${BACKUP_PATH}..."
sudo cp "$REPO_PATH" "$BACKUP_PATH"# 执行替换操作
echo "执行URL替换..."
sudo sed -i 's|https://gerrit.googlesource.com/git-repo|https://mirrors.tuna.tsinghua.edu.cn/git/git-repo|g' "$REPO_PATH"if [ $? -eq 0 ]; thenecho "替换成功完成!"
elseecho "替换过程中出现错误,已恢复备份"sudo mv "$BACKUP_PATH" "$REPO_PATH"exit 1
fi