Episode 8 Package managers

In this episode, we explore some of the capabilities of package managers for installing and updating software on your system. Specifically, we look at the ‘apt’ system on Ubuntu GNU/Linux. On other systems, you might use Yum (RedHat/Fedora), Pacman (Arch), or Homebrew (Mac). This page shows a comparison of commands for several Linux packaging systems: https://wiki.archlinux.org/index.php/Pacman_Rosetta

15 September 2015

[Rhythmic, dark electronic intro music]

League

Hi welcome back to Command Line TV. This is episode 8. And what are we going to talk about today?

Lopes

Well last time we spoke about ImageMagick. We did a lot of image manipulations.

I guess today we’ll talk about package management and how to actually get

ImageMagick and other software onto the computer.

League

Yeah, it’s probably not installed by default on whatever system you’re

using so you definitely will have to install it. And package management is

an important topic in Linux systems and other Unixes because package

managers I think are one of the real advantages of Linux systems.

Basically when you want to install new software, there usually are these

archives or repositories of software that’s already been configured and

prepared to run on your system. So you just have to know the right commands

in order to search those and figure out what you need to install, and then get it installed.

These package managers also figure out the dependencies for you.

So if you have one piece of software that depends on other pieces of

software it can go and install all of them together and make sure that all gets managed.

Lopes

So I know on Windows you usually have an installation wizard that walks you

through every single step of installing software onto the system.

How does that differ using Ubuntu or Linux?

League

The way software is installed on Windows is a little different.

Those wizards might ask you some questions about like, where you’d like to install stuff.

That’s not usually a choice on the package managers on Linux systems –

they install in standard places. And sometimes the package managers will

ask other sorts of questions about configuration and so forth.

But the big difference is that windows packages tend to be either entirely self contained,

which means that you can install the software and you don’t need it to

install other pieces of software for you. Or in many cases for more complex

stuff you might have to chase those dependencies manually.

So I might want to install some IDE that requires the compiler to be installed separately first,

and then I have to tell the IDE where the compiler is and all sorts of things like that.

So the story on Windows is a little simpler and a little more complex,

it all depends on what you’re trying to accomplish.

But another problem that Windows suffered from for many years –

and it’s gotten way better recently – is what we call “DLL hell”.

And DLL is the dynamic libraries that Windows used.

What would happen is – there might be a very common library or dependency

of multiple software packages and that would be represented as a file with the extension .dll.

And then say you install package one which requires it and package two which requires it,

they will each bring their own but maybe install it in some central place

where they could conflict with each other. And so if one of them

over-installs the other one but they might be different versions and the

other one’s not expecting the new version – there are all kinds of problems that can happen.

And so a very strict system of package management helps tame this problem.

Each package specifies explicitly its dependencies and what versions of

those dependencies and in some cases it has facilities so that multiple

versions of the same software or same library can also be installed.

But this takes a lot of effort to put together and it’s one of the reasons

that Linux distributions put a lot of work into making this stuff as simple as possible.

Lopes

In today’s episode we’ll be using Ubuntu which uses ‘apt’ package manager

but what other options do we have in terms of package managers?

League

It all depends on the system that you’re running. The Debian and Ubuntu

systems use ‘apt’ as you mentioned, and other derivatives of them also use it.

RedHat systems and Fedora use something called yum

it pretty much provides the same type of facilities, the commands are just slightly different.

On my laptop I use ArchLinux, and ArchLinux has a command called pacman.

And then on the Mac, the Mac App Store is fine for these self-contained applications,

more like the Windows style. But if you want to install software that’s common on Unix,

including libraries and compilers and things like that –

you probably want to get a package manager on your Mac.

The one that seems to be popular now is called brew,

and it does package management a lot like ‘apt’ or yum.

Historically on the Mac, there have been other ones.

There was one called MacPorts and ‘fink’ and a couple others –

but I think brew is the best solution.

Lopes

So like I said today we’ll be using my Ubuntu as opposed to your Linux.

Here we have my Ubuntu terminal. When we start with ‘apt’,

what would be one of the first things we would do in terms of finding downloads?

League

Yeah, so the command that is most useful for finding stuff is called apt-cache.

It’s all one command, but with a hyphen in it. And then you would do a

sub-command after that called search, and then you can put a keyword or

the name of a package or something like that. Why don’t we try searching for imagemagick.

apt-cache search imagemagick

Try that.

And we got a lot of stuff out there – all of it has some relationship to ImageMagick,

