Software & AppsOperating SystemLinux

How To Install Linux Perf Tools on Ubuntu 20.04 LTS with WSL2

Ubuntu 20

In this article, we will walk you through the process of installing the Linux Performance Tools (perf) on Ubuntu 20.04 LTS using Windows Subsystem for Linux 2 (WSL2).


The perf tool is a powerful utility for performance analysis in Linux. It provides a wide range of functionalities to measure and analyze system and applications performance. However, installing perf on Ubuntu 20.04 LTS running on WSL2 can be a bit tricky due to certain kernel version mismatches. This guide will help you overcome these issues and get perf running smoothly on your system.


Before we begin, make sure you have the following:

  • A system running Windows 10 with WSL2 enabled.
  • Ubuntu 20.04 LTS installed on WSL2.
  • Sudo or root access to the Ubuntu system.

Step 1: Update Your Ubuntu Installation

First, it’s good practice to ensure your Ubuntu installation is up-to-date. You can do this by running the following commands:

sudo apt update
sudo apt upgrade

The sudo apt update command updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories. The sudo apt upgrade command will then upgrade all currently installed packages.

Step 2: Install Necessary Packages

Next, install the necessary linux-tools-generic and linux-cloud-tools-generic packages using the following command:

sudo apt install linux-tools-generic linux-cloud-tools-generic

These packages provide generic files for linux-tools and linux-cloud-tools.

Step 3: Check the Installed Kernel Version

To download the correct kernel headers, you need to know your installed kernel version. You can check this by running:

uname -r

The uname -r command will display your current kernel version.

Step 4: Download the Corresponding Kernel Headers

Once you have your kernel version, download the corresponding kernel headers from the official Ubuntu website. For example, if your kernel version is 5.4.72-microsoft, you can download the headers using the following command:


The wget command is a free utility for non-interactive download of files from the web.

Step 5: Install the Downloaded Kernel Headers

After downloading the kernel headers, install them using the following command:

sudo dpkg -i linux-headers-5.4.72-microsoft-standard_5.4.72-microsoft-standard-1_amd64.deb

The dpkg -i command is used to install a downloaded Debian (.deb) package.

Step 6: Install Perf

Now, you can install perf using the following command:

sudo apt install perf

The sudo apt install perf command will install the perf tool.

Step 7: Verify the Installation

Finally, verify the installation by checking the version of perf:

perf --version

If perf is installed correctly, this command will display the version of perf.


You have now successfully installed the Linux Performance Tools (perf) on Ubuntu 20.04 LTS using WSL2. Remember, WSL2 has limitations with hardware counters, so the results obtained from perf may not be as expected. For more information and alternative solutions, you can refer to the Stack Overflow post discussing this topic.

Happy performance analyzing!

Can I install `perf` on Ubuntu 20.04 LTS without using WSL2?

Yes, you can install perf on a native Ubuntu 20.04 LTS system without using WSL2. The process may be slightly different, but the steps mentioned in this article are specific to installing perf on Ubuntu 20.04 LTS with WSL2.

Can I use `perf` on other Linux distributions?

Yes, perf is available on most Linux distributions. The installation process may vary slightly depending on the distribution, but you can generally install it using the package manager specific to your distribution.

Can I use `perf` to analyze the performance of Windows applications running on WSL2?

No, perf is designed for analyzing the performance of Linux systems and applications. It may not work correctly or provide accurate results when used to analyze Windows applications running on WSL2.

Are there any alternatives to `perf` for performance analysis on Ubuntu?

Yes, there are several alternatives to perf for performance analysis on Ubuntu. Some popular alternatives include valgrind, strace, gprof, and sysstat. Each tool has its own strengths and weaknesses, so you may need to choose the one that best suits your specific requirements.

Can I use `perf` to analyze the performance of Docker containers running on Ubuntu with WSL2?

Yes, you can use perf to analyze the performance of Docker containers running on Ubuntu with WSL2. However, you may need to configure additional settings to enable the necessary permissions and access to the container’s resources. It is recommended to refer to the Docker documentation for more information on using perf with Docker containers.

Leave a Comment

Your email address will not be published. Required fields are marked *