Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of repositories 'apt-get' is checking? [closed]

Tags:

apt

People also ask

How can I see all apt repositories?

list file and all files under /etc/apt/sources. list. d/ directory. Alternatively, you can use apt-cache command to list all repositories.

How do you see repositories in Linux?

You can find software repository information in the /etc/apt/sources. list file on your Debian-based Linux installation. Although you can manually enter repository details in the file, it can quickly become a tiresome job. A better way of adding THEM to your system is by using the add-apt-repository tool.


It seems the closest is:

apt-cache policy

As far as I know, you can't ask apt for what their current sources are. However, you can do what you want using shell tools.

Getting a list of repositories:

grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* >> current.repos.list

Applying the list:

apt-add-repository << current.repos.list

Regarding getting the repository from a package (installed or available), this will do the trick:

apt-cache policy package_name | grep -m1 http | awk '{ print $2 " " $3 }'

However, that will show you the repository of the latest version available of that package, and you may have more repositories for the same package with older versions. Remove all the grep/awk stuff if you want to see the full list.


Try this:

cat /etc/apt/sources.list

It's not a format suitable for blindly copying to another machine, but users who wish to work out whether they've added a repository yet or not (like I did), you can just do:

sudo apt update

When apt is updating, it outputs a list of repositories it fetches. It seems obvious, but I've just realised what the GET URLs are that it spits out.

The following awk-based expression could be used to generate a sources.list file:

 cat /tmp/apt-update.txt | awk '/http/ { gsub("/", " ", $3); gsub("^\s\*$", "main", $3); printf("deb "); if($4 ~ "^[a-z0-9]$") printf("[arch=" $4 "] "); print($2 " " $3) }' | sort | uniq

Alternatively, as other answers suggest, you could just cat all the pre-existing sources like this:

cat /etc/apt/sources.list /etc/apt/sources.list.d/*

Since the disabled repositories are commented out with hash, this should work as intended.