Complete Intro to Linux and the Command-Line

Package Management & APT Basics

Brian Holt

Brian Holt

SQLite Cloud
Complete Intro to Linux and the Command-Line

Check out a free preview of the full Complete Intro to Linux and the Command-Line course

The "Package Management & APT Basics" Lesson is part of the full, Complete Intro to Linux and the Command-Line course featured in this preview video. Here's what you'd learn in this lesson:

Brian gives a brief overview of package management, focuses on the package management tool (APT), and reviews commands.

Preview
Close

Transcript from the "Package Management & APT Basics" Lesson

[00:00:00]
>> The next thing that we're gonna talk about is package management. So one of the best parts about Ubuntu and Linux in general is, there's a package for generally everything. Most things follow that Unix philosophy of every program should do one thing well, and so there's a lot of packages that do one thing well.

[00:00:22]
And this is kinda like NPM, right? Like NPM, you have a bunch of mini packages that do one thing and you use those mini packages to make bigger programs that do bigger things, right? And that's kind of the philosophy here as well. So, every big Linux distribution comes with its own package manager.

[00:00:39]
So, for example, Ubuntu has APT which is, advanced package. Advanced package, I can't remember anyway, APT. APT, I always call it APT, I don't know if you're supposed to, but that's always what I call it. Advanced packaging tool, that's what APT is. But that's just for Ubuntu, that's only Ubuntu's tool.

[00:01:04]
Debian has dpkg, which is also available on Ubuntu, because APT or, sorry, rather, Ubuntu is based on Debian. So you can also use dpkg, it's just a lower level, a bit more difficult to wrangle tool, whereas APT is a very nice tool to use. Red has rhel, something or no, sorry rhel is the name of the distribution.

[00:01:30]
It has RPM, Red Hat package manager. There's yum, yum is also another one for rhel. There's APK which is for Alpine. There's a bunch of various different tools that we use. But so far to say, today we're just gonna focus on APT. But yeah, I did want you to know that dpkg,does actually exist.

[00:01:54]
It's already installed on there. You can use it if you want to. I've never had an opportunity that I didn't want to use APT. So Yeah, so let's go ahead and get started on APT. The one thing I was gonna show you. Before I get into APT there actually is like a really nice tool for managing APT.

[00:02:13]
So if I put in sudo APT install Aptitude, this one right here, Aptitude. It is gonna say, hey, I'm gonna download a bunch of different things, that's typical. It's kinda like NPM where you have to install 20 thousand packages to get one same sort of thing here. So I'm gonna say yes, it's gonna go out to the Network, it's gonna install a bunch of stuff.

[00:02:43]
And then it's going to let me run aptitude. So aptitude, I'm not gonna really show you too much about it. But what's cool about aptitude is, it's actually like a really nice front end to the package manager for Ubuntu. So you can see what I have installed, you can see what I have to upgrade.

[00:03:01]
You can see here that I have all these various different packages that are already installed. Here's things that need to be upgraded. Kind of cool stuff, right? So, this is really nice to be like we wanna browse around, see what I have, what's available to update, that kind of stuff.

[00:03:15]
And then as soon as I hit Ctrl C, it'll exit out of it. And so aptitude is not installed by default, but it is a tool made by canonical and Ubuntu. So it's a tool you can trust, right? So just be aware of its existence, okay? So I wanna take a second and talk about apt-get versus APT, or APT versus apt-get, right?

[00:03:42]
So you'll see a lot of tutorials that do apt-get like this, right? And then you'll do apt-get install and then blah blah blah. Why is there two of them? Why is there apt-get install and APT install? apt-get is the old one, APT is the new one. So in other words, apt-get still works, I think it'll work forever, it has some various different behaviors that are more advanced than APT.

[00:04:06]
So it'll stay there because they just wanna maintain backwards compatibility. But APT install is the new one, go ahead and just use that one. Yeah, it's just meant to be easier. So APT is meant to be an easier tool to use. It's much meant to be simpler and easier to use, for them 99% use case, and they keep asking around if you need to do some wild stuff that I've never had to do.

[00:04:31]
Okay, so the next thing I want you all to install, is one of my very favorite programs called lolcat. So please, at this point, do apt install lolcat like that. Now it's gonna say, hey, you don't have permissions to install this, and that's because when you're running apt install, you actually do have to do sudo apt install it.

[00:04:57]
Now if you remember, if you do exclamation exclamation point, it's going to rerun the previous command. So if I do sudo exclamation point exclamation point, it's gonna run sudo apt install lolcat. So that's like exclusively when I use the double exclamation points or the bang bang. So you can actually see it.

[00:05:17]
The next time it shows you, this is actually what I ended up running. So I'm gonna say yes, that's what I wanna install. Okay, so now we have a new program that we've installed, lolcat, and it makes our terminal very colorful. So even the help text is very colorful.

[00:05:42]
So is lolcat very similar to cat, it just makes whatever it's catting out rainbow colored. So if I say cat log.txt, you can see that this is what it outputs, but if I say lolcat log.txt, you can see it's much improved and much better, right? Now what's cool about this is, some random user somewhere wrote lolcat.

