【Ubuntu22.04】repo安装方法

背景

repo是Google开发的用于基于git管理Android版本库的一个工具,管理多个Git仓库的工具,它可以帮助您在一个代码库中管理多个Git仓库的代码。其在鸿蒙操作系统中大量使用。下面我们就介绍repo在wsl中的安装部署。

安装方法

  1. 使用中国科技大学资源

脚本install_repo.sh:

bash 复制代码
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

脚本执行后重开终端。验证:

bash 复制代码
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
  1. 使用清华大学资源

脚本install_repo.sh:

bash 复制代码
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

脚本执行后重开终端。验证省略。

使用问题集锦

bash 复制代码
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

bash 复制代码
#!/bin/bash

# 查找repo路径
REPO_PATH=$(which repo)

if [ -z "$REPO_PATH" ]; then
    echo "错误:未找到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 ]; then
    echo "替换成功完成!"
else
    echo "替换过程中出现错误,已恢复备份"
    sudo mv "$BACKUP_PATH" "$REPO_PATH"
    exit 1
fi
相关推荐
林政硕(Cohen0415)7 个月前
Repo管理
git·嵌入式·repo
橘长_7 个月前
repo仓库转移到自己本地的git服务器
服务器·git·repo·正点原子
bob_young9 个月前
repo 命令大全详解(第十一篇 repo init)
repo
bob_young9 个月前
repo 命令大全详解(第十七篇 repo smartsync)
repo
江上清风山间明月10 个月前
repo 查看指定日期内,哪些仓库有修改,具体的修改详情
git·repo·记录·日期·修改·作者·详情
江上清风山间明月10 个月前
git标签、repo如何打tag
git·repo·标签·tag·打tag·打标签
Sean_woo19981 年前
【笔记】泰山派环境配置遇到E: Unable to locate package repo
笔记·repo·泰山派
江上清风山间明月1 年前
repo中的default.xml文件project name为什么一样?
repo·default.xml·project name·相同