How to Install and Use Htop in Linux? [3 Best Methods to Install]

Written by

Reviewed by

Last updated: May 8, 2024

Expert verified

SVG Image

TL;DR

To effectively install htop on Ubuntu, follow these steps:

  1. Open your Terminal and update the package list with sudo apt update.
  2. Install Htop by running sudo apt install htop and wait for the installation to complete.
  3. Launch Htop by typing htop in your terminal and pressing Enter.

Here is how to effectively use htop in Linux:

  1. Navigate processes using the Up/Down arrows and sort them with F6 or > based on criteria like CPU or memory.
  2. Manage processes by searching with F3, killing with F9, or adjusting priority with F7 (to increase) or F8 (to decrease).
  3. Customize Htop’s appearance through the setup menu with F2 to modify columns and colors and exit with F10 or q.

Ever feel like you’re juggling too much trying to keep track of all the processes on your Ubuntu system? You’re definitely not the only one! It can be quite overwhelming, but luckily, there’s a handy tool called Htop that can simplify things for you. In this post, I’m excited to show you how to install and use Htop in Linux. I’ll start with the basics, like updating your package list, and move on to how you can tweak Htop’s settings to suit your needs. Plus, I’ll share some handy troubleshooting tips to help you smooth out any bumps along the way. Let’s get started and make system management a breeze!

What is Htop?

Htop is an interactive system-monitor process viewer. It is a more advanced and user-friendly replacement for the traditional top command found in Unix-like systems. Htop offers many enhancements, which make it easier for users to monitor and manage their system’s resources effectively.

Key Features of Htop

  • Interactive UI: Htop provides a colorful and interactive interface, which is navigable using keyboard shortcuts. This makes it more accessible than top, which is primarily command-driven.
  • Real-time Metrics: It updates system metrics in real-time, allowing users to see their system’s current state without delays.
  • Customizable Displays: Users can choose which columns to display, reorder them, and sort processes according to various parameters like CPU usage, memory usage, process ID, etc.
  • Easier Process Management: Htop allows users to manage processes directly from the interface. Tasks like killing, renicing (changing priority), or tagging multiple processes are simpler and do not require typing PID manually.

How Htop Works

When you launch htop, it presents a dashboard divided into three key areas:

  1. Header: Shows overall system metrics such as CPU, memory (RAM), and swap usage. Each CPU core can have its own graph, showing the load on each core individually.
  2. Body: Lists all running processes. Each process is displayed with details like user, priority, CPU usage, memory usage, and command line.
  3. Footer: Offers a menu for interactive commands, which are executed using function keys.

Getting Started with Htop

To start using htop, you can install it from your Linux distribution’s package manager. For example, on Debian-based systems, you would use:

sudo apt install htop

Once installed, simply type htop in your terminal to launch the viewer.

How to Install Htop on Ubuntu?

To install htop on Ubuntu, open your terminal and first update your package list by running sudo apt update. Then, install htop by executing sudo apt install htop. Once the installation is complete, you can verify it by typing htop into the terminal, which will launch the interactive process viewer, displaying your system’s current processes and resource usage. This method uses Ubuntu’s default package manager, APT, which is straightforward and efficient for managing software installations and updates.

That was a quick overview of one method to install Htop on Ubuntu. If you want to explore more methods and the step-by-step guide for each method to install htop on Ubuntu, read the guide below:

1. Using APT (Advanced Package Tool)

The most straightforward way to install htop on Ubuntu is through the APT package manager, which is used by default in Ubuntu and other Debian-based distributions. Here is the step-by-step guide to install htop using this method:

  1. Open your command prompt by pressing Ctrl + Alt + T.
open terminal
  1. Before installing Htop, run the following command to to update the package list:
sudo apt update

It will update your package repository list to ensure you install the latest version available

updating system package lists
  1. Ubuntu includes Htop in its default repositories, making it straightforward to install using the apt package manager. To install Htop, run the following command:
sudo apt install htop

Wait for the installation to complete.

installing htop on ubuntu

2. Using Snap

