Time to complete: ~0.5-1 hours
Using apt, Installing Midnight Commander, Exploring the File System
Welcome back! In this installment we’ll be working with Debian’s Advanced Package Tool. We will manipulate it using the
apt command in order to manage applications. There are other command line tools that can be used to interact with the Advanced Package Tool, but we’ll be using
apt today. This command allows for the easy installation, updating, listing, and removal of programs on Debian and its derived distributions. The
apt command is very commonly used and referenced. We’ll be using it to install Midnight Commander.
Before we dive into
apt and how its commands work we need to clear up a potential issue before it causes confusion. Beginning in Ubuntu 16 the
apt command was created in order to promote ease of use by simplifying common commands issued using
apt-cache. This means that instead of using those commands with all of its options merely using
apt will get you what you want with less input required. It also offers more output like a pretty progress bar when installing applications as well as added output of
apt update in that it tells you how many upgradable packages you have ready to go. Running the
apt list --upgradable command returns an improved formatted list of upgradable apps. Keep this in mind when managing older systems. They may not have
apt installed and you’ll have to resort to using
apt-cache are installed by default on current Ubuntu systems.
ls -lR command on
/etc/apt to get an idea of how its file structure is laid out.
Let’s review the different parts of apt:
This config file, located in /etc/apt, is where the source URIs are listed for repositories. This file is important enough that it has its own man page. From this man page we can see what the default format is for listing a source:
deb [ option1=value1 option2=value2 ] uri suite [component1] [component2] [...]
Use grep to weed out entries containing “deb” to see what sources are configured for your system.
__________________________________________________________________________ |dpaluszek@upskillchallenge:~ -bash v5.0==>grep deb /etc/apt/sources.list deb http://us.archive.ubuntu.com/ubuntu focal main restricted # deb-src http://us.archive.ubuntu.com/ubuntu focal main restricted deb http://us.archive.ubuntu.com/ubuntu focal-updates main restricted # deb-src http://us.archive.ubuntu.com/ubuntu focal-updates main restricted ... ...
This command, when run, prompts you for your text editor of choice, then opens the sources.list file in that editor. From here you can make edits. If you noticed the sources.list file is owned by root, so you’ll need to make use of sudo in order to save your changes.
Aside from editing the
sources.list file manually you could also use this command. In addition to modifying the
sources.list file it will automatically download and register any public keys. Use it like so:
sudo add-apt-repository ppa:<repository-name>
This easily comes in first in the “most used
apt command” contest. Running
apt update will update all package info from all configured sources. Running this before performing any other actions is required in order to ensure you are working with the latest set of package information and thus, getting the latest updates.
Probably the second most used apt command. Run
apt upgrade to install all available updates for packages found using the
sources.list file’s configured repositories. Note that any packages that require an uninstall of any other package won’t be installed. To handle this removal automatically to install such packages use the
apt full-upgrade command.
This one works as advertised. Pass apt search a search term and you’ll be returned with any package containing that keyword, including what is in the package description (useful for searching out features).
These 3 commands rely on the package name you found using apt search to do as their name suggests. The
install switch will install the package while
remove will uninstall. Note that using
remove will not remove configuration file artifacts in the event the program was uninstalled accidentally. To remove those artifacts use the
When packages are installed their dependencies are installed too. When you uninstall a package only that specific package is uninstalled, not the dependencies. Also note that sometimes package dependencies change and those dependencies are no longer needed. To remove the disused dependencies run the
apt autoremove command.
Passing the name of a package attained from the a search will give you detailed info on the package. Use this to gain more insight into the packages you are aiming to install.
This command shows a list of packages by filtering by criteria. You can pass globs to the command as well as use options to list installed (–installed), upgradeable (–upgradeable) or all available (–all-versions) versions.
Now that we have a basic grasp of how apt works, we can go ahead and install a package. Let’s search for and install midnight commander.
_________________________________________________________________________ |dpaluszek@upskillchallenge:~ -bash v5.0==>apt search "midnight commander" Sorting... Done Full Text Search... Done avfs/focal 1.1.1-1 amd64 virtual filesystem to access archives, disk images, remote locations junior-system/focal 1.29ubuntu1 all Debian Jr. System tools krusader/focal 2:2.7.2-1build1 amd64 twin-panel (commander-style) file manager mc/focal 3:4.8.24-2ubuntu1 amd64 Midnight Commander - a powerful file manager mc-data/focal 3:4.8.24-2ubuntu1 all Midnight Commander - a powerful file manager -- data files moc/focal 1:2.6.0~svn-r2994-3build1 amd64 ncurses based console audio player pilot/focal 2.22+dfsg1-1 amd64 Simple file browser from Alpine, a text-based email client
It appears that “mc” is what we are looking for. Let’s go ahead and get some info on it:
apt show mc
Installing is just as easy:
sudo apt install mc
Type Y then hit Enter when prompted to install and let the magic happen.
Exploring the File System
Now that Midnight Commander is installed lets play around with it. Run it in terminal by typing
mc and hitting enter.
You can use either the arrow keys or your mouse to navigate the file system. Poke around with the following:
You can open files by highlighting the file you wish to read and then clicking the “File” menu up top, then clicking “View File”, then clicking “Ok”. Take note regarding files you don’t have permission to access. What do you think you need to do in order to see root owned files using Midnight Commander?
Well this was a lesson that you’re sure to reuse. Using apt on Debian/Ubuntu/et al systems is a must if you are going to administer these machines with success. There are various other tools to manage packages on Linux systems and while they differ in details they are functionally equivalent.
Next episode we’ll use some new commands to view file content as well as do some more basic terminal navigation, playing with hidden files, and we’ll finish off with a deep dive into
I’m just a normal sysadmin type guy who likes cybersecurity a lot.