Ubuntu: repository/PPA 源管理(查询、添加、修改、删除)

查询

在Ubuntu中,每个PPA源是单独存放在/etc/apt/sources.list.d/文件夹中的,进入到该文件夹,使用ls命令查询即可列出当前系统添加的PPA源。

或者使用grep显示所有:

grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*

或者

grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/

#或者
#grep -r --include '*.list' '^deb ' /etc/apt/sources.list*

添加

sudo add-apt-repository ppa:ownername/projectname
sudo apt update
sudo apt install something

注意,添加了PPA源时,记得update一下,不然在install的时候会出现找不到安装包的情况。

批量添加的话,用 installppa.sh:

#! /bin/sh 
# listppa Script to get all the PPA installed on a system ready to share for reininstall
for APT in `find /etc/apt/ -name \*.list`; do
    grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" $APT | while read ENTRY ; do
        USER=`echo $ENTRY | cut -d/ -f4`
        PPA=`echo $ENTRY | cut -d/ -f5`
        echo sudo apt-add-repository ppa:$USER/$PPA
    done
done

When you call it with listppa > installppa.sh you get a script you can copy on a new machine to reinstall all PPA.

Next stop: do that for the other repositories:

#! /bin/sh
# Script to get all the PPA installed on a system
for APT in `find /etc/apt/ -name \*.list`; do
    grep -Po "(?<=^deb\s).*?(?=#|$)" $APT | while read ENTRY ; do
        HOST=`echo $ENTRY | cut -d/ -f3`
        USER=`echo $ENTRY | cut -d/ -f4`
        PPA=`echo $ENTRY | cut -d/ -f5`
        #echo sudo apt-add-repository ppa:$USER/$PPA
        if [ "ppa.launchpad.net" = "$HOST" ]; then
            echo sudo apt-add-repository ppa:$USER/$PPA
        else
            echo sudo apt-add-repository \'${ENTRY}\'
        fi
    done
done

修改

用文本编辑器修改/etc/apt/sources.list.d/文件夹下的文件内容即可。

删除

使用sudo rm命令删除/etc/apt/sources.listd/文件夹中指定的PPA源文件即可。

或者使用命令:

sudo add-apt-repository --remove ppa:whatever/ppa

更安全的方式是通过ppa-purge的方式

# 首先安装 ppa-purge
sudo apt-get install ppa-purge

# 删除ppa
sudo ppa-purge ppa:whatever/ppa

#或者
sudo apt-get purge package_name

 

 

 

本文:Ubuntu: repository/PPA 源管理(查询、添加、修改、删除)

Leave a Reply