Snap packages offer a universal, sandboxed software environment that ensures consistency across different Linux distributions. This method is suitable for users looking for easy updates and cross-platform compatibility. Follow these steps:

  1. To install htop using the Snap package manager, run the command:
sudo snap install htop

Downloads the htop snap package and installs it, including all necessary dependencies and configurations.

installing htop using snap

3. Compiling from Source

This method involves downloading the source code and compiling it manually, which is useful if you need the latest version or specific customizations. Here is the step-by-step guide to install htop using this method:

  1. Access your Terminal and start by installing the necessary dependencies for building htop:
sudo apt install build-essential automake libncurses-dev

Installs compilers, libraries, and other tools needed to build software from source.

installing necessary libraries for htop
  1. Now download the latest source code of htop:
wget https://github.com/htop-dev/htop/archive/refs/tags/3.1.2.tar.gz

Download the tar.gz file containing the source code to your system.

downloading source code for htop
  1. Extract the downloaded file:
tar xvf 3.1.2.tar.gz

Extracts the contents of the tar.gz file into a folder.

extracting tar file
  1. Change to the source directory using the command:
cd htop-3.1.2

Changes the current directory to the htop-3.1.2 directory.

changing directory to htop directory
  1. Now prepare source code for compilation:
./autogen.sh
preparing source code for compilation
  1. Now run the following command:
./configure
setting build configuration

Sets up necessary build configurations and checks for required dependencies.

  1. Compile the program by running the command:
make

Compiles the source code into executable binaries.

building htop application from source code
  1. Now Install the compiled program:
sudo make install

Copies the built program into the appropriate directory (usually /usr/local/bin).

copying program files to appropriate directory

How to Use htop command in Linux?

To use htop command in Linux, open your terminal and type htop, then press Enter. This displays an interactive overview of your system’s processes and resource usage. Use arrow keys to navigate and F3 or / to search for processes. You can manage processes by selecting them and pressing F9 to kill or F7 and F8 to adjust their priority. For more options and customization, press F2 to access settings, and F1 for help.

Here is the step-by-step guide to use the htop command in Linux:

  1. Once Htop is installed, you can launch it very simply through the command line. In your terminal, type:
htop

Press Enter, and Htop will open.

launching htop in ubuntu
  1. When you first open Htop, you will see a colorful display showing your system’s resource usage: 
htop interface
  1. There will be CPU, MEM, and SWP Bars along with a list of processes:
    • CPU Bars: These are displayed at the top of the htop screen and show the utilization of each CPU core. Each bar represents the percentage of time the CPU is being used. The color coding within the bars often indicates different types of CPU activity: user processes, system processes, low-priority processes, and idle time. This helps you quickly see how much of your CPU’s capacity is in use and by what types of processes.
    • Memory (RAM) Bar: This bar indicates how much of your physical memory (RAM) is currently in use versus how much is free. It usually divides the usage into used memory and buffer or cached data. The visual representation helps you understand how much memory is actively being used by applications, as opposed to being reserved by the system for temporary caches and buffers.
    • Swap Bar: The swap bar shows how much of your swap space is being utilized. Swap space is a portion of your hard disk drive that is used to extend your RAM, allowing more applications to run when the physical RAM is full. It’s generally slower than RAM, so high swap usage can indicate that you might need more RAM or need to close some applications to improve system performance.
purpose of top bars at the top in htop
  1. Below the resource usage bars, you’ll see a list of all running processes.
list of running processes in htop
  1. Use the Up/Down arrow keys to scroll through the list of processes.
navigate through processes using arrow keys
  1. Press F6 or >, and you’ll see a list of criteria by which you can sort the processes (e.g., CPU, MEM). Select your desired criterion, and the process list will reorder.
sorting processes by desired criteria
  1. Press F3, and start typing to search for a process by name.
searching a process in htop
  1. Highlight a process with the arrow keys, then press F9
killing a process in htop
  1. You’ll be prompted to choose a signal to send to the process. The default is SIGTERM, which gracefully stops a process. Press Enter to send the signal.
confirm to kill a process
  1. To change the priority of a process, highlight a process, press F7 (to increase priority) or F8 (to decrease priority). This changes the niceness (priority) of the process affecting its priority.
