在Debian上创建自己的apt源

发布时间 2023-09-19 11:12:39作者: smile-you-me

introduction

rambo@debian:~$ cat /etc/issue
Debian GNU/Linux 12 \n \l

rambo@debian:~$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       723Mi        14Gi       4.6Mi       368Mi        14Gi
Swap:          975Mi          0B       975Mi

rambo@debian:~$ df -h | grep -v tmpfs
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
/dev/sda1        15G  5.5G  8.6G  39% /
/dev/sda8        57G   37M   54G   1% /home
/dev/sda7       964M   72K  898M   1% /tmp
/dev/sda5       5.2G  382M  4.6G   8% /var


Installing Required Package

on Debian-based systems, all repositories are managed by the APT utilities (apt, apt-get, apt-cache, etc). The dpkg-dev package is needed for local repository creation compatible with APT.

First Update the system packages:
sudo apt -y update && sudo apt -y upgrade

install the dpkg-dev package:
sudo apt install -y dpkg-dev

Create a Directory for Local Repository

# create a directory to keep binary packages
sudo mkdir -p /opt/local/debs && cd /opt/local/debs

Adding Packages to Local Repo Directory

sudo wget https://down.qq.com/qqweb/LinuxQQ/linuxqq_2.0.0-b2-1089_amd64.deb
 
Tips: You can copy or download as many packages as you like in this step.

# view .deb package
dpkg-deb -c linuxqq_2.0.0-b2-1089_amd64.deb

Create the Required Repository Package Meta for APT

sudo vim /etc/ssh/sshd_config
PermitRootLogin yes


systemctl restart sshd
sudo passwd root
su -
cd /opt/local

# create a Release file
dpkg-scanpackages . /dev/null > Release

# You should get a similar output depending on how many packages you have added to the local repository:
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning:   linuxqq
dpkg-scanpackages: info: Wrote 1 entries to output Packages file.


root@debian:/opt/local# ls
debs  Release


# next, scan all the deb files in the directory and create an appropriate Packages.gz file
root@debian:/opt/local# dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

# Output:
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning:   linuxqq
dpkg-scanpackages: info: Wrote 1 entries to output Packages file.

# Note that you must run these commands every time you add new deb packages to your local repository directory. You could also create a simple bash script and run it whenever you add new packages.

Adding Our Local Repository to Sources.list

root@debian:/opt/local# vim /etc/apt/sources.list
deb [trusted=yes] file:/opt/local/   ./

Verification

sudo apt -y update
sudo apt install -y linuxqq

# remove installed packages 
sudo apt remove linuxqq