Note:<\/strong> It\u2019s a security best practice to access a protected server through a SSH jumpbox, often called a \u201cbastion host.\u201d<\/p><\/div><\/div><\/div>\n\n\n\nStep 2: Explore the APT Structure<\/h2>\n\n\n\n APT gets its packages from repositories defined in the \/etc\/apt\/sources.list<\/strong> file and in the \/etc\/apt\/sources.list.d\/<\/strong> directory. The sources.list<\/strong> file contains a list of \u201csources\u201d or locations from which APT fetches packages. Each line in the file specifies a different source, starting with the type of archive (deb for binary packages and deb-src for source packages), followed by the URL of the repository, the distribution codename, and the repository sections.<\/p>\n\n\n\n <\/figure>\n\n\n\nIn the screenshot above, we can see deb and deb-src packages belong to the bookworm<\/strong> distribution which is Debian 12, and the repository section main <\/strong>contains free and open source software officially supported by Debian. In the case we see the repository section called restricted<\/strong>, that is related to proprietary drivers.<\/p>\n\n\n\nStep 3: Add New Repositories<\/h2>\n\n\n\n The first step when adding custom repositories to our repository list is to make a backup of our current sources.list<\/strong> file.<\/p>\n\n\n\n\n
sudo cp \/etc\/apt\/sources.list \/etc\/apt\/sources.list.backup<\/p>\n<\/div><\/div>\n\n\n\n
Next, we can open the sources.list<\/strong> file in our preferred text editor:<\/p>\n\n\n\n\n
sudo nano \/etc\/apt\/sources.list<\/p>\n<\/div><\/div>\n\n\n\n
There we can paste the information about security-related repositories for our Debian version:<\/p>\n\n\n\n
\n
deb http:\/\/deb.debian.org\/debian\/ bookworm-updates main contrib non-free deb-src http:\/\/deb.debian.org\/debian\/ bookworm-updates main contrib non-free<\/p>\n<\/div><\/div>\n\n\n\n
We can see that there are already repositories that are defined but we will add official ones for redundancy.<\/p>\n\n\n\n <\/figure>\n\n\n\nPress Ctrl + W<\/strong> for writing changes and Ctrl + X<\/strong> to exit the file.<\/p>\n\n\n\nNow we can run the following command:<\/p>\n\n\n\n
\n
sudo apt update<\/p>\n<\/div><\/div>\n\n\n\n
This command will refresh the list of available updates and also include the repositories that we placed in our sources.list<\/strong> file.<\/p>\n\n\n\nAs we can see in this example, the update command added a few packages that have pending updates.<\/p>\n\n\n\n <\/figure>\n\n\n\nWe can check them by running the command:<\/p>\n\n\n\n
\n
apt list –upgradable<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nNext, we can add a new PPA or Personal Package Archives which are repositories designed for individual developers to deliver updates directly to users. This allows additional flexibility as you can often find some custom packages that are not available in official repositories.<\/p>\n\n\n\n
You should research these archives and repositories thoroughly before installing them on your system since some of them could create errors and broken dependencies.<\/p>\n\n\n\n
We can add the latest PHP version as part of ppa:ondrej\/php <\/strong>for Debian. The first step is to import the GPG signing key.<\/p>\n\n\n\n\n
sudo wget -O \/etc\/apt\/trusted.gpg.d\/php.gpg https:\/\/packages.sury.org\/php\/apt.gpg<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nImporting GPG keys for APT repositories is crucial because it allows your package manager to verify the integrity and authenticity of the packages you download and install. It ensures that the packages have not been tampered with and are from a trusted source.<\/p>\n\n\n\n
This command downloads the GPG key from the provided URL and saves it directly into the trusted.gpg.d directory, which is where APT looks for additional GPG keys beyond the default keyring.<\/p>\n\n\n\n
Next, we can add the repository:<\/p>\n\n\n\n
\n
echo “deb https:\/\/packages.sury.org\/php\/ $(lsb_release -sc) main” | sudo tee \/etc\/apt\/sources.list.d\/php.list<\/p>\n<\/div><\/div>\n\n\n\n
This command adds a new source to the APT sources list for PHP packages provided by the “packages.sury.org”<\/strong> repository.<\/p>\n\n\n\nNow we can sync the PPA with our local list, so we will run the update command again:<\/p>\n\n\n\n
\n
sudo apt update<\/p>\n<\/div><\/div>\n\n\n\n
Now we can install the latest PHP 8.3 version:<\/p>\n\n\n\n
\n
sudo apt install php8.3<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nWe can verify that our PHP version is installed by running the following command:<\/p>\n\n\n\n
\n
php -v<\/p>\n<\/div><\/div>\n\n\n\n <\/figure>\n\n\n\nStep 4: Remove or Disable Repositories<\/h2>\n\n\n\n Removing a repository might be necessary if the source is no longer maintained, if it conflicts with other software sources, or if you no longer require the software provided by that repository. Disabling, on the other hand, does not remove the repository but temporarily turns it off, which can be useful for troubleshooting issues or testing the system without certain updates.<\/p>\n\n\n\n
Understanding how to effectively remove or disable repositories ensures that your system’s software sources remain reliable, up to date, and secure. This segment of the tutorial will delve into the practical steps and considerations for removing and disabling repositories on Debian and Ubuntu systems, ensuring that you are comfortable with this important segment of APT management.<\/p>\n\n\n\n
We will look into disabling a repository first; this process is pretty straightforward. We need to comment on the line in our sources.list<\/strong> file.<\/p>\n\n\n\nFirst, open sources.list file in your preferred text editor:<\/p>\n\n\n\n
\n
sudo nano \/etc\/apt\/sources.list<\/p>\n<\/div><\/div>\n\n\n\n
Here, we need to comment out lines for repositories we want to exclude:<\/p>\n\n\n\n <\/figure>\n\n\n\nTo remove the repository, the solution is to delete the line or lines completely from the sources.list<\/strong> file.<\/p>\n\n\n\nIf we have custom PPAs that we want to remove, we can do so by first checking the sources.list.d<\/strong> directory where custom PPAs are stored.<\/p>\n\n\n\nIn this example, we have our php.list<\/strong> that we installed previously, and there is one opencpn<\/strong> repository that is broken so we will remove it.<\/p>\n\n\n\n <\/figure>\n\n\n\nWe can do so by removing the file directly:<\/p>\n\n\n\n