but maybe we want to – I don’t know – scroll up or pipe it through less

apt-cache search imagemagick | less

so we can look more carefully at those. Right

So near the top, I see imagemagick as a package name all by itself.

Each line here is a package name followed by the space dash space, and then a description.

So imagemagick all by itself is the name of a package and that might be the one that we want.

You can see other ones that are interfaces for programming,

like it says “C++ interface to ImageMagick” and so on.

So let’s see if we can just find more information about one of those packages.

I’m going to quit the less output (q) and let’s do apt-cache show and

then the name of the package. In this case, it’s got to be the name of a package,

apt-cache show imagemagick

not just a keyword. But this will give us a lot of details about this package,

including a longer description, and if we look up a little bit it has the version number –

this is 8:6.7.7 something – and then the dependencies.

It shows what other packages this depends on, and what versions it requires.

It’s a little bit flexible about – so libc6 has to be a version >= 2.2.5.

So if a new libc6 comes along, it should still play nicely with imagemagick.

And then there’s a list of packages that it recommends or suggests.

These are not installed by default like the dependencies are,

but they might be other tools that work with it in some way,

and you might want to look at that list and get other ideas of things you might want to try.

So I think we’re ready to try and install this. The command to install isn’t based on apt-cache,

but it’s called apt-get with a hyphen. And then you just say install

and the name of the package. Yes, let’s try it.

apt-get install imagemagick

Oh, what happened there?

Lopes

I still have to do sudo.

League

Yeah, permission denied, so sudo is a command to get us administrative access,

sudo apt-get install imagemagick

assuming that we’re allowed to do that. And periodically with that you’ll have to type a password.

Okay, so it’s installing several packages, in addition to imagemagick.

It has some stuff here about update-alternatives which we can look at.

But now you should have the commands like convert and mogrify and all that.

Just see if they’re available.

which mogrify

Yeah, so which tells us where a command is, and those are now installed

on this system and we can start using them.

Lopes

So on Windows, normally once a program is installed it’ll update automatically.

How do we go about making sure all our programs are up to date on an Ubuntu device?

League

Some Ubuntu systems are configured to do what I’m about to show you periodically by itself.

If not though, it’s perfectly easy to do it yourself.

So what we’re going to do is run a command, also on apt-get but the sub-command is update,

apt-get update

so apt-get update. And this will basically contact that package

repository and see what the latest versions – we do have to be admin for that too –

sudo apt-get update

it’ll see what the latest versions are in these package repositories and

download the version information, so that we can see if there is new stuff

that needs to be downloaded.

And you see some of the hits here that we’re contacting are security.ubuntu.com,

so this is the repository where it keeps track specifically of security updates.

So now we’ve got the latest package lists and we want to see if there are new things to upgrade.

And that’s apt-get upgrade – also we need sudo.

sudo apt-get upgrade

It will ask us to confirm after showing us the packages that it wants to upgrade.

So basically it says “the following packages were automatically installed and no longer required” –

I’ll show you how to get rid of those shortly. But the next section,

“the following packages will be upgraded” – those are things where there

are new versions available, so we can just press enter or say yes to let that happen.

And it’ll go and fetch those latest versions and install them.

Lopes

So on Windows we could easily access the “Program Files” to see what

applications we already have installed. How could I do the same thing using the command line?

League

So there’s a lower-level tool that’s part of the ‘apt’ system called dpkg.

And if you run that with a -l (lowercase l), just that by itself will

dpkg -l

give you the complete list of all the installed packages.

Technically the ii at the front means that it’s installed,

and then following that is the package name, version, and description.

That was a lot of output so we could of course use less and grep and stuff like that.

But also you can put a pattern right after the -l,

so we could see like what’s installed that has something to do with images, or something like that.

Yeah, * would match anything after image.

dpkg -l 'image*'

Yeah, so this shows us that there’s a couple of packages related to imagemagick.

And one of them says un before it – that means that it’s not installed –

but it may have been installed at some point previously,

or else it probably wouldn’t show up here at all.

Let’s go ahead and install that imagemagick-doc package.

sudo apt-get install imagemagick-doc

This is supposed to contain documentation for the system.

Lopes

Now that the imagemagick-doc has been installed, how do I locate it?

League

So the files that are actually installed as part of that package can be listed.

And that’s dpkg -L (capital L) and then you put the name of the package afterwards.

dpkg -L imagemagick-doc
Lopes

And that always has to be with the exact name, correct?

League

Right you can’t just use a wildcard in this case. So it gave us a whole list of files here,

