To learn how how to install new programs on your Linux machine we will start by examining a preinstalled program called top.
The program top provides a real time dynamic view of resource usage and currently running processes. It can be invoked by the command top on the command line.
Typing top into the command line of your terminal starts the top application. The upper part is a summary of resource usage and the bottom part under the black line in the screenshot is the running processes.
You even see here that the user, ec2-user , is running top because I am! The top part is showing me a summary of how many processes are running, how much CPU I am using and how much memory is available and being used, and the bottom part is breaking the usage out by each process. Pretty awesome.
If you played along and you now have this list of processes running on your Linux machine, you will want to get back to the command line prompt by simply typing “q” for quit.
This is not an exhaustive tutorial on top. The top program is used here so I can show you a few things that will help you when you install your first program on your Linux machine or EC2 instance.
OK I will show you one top specific command.
$ top -a
will sort the top process list by memory so you can see which processes are taking up the most memory. This is very important in server management.
In the command top -a the command is top and -a is an option you can set on the command. You can find options by reading the documentation on top.
Let’s explore top a little bit. This program came prepackaged but where is top “installed”? Another way to ask that is, “where is top’s executable binary?”
Linux has a few other commands that can help us answer that questions.
We have three pretty good options:
- whereis locates the source, binary and manuals sections for specified files
- which locates the executable file associated with a given command
- find searches for files in a directory hierarchy
You might be thinking, I thought this tutorial was about installing new programs on a Linux machine. It is! Bear with me. I am hopeful the stuff I am explaining will save you a lot of headache in the future.
The goal of this tutorial is to install your first program on your Linux machine. We can get into specifics later let’s actually do what we came to do.
To install our first program, htop, we are going to use the package manager, yum. Htop is a interactive process viewer for Linux like the preinstalled top, but is a bit more visual and provides more information than top. Htop is a great system monitor.
$ sudo yum install htop
Now simply type htop into the command line.
$ which htop
You can see that htop is the in the same directory, /usr/bin/, as top.
When we check the permissions of htop we see that the two executables have the same permissions, group and users.
ls -la htop top
-rwxr-xr-x 1 root root 121312 Jul 24 2013 htop
-rwxr-xr-x 1 root root 58400 Mar 17 2015 top
The permissions read -rwxr-xr-x
Read Write Execute
Read – Execute
Read – Execute
So any user on the system can execute this file.
$ echo $PATH
usr/bin is in your path so you can execute htop simply by running the command htop anywhere by any user in the system.
Analyzing the permission, groups, owner and path will be important in running programs after you install them.