= Hands-On = == Repositories and key management == A Linux repository is a storage location that contains essential and popular software for different Linux distributions and, each distribution has its own official repositories (also called standard-repositories). Debian-based distributions, including, Ubuntu make use of the Advanced Package Tool (APT) to install and update packages. You can find software repository information in the `/etc/apt/sources`. list file on your Debian-based Linux installation. === Add repos manually === A better way of adding them to your system is by using the `add-apt-repository` tool. You won't find the `add-apt-repository` utility installed on your system by default. To install `add-apt-repository` using the APT package manager, type: `sudo apt install software-properties-common` Then execute, `sudo apt update` Add the repository as below. === Add Repositories Using add-apt-repository === The basic syntax for adding repositories is: `sudo add-apt-repository [options] repository` example: `sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"` === Key Management === The Linux key-management facility is primarily a way for various kernel components to retain or cache security data, authentication keys, encryption keys, and other data in the kernel The `add-apt-key` will request the specified GPG key from a public keyserver and insert it into the APT keyring so that archives signed with that key will be trusted. `sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ` Replacing the with the second part of the key informed in the PPA website that you want to add. For example, if you find this line: 4096R/7BF576066 Use only the second part (no matter its size), which in this example is 7BF576066 After performing that command, and setting up the sources {{{ sudo apt-get update sudo apt-get install[PACKAGE] }}} To list the key list, execute `apt-key list` and if you need to delete a key, `sudo apt-key del ` === Manual way to change the mirror === Change original URL addresses in `/etc/apt/sources.list` into the desired ones. The easiest way to do this is by using nano/vi. The last, perform a reload command to re-download the new mirror addresses: `sudo apt-get update` ==== How to select the fastest apt mirror on Ubuntu Linux ==== Choosing the fastest mirror with `netselect` The `netselect` package is not available within Ubuntu’s standard repository by default, so we will need to borrow it from Debian stable repository: `sudo apt-get install netselect-apt` Once you have the netselect command available on your Ubuntu system use it to locate the fastest mirror based on the lowest ICMP latency. The netselect output will be relative to your location. The below example output will show top 20 apt Ubuntu mirrors `sudo netselect -s 20 -t 40 $(wget -qO - mirrors.ubuntu.com/mirrors.txt)` Alter manually your /etc/apt/sources.list file to reflect the above netselect results or use sed command, where the lower score number on the left represents a higher mirror transfer rate. `$ sudo sed -i 's/http:\/\/us.archive.ubuntu.com\/ubuntu\//http:\/\/ubuntu.uberglobalmirror.com\/archive\//' /etc/apt/sources.list` ==== Manual apt mirror selection ==== `$ wget -qO - mirrors.ubuntu.com/mirrors.txt` Based on your experience select the best mirror and alter your /etc/apt/sources.list apt configuration file appropriately. = Linux package management = The most common and popular package managers they are likely to first start using is the apt (Advanced Package Tool) because it is most widely shipped as the default Package Manager for users of Debian, Ubuntu and Mint. We’ll cover some of the basic commands of how to use apt in order to illustrate the ease of use of using a package manager in the terminal window. == Let's see - update/upgrade, package installation == === How to install a package === Install a package as follows by specify a single package name or install many packages at once by listing all their names. To install apache2 `sudo apt install apache2` === Find dependencies of a package === Once package has been installed you might want to understand which dependencies the package is making use of, you can list out the dependencies of a package using apt as follows. `sudo apt depends apache2` === Search for package === It is highly likely that you will need to search for a package to perform a specific task. The apt package manager enables you to easily search for packages via the terminal. In this case, I want to search for an image manipulation program, I can simply include the phrase in quotes and use the apt search facility `sudo apt search "image manipulation program"` === View package details === You will often want to find and view details of package. In this example I want to view some details regarding the apache2 package we installed earlier. `sudo apt show apache2` === Upgrade system packages === Often the above command will instruct you that new releases of packages are available, so to install new versions of all the packages on your system. `sudo apt upgrade` Then reboot the system. You will often want to execute both these commands at the same time, so you can run them both at the same time using. `sudo apt update && sudo apt upgrade -y` Then reboot the system. If you need to update Ubuntu {{{ sudo apt update sudo apt upgrade sudo do-release-upgrade }}} Then check for the version. === Remove packages === To remove packages from your system. `sudo apt remove apache2` if you want to ensure all packages configuration and dependencies are removed at the same time you can use the purge switch. `sudo apt remove apache2 --purge` === Remove unused packages === Installing or upgrading packages will result in some dependencies not being required, you can clean up these unused dependencies after removing that particular package, it's dependencies will remain on the system, therefore to remove them use auto-remove as follows: `sudo apt autoremove`