In this guide, you will learn, how to create a local APT repository on your Ubuntu 20.04 LTS operating system.
Table of Contents:
- What is APT?
- Environment Specification
- Updating List of Available APT Packages
- Installing DPKG-DEV Package on Ubuntu 20.04 LTS
- Installing Apache Web Server on Ubuntu 20.4 LTS
- Configure Ubuntu Firewall
- Create APT Repository Directory
- Write Script to Update Package.gz File
- Add Your APT Repository in Ubuntu Sources.list
- Conclusion
What is APT? :
Advanced Package Tool, or APT, is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian, Ubuntu, and related Linux distributions.
In Ubuntu Linux, APT repository is the primary source of installing stable and supported software packages on your Operating System.
Online APT repositories are available free of cost specific to different versions of Ubuntu and related distributions.
However, there are situations, where we do not have access to Internet or our Ubuntu machines are not connected to Internet due to some security reasons.
In such cases, you can setup your own local APT repository and use it to install software packages on your Ubuntu machines.
Environment Specification:
We are using a minimal Ubuntu 20.04 LTS virtual machine with following specifications.
- CPU - 3.4 Ghz (2 cores)
- Memory - 2 GB
- Storage - 20 GB
- Operating System - Ubuntu Server 20.04 LTS
- Hostname – local-apt-repo.centlinux.com
- IP Address - 192.168.116.239 /24
Updating List of Available APT Packages:
Update APT packages list by executing following command at Linux shell.
ahmer@local-apt-repo:~$ sudo apt-get update
Installing DPKG-DEV Package on Ubuntu 20.04 LTS:
You are required to install dpkg-dev package, to create the packages meta data for your local APT repository.
ahmer@local-apt-repo:~$ sudo apt-get install -y dpkg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9
fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1
libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0
libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev
libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev
libtsan0 libubsan1 linux-libc-dev make manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib
g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison
gdb gcc-doc gcc-9-multilib glibc-doc bzr libstdc++-9-doc make-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9
dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1
libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0
libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev
libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev
libtsan0 libubsan1 linux-libc-dev make manpages-dev
0 upgraded, 41 newly installed, 0 to remove and 23 not upgraded.
Need to get 40.0 MB of archives.
After this operation, 175 MB of additional disk space will be used.
...Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Installing Apache Web Server on Ubuntu 20.4 LTS:
If you are planning to configure your local APT repository for use by other Ubuntu 20.04 LTS machines on your network. Then you should install Apache web server to host your APT repository.
ahmer@local-apt-repo:~$ sudo apt-get install -y apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert
0 upgraded, 11 newly installed, 0 to remove and 45 not upgraded.
Need to get 1,865 kB of archives.
After this operation, 8,080 kB of additional disk space will be used.
...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Configure Ubuntu Firewall:
Allow Apache service port in Linux firewall by executing ufw command.
ahmer@local-apt-repo:~$ sudo ufw allow http
Rules updated
Rules updated (v6)
Create APT Repository Directory:
Create a directory 'repo' within Apache document root, to host your local APT repository.
ahmer@local-apt-repo:~$ sudo mkdir /var/www/html/repo
Mount the Ubuntu DVD at /mnt/cdrom.
ahmer@local-apt-repo:~$ sudo mkdir /mnt/cdrom ahmer@local-apt-repo:~$ sudo mount /dev/cdrom /mnt/cdrom mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
Find and copy all the *.deb packages into our local APT repository.
ahmer@local-apt-repo:~$ sudo find /mnt/cdrom -iname *.deb -exec cp {} /var/www/html/repo \;
Check the files that was copied by previous command.
ahmer@local-apt-repo:~$ ls /var/www/html/repo/
Write Script to Update Package.gz File:
Create a script file to scan and update the Packages.gz file.
It is required, because you may add new .deb packages in your local APT repository, time to time. Therefore, you are required to update the Packages.gz file, each time after add a new .deb file in repo directory.
ahmer@local-apt-repo:~$ sudo nano /bin/update-mydebs
Add following lines of code in this file.
#!/bin/bash cd /var/www/html/repo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Grant execute permissions to update-mydebs script.
ahmer@local-apt-repo:~$ sudo chmod u+x /bin/update-mydebs
Now, execute this script to create or update Packages.gz file.
ahmer@local-apt-repo:~$ sudo /bin/update-mydebs
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning: amd64-microcode crda efibootmgr grub-common grub-efi grub-efi-amd64 grub-efi-amd64-bin grub-efi-amd64-signed grub-gfxpayload-lists grub-pc grub-pc-bin grub2-common intel-microcode iucode-tool iw jfsutils kpartx-boot libdbus-glib-1-2 libfreetype6 libnl-3-200 libnl-genl-3-200 libnvpair1linux libuutil1linux libwrap0 libzfs2linux libzpool2linux linux-firmware linux-generic linux-generic-hwe-20.04 linux-headers-5.4.0-65 linux-headers-5.4.0-65-generic linux-headers-5.8.0-41-generic linux-headers-generic linux-headers-generic-hwe-20.04 linux-hwe-5.8-headers-5.8.0-41 linux-image-5.4.0-65-generic linux-image-5.8.0-41-generic linux-image-generic linux-image-generic-hwe-20.04 linux-modules-5.4.0-65-generic linux-modules-5.8.0-41-generic linux-modules-extra-5.4.0-65-generic linux-modules-extra-5.8.0-41-generic mokutil multipath-tools-boot ncurses-term openssh-server openssh-sftp-server os-prober reiserfsprogs shim shim-signed ssh-import-id thermald wireless-regdb zfs-initramfs zfs-zed zfsutils-linux
dpkg-scanpackages: info: Wrote 58 entries to output Packages file.
Your local APT repository has been successfully setup. You can now add it in the sources.list file of your Ubuntu 20.04 machines.
Add Your APT Repository in Ubuntu Sources.list:
Edit sources.list file in nano text editor.
ahmer@local-apt-repo:~$ sudo nano /etc/apt/sources.list
And add following lines at the end of this file.
# Local APT Repository deb [allow-insecure=yes] http://local-apt-repo.centlinux.com/repo ./
Execute apt-get command to update packages list.
ahmer@local-apt-repo:~$ sudo apt-get update
Ignore the warning about the release file.
Try to install a package from your local APT repository.
ahmer@local-apt-repo:~$ sudo apt install jfsutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
jfsutils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 195 kB of archives.
After this operation, 1,616 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
jfsutils
Install these packages without verification? [y/N] y
Get:1 http://local-apt-repo.centlinux.com/repo ./ jfsutils 1.1.15-4 [195 kB]
Fetched 195 kB in 0s (3,991 kB/s)
Selecting previously unselected package jfsutils.
(Reading database ... 77573 files and directories currently installed.)
Preparing to unpack .../jfsutils_1.1.15-4_amd64.deb ...
Unpacking jfsutils (1.1.15-4) ...
Setting up jfsutils (1.1.15-4) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for initramfs-tools (0.136ubuntu6.3) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-66-generic
Your required package has been installed successfully.
Conclusion:
In this article, you have successfully create a local APT repository on Ubuntu 20.04 LTS.
Hi,
ReplyDeletethis tut doesn't work at the end, when I want to install something from /var/www/html/repo apt pul packages from official repo not from local.
Hi, this tutorial is written for an offline Ubuntu server. It looks like your machine is connected to Internet, that is why it manages to pull the packages from online repositories.
DeleteHowever, you can comment out (#) all online repositories in sources.list file to achieve the desired result.