Third Party Packages#
We've just done a big upgrade of the existing packages on our system. Let's now knock down two bottles with a single stone:
- Install a new, third-party repository
- Install some new software from the repository
Adding Apt Repositories#
We need to install nginx
, a web server, so that we can serve a static website from our server. The repository is maintained by the official nginx
developers at nginx.org
and it offers the latest versions of nginx
available.
First, nginx
has some dependencies before it can run, so let's install those now. We're about to use apt install
for the first time.
1 |
|
That installed only 1
new package on my system. Your results might vary.
Now we need a GPG key. This is a public key like cryptographic component that's used to securely sign the packages inside the repository. This helps to guarantee that the package you download was created by the nginx
developers and hasn't been changed whilst you were downloading it to your system. Apt takes care of checking all of this for you.
Run this: curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
1 2 3 4 |
|
We're using a very powerful tool called curl
to download https://nginx.org/keys/nginx_signing.key
(note how it's downloading over HTTPS? That makes downloading this file secure.) We then pipe (|
) the stdout
from the curl
command into the stdin
of the gpg
command. The gpg
command then saves the signing key locally and it can now be used to verify packages from the nginx
developers and their apt repository. We can even test this: gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
1 2 3 4 |
|
We have a public key that will expire in 2024-06-14
.
Now let's add the Apt repository:
1 |
|
And I get:
1 2 3 4 |
|
We're using echo
to print a string. The string has some sneaky tricks embedded in it:
1 |
|
What this is doing is calling the (local) command lsb_release
with the -cs
flags, and then substituted itself in the string with the results. Compare these strings:
1 |
|
Versus:
1 |
|
Notice in the second string we don't have lsb_release -cs
, we have focal
? Run the command: lsb_release -cs
1 2 |
|
So echo
is using that embedded little trick to execute the lsb_release
command inside the string so the value is replaced with the current version of Ubuntu you're running.
Now we have a string you've seen before (with a slight difference): deb <signing-key> <url> <distribution> <repository>
. The <signing-key>
field is used to tell Apt that the GPG key we downloaded earlier should be used to check the packages are secure and coming from the original authors unedited or not corrupted.
Finally, we update the list of packages we have available and then install nginx
:
1 2 |
|
My apt update
got me some new packages:
1 2 3 4 5 |
|
And my apt install
installed nginx
for me:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Whenever you're installing from the default, included Canonical repositories, you only need to use sudo apt install
. You don't have to keep adding repositories like we have above. This was to demonstrate adding a new repository and installing software.
Simple.