[00:06:10]
And we can now install that wherever we want, just because they wrote that for us and they put it on the apt registry. So actually another one of the frontend masters instructors, Sarah Dresner, every time that she runs ls, she actually has it like set up, so it always runs it through lolcat.

[00:06:33]
So this is always what it looks like when she runs ls. Which I have to say, is pretty fabulous, right? This just makes me a little bit happier every single time that I have to go run ls. So yeah, credit to Sarah Dresner for showing that one to me.

[00:06:52]
And I linked an article in the course notes here that you can actually go out and set that up yourself. Sarah wrote a funny little article of how to do that. So I wanna be able to run node, but you can see this computer does not have node.

[00:07:08]
So if I try and run node, it says, hey, no, it's not here, do you want to install node? Yes I do, so I'm gonna say, just copy and paste that, and I'm gonna go out and install node.js. So now if I come in here and I say node again, it's gonna drop me into the Node REPL.

[00:07:36]
Or I can go ahead and run something like no-e, which is going to execute whatever you put in the quotes. Console.log.hello from node. Now you can see, this ran node.js, it ran a console log and it says hello from node, which is exactly what we saw there. So pretty easy.

[00:08:01]
I did want to show you that can do apt search for node js, and this is probably gonna show you a bunch of things, right? So these are all the various different node js things that are available to install off of apt. And then I can also say apt, show node js.

[00:08:18]
And it's gonna show me all of the information about node js that it has. It has all these different versions, it's maintained by these people. It's priorities extra, I think that means it's like they keep a very close watch on it. Whereas like if we said apt show lolcat, You can see, I guess, extra as well.

[00:08:38]
So I actually don't even know priority is there, but you can see these are all the various maintainers of it. So for example, you didn't know but lolcat was actually written in Ruby. I didn't know that until I looked at that. So that's interesting. Cool. So that's kind of a whirlwind tour of how to use apt.

[00:09:00]
I use it quite a bit because you can go out there and install, there's different utilities that you need. When you're doing things like setting up Docker, it's really useful to use apt to install the various different packages you need for your containers. Yeah, it's good. Let's show you a couple more different commands that are useful to know.

[00:09:20]
There's sudo apt auto remove, that's gonna go and just clean up stuff that you have that you really don't need. So it's gonna say, I found one package that you don't need to have, so I'll say yes. And it's removing this grub-pc-bin, cuz apparently nothing is installed and nothing is referring to it.

[00:09:39]
So it just goes and removes it. Sudo apt update. So the way that apt actually works, is it downloads a list of all available packages to your computer. So if you do this update, it will actually go get the new copy of that. Now, mine probably didn't have that much to upgrade, cuz this is a very new copy of it.

[00:10:04]
But if you run your Ubuntu for 30 or 40 days, there's probably gonna be a new version of various different packages for you to have. So before you install something, it's usually a good idea to do an apt update and then an apt install, to make sure that you're getting the latest version of everything.

[00:10:23]
You can do a sudo, or I like to assume it's an apt list, and it'll list all of the packages that you have installed. You can see it's a lot, right? So sometimes it's useful to just say app list upgradeable. And here, from here, right? Here is everything that I could update.

[00:10:45]
So this will let me know, here's all the stuff you can go update. And if you wanna just go do that, you can do sudo apt upgrade. And if you don't tell us any specific package, like I could say right now, just updated libxau6, right? And it would just update that package, but if I don't tell it anything, it's just gonna go update all of them.

[00:11:12]
So that'll take in to go, and it'll go reinstall and update all of those various different packages. And there's no reason that we need to necessarily wait here for all of this. Normally it goes faster though, there you go. Well, one of the packages has a post install script which is kind of fun.

[00:11:42]
So let's just say keep the local versions installed, I have no idea. It's doing some boot stuff upgrade. I probably should have paid a lot more attention to what I just did. But this is a local VM that I'm gonna blow up at the end of this, so I don't care.

[00:11:59]
I probably just upset some sysadmin somewhere. Some dark cave somewhere they crawl down and say, why didn't you do that? Okay and then the last thing I wanted to show you is sudo apt full upgrade. And this is just gonna do those previous two commands that I showed you together with the auto remove and the upgrade at the same time.

[00:12:21]
It's just going to go do everything for you. Since I already ran both of them, it's gonna, it should have nothing to do, which it doesn't. But that's another good thing to do when you first start something. Do a full upgrade, get everything up to date. Make sense?

[00:12:36]
Good so far. The one thing I was gonna show you from the class notes. When I come back in here, close my dev tools and here in, package management in apt down at the bottom. There's a link here. If I click on this, It'll take you to apt-browse.org.

[00:13:01]
There's no official website for the apt registry but this will browse it for you. So if I put no Jason here, it'll show me everything that matches that I can click on that. And this will just give me a bunch of information about that node JS package. So if you wanna look at it, you wanna see what files are coming with it.

[00:13:19]
You can see a description where it's coming from, those sorts of things. This is a good place to go check it out really quick before you install it.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now