which make up the documentation for this imagemagick package.

dpkg -L imagemagick-doc | less

And a lot of them are in this folder /usr/share/doc/imagemagick/www, right.

And there’s a bunch of .html files in there. Probably there’s one called index.html.

You’re using less right now to view this, so I’m going to show you one

other cool thing about less, which is to search forward –

you do the slash, so just hit / and start to type index and press enter.

And it jumped down and highlights an index.html but that’s part of the API,

that’s not the one I want. So just hit / and enter and it will redo the previous search.

That’s part of MagickWand, / enter – and eventually we get down at the bottom of the screen,

to one that’s just part of the www itself and I want to open up that

index.html so we can start to browse the documentation.

So we can do that with nano but because it is HTML we’re going to see all

of the code and not the rendered web page. So instead,

remember how we opened images – there was xdg-open, I think?

Let’s try that – there’s a dash after the xdg. And try that on that /usr/share/doc/

yeah sometimes you’ll be able to complete it and sometimes not – and index.

xdg-open /usr/share/doc/imagemagick-doc/index.html

Okay.

That opened up your web browser, and here’s a local web page – this didn’t go to the actual web.

See in your browser it says file:// so this is just a local HTML file

you’re browsing that has documentation for this entire system.

And that’s pretty cool, I like to have documentation packages installed a

lot because I might want to browse how to do something when I’m not even connected to the Internet.

Lopes

Now that we’ve learned how to install programs via the package manager,

how can we find out what commands, or what packages certain commands belong to.

League

Sure, so dpkg has another option which is the -S (capital S).

And here you can put a filename, path name, fragment of a path.

So let’s try one of the imagemagick commands like mogrify.

dpkg -S mogrify

And this will show us a series of lines, each one has a package before the colon,

and then a filename after the colon. So this is all of the files on your

system that are installed by the package manager that contain mogrify.

And so most of them of course come from imagemagick-doc or imagemagick itself.

There is one strange one there, the package is called bash-completion.

And it’s got something called mogrify out there and I believe this is because –

so the completion mechanism in your shell is when you hit Tab,

and it will complete the command that you’re typing.

The fact that bash-completion knows about mogrify means that it might

also be able to complete the options for that command, which is pretty useful.

So let’s try out mogrify – and remember when we were resizing, we did (I think) -geometry.

So let’s start to type -geometry but you can hit Tab and it will actually complete that for you.

That’s because bash knows about this command and it has that completion for mogrify.

You can also do just a dash - and hit tab, and it will (I think) list –

you might have to hit Tab twice or something – and if there are a lot of

possibilities for completion it asks if you really want to see them all.

But now it’s showing you all of these options that mogrify supports,

which is a crazy number of them.

But that’s just a useful thing that we learned that bash supports this –

because we went looking for all the files that contain mogrify.

So today we spent a lot of time with Ubuntu’s package manager,

which is called ‘apt’, and we learned commands like apt-cache, apt-get, and dpkg.

But there are other package managers for other systems.

The concepts that we learned will mostly carry over,

and what you’d have to do is figure out on a different packaging system,

the commands that are different. And it’s pretty easy to find on the web a translation guide –

if you’re used to ‘apt’, how do you do this in yum,

or if you are used to brew how does it work in pacman or something like that.

So maybe in the show notes we’ll have some links to some of those translations that are available.

Lopes

Another thing that I do, even though since I’m a beginner at Ubuntu still –

is I’ll use a web browser to search different packages and programs I can use.

And then practice that via the terminal.

League

Yeah so that search output, like when you’re looking for a package to do

something and you apt-cache search – it’s pretty overwhelming what you get back from that,

because there might be tons and tons of packages that have to do with your keyword,

but it’s hard to tell what’s what. So yeah, just searching the web and

using Google in general is going to help you hone in on what program you

might really be looking for.

Lopes

So what do we have in store for next episode?

League

I think next time we’re going to look at some more shell basics that we haven’t gotten to yet,

like redirection – this means taking the output of a command and saving it to a file,

or getting the input of a command from a file. We’re also going to look at

the back-quote character – it’s another way to combine different commands,

like the pipe, but it works in a different way. And the last thing I think

we’ll look at next time is symbolic links, which is kind of a way –

like we studied aliases – it’s a little like an alias but it works differently.

It’s a way of saving another name for the same content within the file system.

So we’ll get to those things next time, thanks for joining us.

[Dark electronic beat]

[Captions by Christian Lopes and Christopher League]

[End]