increase or decrease the priority of a process
  1. Press F2 to enter the setup menu. Use the arrow keys to navigate to Columns and press Enter. Here you can choose which columns to show or hide.
show or hide column in htop
  1. Still in the setup menu, go to Colors to customize the color scheme.
changing color scheme in htop
  1. To exit Htop, simply press F10 or q.
exiting htop

Troubleshooting Common Htop Installation and Usage Errors

When installing and using Htop on Ubuntu, you might encounter some issues. By addressing these issues, you can minimize disruptions and make full use of Htop for monitoring and managing your Ubuntu system’s resources. Here’s how to solve five common problems, making your experience smoother and more efficient:

  • 🛠 Htop Not Found After Installation: If you receive a “command not found” error after installing Htop, it’s likely your shell hasn’t recognized the new installation. Refresh your terminal session by closing and reopening it, or explicitly reload your PATH with source ~/.profile. This tells the shell to recheck its environment.
  • 📦 Package htop has no installation candidate: This error indicates that your package lists are outdated or corrupted. First, ensure your package sources are correct and that your system is connected to the Internet. Update your package lists with sudo apt update, then try installing again. If the issue persists, check your /etc/apt/sources.list for correct repository entries.
  • 🔄 Inconsistent Terminal Display: If Htop’s display looks messy, it could be due to your terminal’s font or encoding settings not supporting certain characters. Try switching to a different terminal emulator like GNOME Terminal or Xterm, or adjust your current terminal’s font settings to a more compatible option, such as DejaVu Sans Mono.
  • 🔒 Permission Denied: Encountering permission denied error during the installation of Htop typically means that the user does not have the necessary administrative privileges. Ensure you are using sudo when installing Htop to grant administrative rights for the installation. If you’re not in the sudoers file, you’ll need to ask your system administrator to either install Htop for you or grant you sudo access.
  • 🌐 Unable to Fetch Package: If your system cannot download the Htop package, it could be due to network issues or repository problems. Verify your internet connection is active and stable. If you are connected but still cannot download, your repository list might be pointing to an unavailable or outdated server. Try switching to a different repository in your sources.list or using a mirror closer to your geographical location.

Final Thoughts

In this guide, I’ve shown you how to install and use Htop on Ubuntu, providing a clear, step-by-step approach to managing your system’s processes efficiently. If you encounter any issues, the troubleshooting tips I included should help you keep everything running smoothly. This knowledge is crucial for maintaining a healthy and responsive system.

If you want to improve your skills in system management and optimization on Linux, explore topics like clearing the Apt cache to manage package storage efficiently, creating desktop shortcuts on Ubuntu for better workflow, and using the Vim page down and up controls to enhance file editing directly in your terminal. These skills will nicely complement your proficiency with Htop, boosting your overall system management capabilities.

Frequently Asked Questions

  1. Can Htop be used remotely to monitor servers?

    Yes, you can use Htop remotely to monitor servers. To do this, simply connect to your server via SSH and run the Htop command just as you would on your local machine. This method provides real-time monitoring of server processes from anywhere.

  2. What are the security considerations when using Htop?

    Security-wise, using Htop involves potential risks because it often requires root privileges to view all processes. Ensure that only authorized users have root access to minimize security risks. Regularly updating your system and Htop can also help protect against vulnerabilities.

  3. Can Htop display disk I/O stats, and if so, how can I enable this feature?

    Yes, Htop can show disk I/O statistics. To enable this feature, open Htop, press F2 to enter the setup menu, navigate to the Columns section, and enable the IO_RATE and IO_READ_RATE or IO_WRITE_RATE options. This will allow you to see the disk read and write rates for each process.

  4. Is it possible to export Htop data for later analysis, and what are the steps?

    Htop doesn’t directly support exporting data, but you can save the current display by running Htop in batch mode. Use the command htop -b > filename.txt to write the output to a text file. This file will contain a snapshot of the processes at the time of export.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Install Intel Graphics Driver on Ubuntu Linux? [12 Simple Steps]

Next Post

How to Get All Keys in Redis Using Command Line Interface? [2 Best Methods]

Read next