当前位置 博文首页 > 码农之家:【Linux】【开发环境】【RHEL】开发环境搭建系列之五

    码农之家:【Linux】【开发环境】【RHEL】开发环境搭建系列之五

    作者:[db:作者] 时间:2021-07-30 18:01

    git-repo简介

    • git-repo简称Repo,是google为了方便管理多个git库而开发的Python脚本;
    • repo本身依赖git(建议1.9以上)和python(3.5以上版本);
    • 实际在Android开发或高通芯片sdk开发中,经常使用这种机制来下载源代码。

    安装过程

    下载repo

    [qxhgd@localhost git-repo]$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 43050  100 43050    0     0   7213      0  0:00:05  0:00:05 --:--:-- 12471
    

    增加x权限

    [qxhgd@localhost git-repo]$ chmod +x repo
    

    修改repo更新自己的git源

    [qxhgd@localhost git-repo]$ vi ~/.bashrc
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    [qxhgd@localhost git-repo]$ source ~/.bashrc
    

    也可以加入到~/.profile文件中,效果一样。
    不修改该环境变量,则需要FQ。

    安装python3.8.0

    从源码安装python的时候,需要额外安装或替换zlib、ssl等几个库。
    具体看后面的详细命令。
    一定要安装openssl、openssl-devel两个库。

    使用git-repo下载代码

    [qxhgd@localhost repo]$ sudo repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b cm-14.1 --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
    [qxhgd@localhost repo]$ repo sync
    

    在实际的工作当中,上述命令的具体格式和参数都是由提供产品或服务的厂商提供的。

    命令汇总

    ## 1、repo环境安装
    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
    vi ~/.bashrc 
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    source ~/.bashrc
    
    ## 2、repo下载git代码库
    repo init #初始化库
    repo sycn #下代码包
    
    ## 3、python卸载(卸载有风险)
    yum remove python #yum卸载python
    rpm -qa | grep python|xargs rpm -ev --allmatches --nodeps  ##强制删除已安装程序及其关联
    whereis python | xargs rm -frv #删除所有残余文件
    whereis python #确认下
    
    ## 4、python源码安装,如安装python3.8为例:
    yum install openssl       #后续git repo依赖于ssl库,非常重要
    yum install openssl-devel #后续git repo依赖于ssl库,非常重要 
    # 以上两条可避免repo init的时候,报“fatal: error unknown url type: https repo”这个错误
    
    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz #下tar包
    tar -zxvf Python-3.8.0.tgz #解压
    ./configure --with-zlib --with-ssl #配置
    make #编译
    make install #安装
    ln -sf /usr/bin/python3 /usr/local/bin/python3 #建软链接
    

    注意事项

    虽然git-repo要求python版本不低于3.5,但yum默认的python版本为2.7.5,所以升级python版本容易出问题。
    如果yum和repo并存,则需要两个版本的python并存,具体由:

    /usr/bin/yum
    /usr/bin/repo
    

    两个脚本中的首行“#!/usr/bin/python”来选择使用的python版本。

    常用git-repo库镜像及repo命令说明

    清华镜像
    码云
    google原装(需要FQ)
    repo命令参考

    如本文对你有些许帮助,欢迎打赏:
    支付宝打赏链接

    cs