How to Install and Use htop on Ubuntun 18.04 | DigitalOcean Community
In this tutorial, we’ll cover how to install and use the htop command line utility for monitoring system resources in real time on an Ubuntu 18.04 server. This tool provides more features than the classic top command, making it a great choice for managing resource usage over time or troubleshooting performance issues.
Step 1: Installing htop
To install htop, open up a terminal window by pressing Ctrl + Alt + T or searching for “Terminal” in the Activities Overview (the Super key). Once you have your terminal open, run this command to update your package list and then install htop:
#!/bin/bash
# This is a bash script for installing htop and updating package list
# The following command updates the package list using apt-get update
sudo apt-get update
# The && operator allows for multiple commands to be executed in one line
# The -y flag automatically answers yes to any prompts during installation
# The following command installs htop using apt-get install
sudo apt-get install htop -y
This will download and install the latest version of htop from the Ubuntu repositories. The `-y` flag tells Apt to automatically answer “yes” to any prompts that may appear during installation, making it a one-liner command.
Step 2: Starting htop
Once you’ve installed htop, let’s start it up! You can do this by running the following command:
#!/bin/bash # This line specifies the interpreter to be used for executing the script, in this case, bash.
sudo apt-get install htop -y # This line uses the `apt-get` command to install htop from the Ubuntu repositories, with the `-y` flag to automatically answer "yes" to any prompts.
htop # This line starts htop, a system monitoring tool.
This will launch htop in your terminal window and display a real-time view of your system resources. The first time you run htop, you may see some warnings or messages about configuration files not being found. Don’t worry; these are harmless and can be safely ignored.
Step 3: Navigating htop
Now that we have htop running, let’s take a look at its interface. The default view shows the top five processes by CPU usage, with their respective PIDs (process IDs), memory usage, and other information. You can navigate through this list using your arrow keys or Page Up/Page Down to scroll up and down.
To see more detailed information about a specific process, press F4 to enter “Edit” mode. This will allow you to modify the columns displayed in htop’s view. To exit Edit mode, simply press Enter.
Step 4: Customizing htop
One of the great things about htop is its flexibility and customization options. You can add or remove columns based on your needs by pressing F2 while in Edit mode. This will bring up a menu that allows you to select which columns are displayed, as well as their order.
To sort processes by a specific column (such as CPU usage), press Shift + F8 and then use the arrow keys or Page Up/Page Down to navigate through the available options. Once you’ve selected your desired column, htop will automatically reorder its view based on that column.
Step 5: Exiting htop
When you’re done using htop, simply press Ctrl + C to exit and return to your terminal window. This is a great way to monitor resource usage over time or troubleshoot performance issues in real-time.
Conclusion
You now know how to install and use htop on Ubuntu 18.04. With its customizable interface, detailed information about processes, and real-time monitoring capabilities, htop is a powerful tool for managing your system’s resources.
In the context of troubleshooting server issues, htop can be used to identify resource bottlenecks or other performance problems by providing real-time data on CPU usage, memory utilization, and disk I/O. By monitoring these metrics over time, you can identify trends that may indicate underlying issues with your system’s configuration or hardware.
In addition to htop, there are several other tools available for troubleshooting server issues in real-time:
1. top The classic tool for monitoring resource usage on Unix and Linux systems. It provides a dynamic view of the most CPU-intensive processes running on your system, as well as information about memory utilization and swap activity.
2. iostat A command line utility that displays statistics about disk I/O performance over time. This can be useful for identifying slow or bottlenecked disks, which may indicate issues with hardware configuration or file system fragmentation.
3. sar Another tool for monitoring resource usage and performance metrics on Unix and Linux systems. It provides a historical view of CPU utilization, memory usage, disk I/O, and other statistics over time intervals that you specify.
4. sysstat A suite of tools for system monitoring and analysis, including iostat, sar, and mpstat (for monitoring processor performance). These tools can be used to identify trends in resource usage over time, which may indicate underlying issues with your system’s configuration or hardware.
5. lsof A command line utility that displays information about open files and network connections on Unix and Linux systems. This can be useful for identifying processes that are consuming large amounts of resources (such as disk I/O) by opening and reading large files, or for troubleshooting networking issues by displaying the current state of all active network connections.
By using these tools in combination with htop, you can gain a more comprehensive view of your system’s resource usage and performance metrics over time, which can help you identify underlying issues and optimize your system’s configuration for better performance.