This course will be retired on March 4, 2019. We recommend "Introduction to the Terminal" for up-to-date content.
Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Sometimes, building software from source can be more hassle than it's worth. If you have a package manager on your computer, it can make managing your software much easier.
Commands
-
apt-get update
Update your package catalog on your computer -
apt-cache search PATTERN
Search the available packages for a pattern -
apt-get install PACKAGE
Install one or more packages -
apt-get upgrade
Upgrade to the latest version of all the packages installed -
apt-get remove PACKAGE
Remove or uninstall package from your computer
-
0:00
[Deep Dive]
-
0:02
[Setting up a Server - Introduction to Package Managers]
-
0:04
[with Jim Hoskins]
-
0:06
Whenever we can, we are preferred to use a package manager
-
0:09
to install our software.
-
0:11
Besides making installs easy, it has many other benefits
-
0:13
like managing dependencies, handling updates, and uninstalling.
-
0:17
The package manager for Ubuntu Linux is called APT.
-
0:21
Ubuntu is actually a member of a family of Linux distributions
-
0:25
that are based on Debian Linux.
-
0:27
Linux comes in many different flavors and while they share the same core,
-
0:31
the tools and configurations and options
-
0:34
vary from distribution to distribution.
-
0:36
There are many different package managers for Linux,
-
0:39
and they vary from distro to distro.
-
0:41
APT is what is used for Debian-based Linuxes
-
0:44
and its related distros.
-
0:46
Some others are Pacman, RPM, and YUM
-
0:50
on the various other distros.
-
0:52
Mac OS X even has its own package manager called Homebrew
-
0:55
that you can install and use.
-
0:57
Let's learn the basics of using APT on our Ubuntu Linux console.
-
1:03
So we saw how to install a program from source.
-
1:05
We don't usually need to do that.
-
1:07
Instead we can use our package manager.
-
1:10
We used it briefly to install our initial build tools.
-
1:13
Now let's take a look at our tool in a little more depth.
-
1:16
APT or the advanced packaging tool is the package manager
-
1:21
we use on Ubuntu Linux, as well as some other distributions
-
1:25
of Linux based on Debian.
-
1:27
One of the first things that you should do is to run sudo apt-get update.
-
1:35
This command will update our local databases
-
1:38
of the available packages.
-
1:40
You'll want to run this every once in awhile.
-
1:43
This will make sure that our database has the complete list
-
1:46
of packages up to date including the most up-to-date versions.
-
1:50
If you attempt to install something
-
1:52
and you have not run update in awhile, you may find that packages
-
1:55
are unavailable because our local database is out of sync
-
1:59
with what's really available.
-
2:01
So it's a good idea to run sudo apt-get update every once in awhile.
-
2:05
Now you may have to type in your password
-
2:07
depending on how recently you've used the sudo command.
-
2:11
If it looks like this, everything should be up to date.
-
2:14
I'm going to go ahead and clear our screen.
-
2:16
So let's say I wanted to install the program Git.
-
2:20
Git is a version control system that is very popular
-
2:24
for managing the source code of our applications.
-
2:27
There should be a Git command on our system.
-
2:29
If we try to type it, we'll see a message come back
-
2:32
from our operating system saying,
-
2:34
"The program Git is currently not installed."
-
2:36
It's actually telling us how we can install Git using the APT system.
-
2:41
Sometimes when you try to run a command
-
2:43
that you don't have installed, it'll simply say it's not found.
-
2:45
But Ubuntu is a very friendly operating system,
-
2:48
and it recognizes that Git is a thing;
-
2:50
however, it's just not a thing it has installed,
-
2:53
so it gives us this nice little tip.
-
2:55
So if we wanted to find out how to install Git,
-
2:58
we could just listen to this prompt and type sudo apt-get install get.
-
3:03
But I want to show you how you can search for things
-
3:05
using the APT system.
-
3:07
We can use a program called APT-Cache.
-
3:11
And one of the commands that APT-Cache allows us to use is search.
-
3:16
And this allows us to search for packages based on a pattern.
-
3:20
So let's say we wanted to find the packages
-
3:23
that have the word Git in them.
-
3:25
Now there's quite a few of them, and if we want to scroll through
-
3:29
we can see what they all are with a brief description.
-
3:33
Now I'm pretty sure that the package that we're looking for is called Git.
-
3:37
But sometimes there's a specific package name
-
3:41
that may not be obvious to you,
-
3:43
so using a search like this can be useful.
-
3:49
Now once we've looked through the list of programs we want to install
-
3:52
and found what we're looking for, the apt-get install is what we'll use.
-
3:56
Let me clear our screen and we can run sudo apt-get install get.
-
4:06
Now it's given us a little bit of information
-
4:08
about what it's about to install.
-
4:10
One of the really nice features of a package manager
-
4:13
is that it understands the dependencies that programs have.
-
4:16
For instance, when we install Git, there are other tools
-
4:19
that it depends on in order to run.
-
4:22
Those tools we can see here are also the extra packages
-
4:25
that are also going to be installed.
-
4:27
It even gives us some suggestive packages
-
4:29
that will compliment the install that we're running nicely.
-
4:33
So it's saying we're about to install 3 new packages,
-
4:36
and it doesn't need to update or remove anything else.
-
4:40
It even gives us a little bit of information
-
4:42
about how much disk space is going to be used.
-
4:45
We have a confirmation here.
-
4:47
We can type in y to continue or n to cancel.
-
4:51
It looks good to me, so I'll hit y, and it's going to go ahead
-
4:54
and download it, install it, install all the documentation that we need,
-
4:58
and then we'll be done.
-
5:02
So if I type in clear, I can type in which git.
-
5:07
We can see that Git is now installed.
-
5:10
I can run Git, and it's giving me the help command,
-
5:14
and everything looks good.
-
5:18
Let's go ahead and clear the screen.
-
5:21
Now we've installed our software, but every once in awhile
-
5:24
we may want to make sure that we're keeping our software
-
5:26
up to date.
-
5:28
For instance, a new version of Git or any of the other tools
-
5:30
we have installed on our system may come out.
-
5:34
So it's good to periodically upgrade our packages.
-
5:38
In order to do this, we can run sudo apt-get upgrade.
-
5:44
This is a good program to run.
-
5:46
Not only to make sure we have all the latest features
-
5:48
of all of our packages, but there may be security updates
-
5:52
that are going to make our computer safer to use.
-
5:56
And we want to make sure we have all of the latest security patches.
-
5:59
This will allow us to do it.
-
6:01
So we're using the same apt-get command,
-
6:02
but now we're doing upgrade instead of install.
-
6:06
Now by fault it's going to upgrade the packages that it knows about.
-
6:10
You'll usually want to run the upgrade command
-
6:12
after you've done an update.
-
6:15
If we haven't updated our system,
-
6:17
it won't be aware of any new packages,
-
6:19
so run sudo apt-get update then sudo apt-get upgrade.
-
6:25
So again it's giving us a confirmation, and it's telling us
-
6:28
about all the things that is about to upgrade.
-
6:31
Some of the things it will not upgrade,
-
6:33
and some of the things it will.
-
6:35
And we can see there are quite a few packages
-
6:37
that are about to be upgraded.
-
6:39
There's 118 packages we're about to upgrade, and it didn't
-
6:41
require us installing any new ones or updating anything else.
-
6:45
It's telling us it's going to download about 70 megabytes,
-
6:48
but it's only going to increase our disk space by 610 kilobytes.
-
6:54
Again this all looks good to me, and so we can just go ahead
-
6:57
and hit y and run it.
-
7:00
Now since there are quite a few upgrades that are going to happen,
-
7:03
this command may take a little while to run.
-
7:06
But after we do, all of our packages will be up to date and ready to go.
-
7:12
And now our sudo apt-get upgrade has run,
-
7:15
and our packages are up to date.
-
7:17
Finally, a common thing you might want to do is uninstall the program.
-
7:21
To uninstall, we'll type sudo apt-get remove
-
7:28
and the name of the package.
-
7:30
Let's uninstall Git since that's what we most recently installed.
-
7:34
Now it's only going to remove the package that we named.
-
7:38
Remember those 2 packages that it installed because we installed Git?
-
7:43
Those 2 are not going to be uninstalled by just typing 'remove'.
-
7:47
In fact, it tells us this.
-
7:49
It says, "The following packages were automatically installed
-
7:51
but are no longer required once we remove Git."
-
7:55
Later we can run sudo apt-get autoremove to remove
-
7:59
any dependencies that were installed
-
8:02
by consequence of installing it on a package that is no longer needed.
-
8:06
It keeps track of this for us and knows that installed things like
-
8:09
git-man and liberror-perl because we installed another program.
-
8:15
Once we uninstall the program that required them,
-
8:17
it's able to automatically clean itself up
-
8:20
using the app-get autoremove command.
-
8:23
For us we really don't need to worry about it.
-
8:25
If we want to save on space, we can use the autoremove to do that.
-
8:29
But for now let's just worry about removing the Git package,
-
8:33
and not worry about it's dependency.
-
8:36
Again it confirms with us, and through it we'll just hit y and enter,
-
8:41
and it's going to remove the Git command from our system.
-
8:44
So if we type git, there is no such file or directory.
-
8:48
You'll notice that it has now changed to a different error message
-
8:51
than we used to have.
-
8:53
Before, it told us that we could install it with the apt-get install command;
-
8:58
however, now we get these normal cannot find usr/bin/git.
-
9:04
It's been removed.
-
9:06
If we ever want to have Git installed again,
-
9:08
we can simply do sudo apt-get install git, and it'll all work.
-
9:12
Now the packages can be used to install all sorts of things
-
9:16
from utilities like Git all the way up to things like servers like Apache,
-
9:21
databases like MySQL or even SQLite,
-
9:24
which we previously installed from source.
-
9:27
I recommend any time you need to install something,
-
9:29
checking to make sure it's available in your package manager.
-
9:33
It's much easier to install as well as manage.
-
9:36
And when you need to, it's also easier to uninstall
-
9:39
than if you had installed from source.
You need to sign up for Treehouse in order to download course files.
Sign up