Ubuntu Local Repo Server Setup

From Notes_Wiki
Revision as of 05:29, 22 September 2025 by Hemanth (talk | contribs) (Created page with "= Ubuntu Local Repo Server Setup (Server = 172.30.14.59) = == Keep Downloaded Packages == By default, Ubuntu removes downloaded <code>.deb</code> files from <code>/var/cache/apt/archives/</code> after a successful install. To keep them permanently: <pre> sudo nano /etc/apt/apt.conf.d/02keep-debs </pre> Add the following line: <pre> APT::Keep-Downloaded-Packages "true"; </pre> Save and exit. Now all downloaded packages will stay in <code>/var/cache/apt/archives/<...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Ubuntu Local Repo Server Setup (Server = 172.30.14.59)

Keep Downloaded Packages

By default, Ubuntu removes downloaded .deb files from /var/cache/apt/archives/ after a successful install. To keep them permanently:

sudo nano /etc/apt/apt.conf.d/02keep-debs

Add the following line:

APT::Keep-Downloaded-Packages "true";

Save and exit. Now all downloaded packages will stay in /var/cache/apt/archives/.

Install Apache

sudo apt update
sudo apt install apache2 -y
sudo systemctl enable apache2
systemctl status apache2

Create Repository Directory

sudo mkdir -p /var/www/html/apt
sudo chmod -R 755 /var/www/html/apt

Copy Cached Packages

Move cached .deb files into the repository directory:

sudo cp /var/cache/apt/archives/*.deb /var/www/html/apt/

Generate APT Metadata

Install dpkg-dev:

sudo apt install dpkg-dev -y

Generate Packages.gz index:

cd /var/www/html/apt
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Now the repo contains:

  • .deb files
  • Packages.gz (index file)

Verify Apache

Check if the repository is served:

http://172.30.14.59/apt

Also confirm locally:

ls -lh /var/www/html/apt/Packages.gz

Configure Client

On the client machine, edit sources:

sudo nano /etc/apt/sources.list

Add:

deb [trusted=yes] http://172.30.14.59/apt ./

Remove conflicting files:

sudo rm -rf /etc/apt/sources.list.d/*.sources
sudo rm -rf /var/lib/apt/lists/

Test from Client

sudo apt-get clean
sudo apt-get update

Install Package from Repo

sudo apt-get install package-name