1080*80 ad

Installing Perf on Ubuntu 18.04

How to Install Perf on Ubuntu: The Complete Guide

Are you a developer or system administrator looking to dive deep into application performance on Ubuntu? If so, the perf command is one of the most powerful tools in your arsenal. This Linux utility provides deep insights into your system’s performance, from CPU cycles to cache misses. However, getting it installed isn’t always as straightforward as a simple apt install.

Many users are met with a frustrating perf: command not found error, even after trying to install it. This guide will walk you through the correct way to install perf on Ubuntu and explain why the standard installation method often fails.

Why a Simple apt install perf Doesn’t Work

The core issue is that perf is not a standalone package but is tightly coupled with your specific Linux kernel version. Because it interacts directly with low-level kernel features for profiling, the version of perf you install must exactly match the version of the kernel you are running.

When you run a generic sudo apt install perf, the system doesn’t know which kernel-specific version you need, often leading to failure or the installation of a mismatched, non-functional tool.

Step-by-Step Installation Guide for Perf

Follow these simple steps to correctly identify your kernel version and install the corresponding perf tools.

Step 1: Find Your Current Kernel Version

First, you need to determine the exact version of the Linux kernel your system is using. Open a terminal and run the following command:

uname -r

This command will return a string that represents your kernel version. The output will look something like this (your version numbers will likely be different):

5.4.0-109-generic

Make a note of this version string, as you will need it for the next step.

Step 2: Install the Kernel-Specific Linux Tools

Now that you have your kernel version, you can install the correct package. The perf utility is included in a package named linux-tools that is specific to each kernel. The package name follows the format linux-tools-<YOUR_KERNEL_VERSION>.

You could manually type this out, but there’s a much more efficient and error-proof way. You can use the output of uname -r directly in your apt command.

Run the following command in your terminal to install the correct tools:

sudo apt update
sudo apt install linux-tools-$(uname -r)

This is the key command. The $(uname -r) part is automatically replaced by your system’s kernel version, ensuring you fetch and install the exact package you need. The system will ask for your password and then proceed with the installation.

Step 3: Verify the Installation

Once the installation is complete, you should verify that perf is installed and working correctly. You can do this by checking its version:

perf --version

If the installation was successful, you will see output confirming the perf version, which should correspond to your kernel version:

perf version 5.4.0-109

You are now ready to start using perf for performance analysis.

Important Considerations

  • Kernel Updates: If you ever update your system’s kernel, you will need to reinstall the corresponding linux-tools package. The old version of perf will no longer work with the new kernel. Simply re-run the sudo apt install linux-tools-$(uname -r) command after rebooting into your new kernel.
  • The linux-tools-common Package: You might see a package named linux-tools-common during installation. This package contains scripts that are common across different kernel versions, but it does not include the perf binary itself. You must install the kernel-specific package as shown above to get the actual tool.

By following this process, you can ensure a successful installation of perf and unlock a powerful suite of tools for optimizing your applications and understanding your system’s behavior at a granular level.

Source: https://kifarunix.com/installing-perf-performance-analysis-tool-on-ubuntu-18-04/

900*80 ad

      1080*80 ad