Now for our first demonstration,
we're working on our Ubuntu 20.04 system and investigating
the advanced packaging tools, or apt.
So here we are working on our Ubuntu system.
The Ubuntu knows about the software that's available through its
repository files. And in Debian‑based systems such as Ubuntu, we're
going to find those as /etc/apt and then the /sources.list. Now this
is our file, but often there is an extension directory where we can
add in additional files.
We can see the directory is empty at the moment, so we're working
just with our /etc/apt and /sources.list file.
This is a list of online repositories where we can locate and
install software from. If we go through and take a look inside of
this file, and I can use my escape and dot. That brings up my
previous argument, but escape and dot brings up the previous
argument to the last argument.
We can then go through and list our content, and we can see, well, it's heavily
commented because we have a lot of additional repositories that we could use,
but are not used by default. If we want more software to be available to us,
uncomment those additional repositories. But if we want to look at those that
are just configured at the moment,
then we can use our good friend, grep. Using ‑v, we reverse our search, and we
can have an enhanced regular expression because this is going to allow me then
to combine two expressions together, so we can say lines that begin with either
the comment or the end of line marker.
Remember, we're saying don't show me those lines. We're reversing our search.
So we're saying don't show me lines that begin with a comment or are empty.
And we can see then that these lines are not commented and obviously aren't
empty, representing the online repositories that we are currently looking at.
Now the packages that are located in these repositories,
we need to know about them, and they are stored in a cache, but there
isn't a maintenance task by default to update the cache.
So very often, the first thing that we need to do is to update our
cache before we look at installing software.
If we want to check the age of the cache to see when it was last updated, we
can use the stat command. Stat ‑c, instead of showing us all of the metadata
from a file, asked to show just one specific element.
The %z is looking at the last status change of the file, and the
update was last carried out from the timestamp,
/var/lib/apt/periodic/update‑success‑stamp file.
So reading the metadata from this file,
we're going to be able to see in human readable format
when the cache was last updated.
So hitting the big Enter key,
we can see that it was 2021, December, and the 2nd of December. Which is fine,
but considering we're now actually on the 4th of January, 2022 may obviously be
a little bit different when you're watching this,
but we can see the cache has become out of date. And in that case, we might
not be able to find the packages that we are looking for because their name
has changed, as the version has been updated.
So we need to make sure that we update the cache.
We can do that with our advanced packaging tool, or apt.
And it's quite a simple matter of sudo apt update, so update is updating the
metadata. As we then go through and read from our online repositories, we're
just getting a fresh list of what software is available.
We can see there are 19 packages there that are upgradable. And when we go
through now and take a look at the timestamp on the file,
we can see then that its status last changed the 4th of January.
So we are up to date, but it is something you need to
consider when installing software.
If you know you haven't recently installed software on that system,
then go through and run an update before you try installing.
When we're ready to install software,
we first have to know the software package that we want.
If I go through and do something like an apt search and the package tree, well,
because we're searching a lot of the descriptions, as well as the name,
we're getting a huge amount of information coming back.
But we can actually search for a regular expression.
So if we look for the package beginning with tree and ending with tree,
then we are looking for the complete name, and then we
get just one package coming back.
If we want to install the package tree and we can see what it does,
it gives me a nice graphical display of a directory tree structure.
We can then run ahead and use our sudo apt install tree.
It's a relatively small package, so it comes down. And if I just go tree,
it will look at the current directory.
Well, my home directory doesn't have a whole heap in here,
so that's not doing too good for me.
But if I then go through look at tree and /usr/share/,
and let's look in the dictionary directory, well,
that also is empty.
I can look in the doc directory, but we're going to have a file more here,
but we've got a good idea of what it does when we start looking because we
can see then the directories and the contents of those directories, and it
could be great for documenting setups for blogs and what have you. Now
having installed the package tree, maybe we don't need it anymore.
And we can either remove it using the command
remove, so I can use apt remove tree.
Another way to remove it is using purge.
They both will do the same thing as far as the tree package is concerned.
The differences with purge is that once it's been removed,
it will also remove configuration files.
Now especially with a service, we might have spent a
lot of time configuring that service.
We might want to reuse that configuration file on a different system or later
if we reinstall the software. So remove doesn't take out the configuration
files if they've been modified, whereas purge will remove all of the package,
including modified configuration files.
Now having gone through and removed our software,
we can also go through and take a look at other actions. Here, if I
go through and see what software can be upgraded, so it's all
software that I have, but there are later versions within my
repository, then we can go through and take a look by doing the apt
list and ‑‑upgradable.
So we can see there are a few packages that are available.
We can also see that some are marked with security.
I can honestly go through and run a grep to look for
those security updates, but there isn't a separate switch
just for the security updates.
If I want to go through and update all of these packages,
well then, it's going to be quite simple.
Again, using my apt tool, it just becomes a simple matter of apt and upgrade.
So update is to update the metadata, the cache, about what's available,
upgrade is then upgrading a package or if I leave the package name blank,
upgrading all packages. I can leave this cooking.
It will probably take a little while,
but then we're going to be up to date, as far as our software is
concerned. But we've seen the basic operations and tools for managing your software on an Ubuntu‑based system.