How do I install the perf
monitoring tool?

- 487

- 4,711
-
2What exactly do you want to monitor? – ddeimeke Jun 23 '11 at 07:31
-
10@ddeimeke that seems like an irrelevant question. – abcd Oct 16 '15 at 17:20
-
@ddeimeke it doesn't matter – SmallChess Jul 28 '18 at 00:47
12 Answers
On Ubuntu I had to install three packages:
apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

- 1,569
-
7When I tried it, just using
sudo apt-get install linux-tools-common linux-tools-generic
(skipping the part, which depends on the kernel version) was sufficient. – Martin R. Jun 29 '15 at 22:17 -
8@Martin-R linux-tools-generic always points at the tools for the most up to date kernel version. When running an older kernel (e.g. a server with a couple months uptime) if you want perf without rebooting to the newer kernel you have to explicitly install the tools paired with that kernel (hence the
uname -r
shell expansion). – notpeter Jun 30 '15 at 06:09 -
sudo apt-get update sudo apt-get -y install linux-tools-common linux-tools-generic linux-tools-
uname -r
– dylanninin Jun 19 '16 at 03:10 -
4
-
2E: Unable to locate package linux-tools-5.5.* what can be done to run perf on kernel 5.5? – txs Feb 05 '22 at 01:04
-
I too kept getting the "Unable to locate package linux-tools-..." message and nothing helped me fix it until i followed the first part of this answer and then came back to this answer and tried it again – MilesStanfield Dec 25 '23 at 16:09
-
The perf
utility can be found in the linux-tools
package.

- 443

- 41,136
-
17You also probably want to install linux-tools-generic since it includes kernel modules that perf interacts with. – Allen Sep 06 '14 at 21:59
-
1
-
Also, if (like me) you have HWE installed, you'll need to install
linux-tools-generic-hwe-$version
(linux-tools-generic-hwe-20.04
is what I have currently). – pizzapants184 Mar 08 '22 at 02:15
Make sure you are installing this tool for the right Kernel release. If you just type:
sudo apt-get install linux-tools
It will install it for the latest Linux release in your machine and in case you are booting a previous version (say for stability reason), it will err. In my case it installed for .45 instead of .43 and I had to use the following command to install it:
sudo apt-get install linux-tools-3.2.0.43
You can find your Kernel release by typing :
uname -r
To make sure it's working right you can try this:
perf record /bin/ls

- 1,569

- 4,545
- 21
- 68
- 99
To get the latest version of perf irrespective of the kernel version (perf version is independent of the kernel version):
git clone --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux/tools/perf
make
cp perf /usr/bin
perf --version
to check the current version
-
3Build deps for reference
apt-get install build-essential git flex bison
– Matthias Kuhn Aug 24 '21 at 11:01 -
2This is the right answer if your using a newer kenel. All the answer referring to using dpkg, and apt downloads are dependent on if dpkg repos have access to perf based on your kernel version. Running the latest Ubuntu image 21.04 with a kernel of 5.11, perf does "install" after using dpkg to download, however when trying to run
perf -h
you will be prompted withWARNING: perf not found for kernel 5.11.0-41
(or which ever newer kernel you have that perf is not apart of). Had to literally compile the tool from linux-tools manually. – Dave Feb 08 '22 at 15:26 -
that worked to install - but it seems to be installing a different version - it doesn't support
perf trace
– stason Apr 04 '23 at 05:10 -
-
it's installing 6.3.x as of this writing. it looks like v6 dropped
trace
, it's there in v5.I also very much doubt that v6
perf
would work on kernel 5.x.may be could add to your answer to suggest to check that the same major version is used as the actual kernel?
– stason Apr 04 '23 at 17:02
Ubuntu:
sudo apt install linux-tools-common
https://packages.ubuntu.com/eoan/linux-tools-common
Debian:
sudo apt install linux-perf

- 2,326
In 14.04, the linux-tools
package does not exist unqualified:
$ sudo apt-get install linux-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package linux-tools is a virtual package provided by:
linux-tools-virtual 3.13.0.36.43
linux-tools-lowlatency 3.13.0.36.43
linux-tools-generic-lts-trusty 3.13.0.36.43
linux-tools-generic-lts-saucy 3.13.0.36.43
linux-tools-generic 3.13.0.36.43
You should explicitly select one to install.
E: Package 'linux-tools' has no installation candidate
Instead, you can install one of the packages listed, depending upon the kernel you have installed. Most users will want linux-tools-generic
.

- 5,708
-
For Ubuntu 22.04, this is the correct answer. It will bring in
linux-tools-common
and the specific package for your current kernel version automatically. – davidA Mar 16 '23 at 23:12
On ubuntu "perf" is a shell script that calls a kernel specific perf binary.
But that's not actually needed, perf is compatible. Just remove the wrapper from /usr/bin and copy any of the perf binaries from ./lib/linux-tools* to it.

- 81
-
that worked - thank you! You could call directly
sudo /usr/lib/linux-tools-5.15.0-67/perf trace date
- trylocate /lib/linux-tools | grep perf
to find which version you may have. – stason Apr 04 '23 at 05:07
I installed Linux 3.17.2 on my machine and tried
sudo apt-get install linux-tools-3.17.2
it showed that linux-tools is not present. In this case, download the required linux kernel version, go to linux->tools->perf :
cd linux/tools/perf
and then run make command :
make
and then run make install command:
make install
and then reboot. You just installed perf manually.

- 197,895
- 55
- 485
- 740
-
Reboot is not necessary. Also, if you are to compile from the source code; linux-tools-3.17.2 should not be necessary – Chang Hyun Park Oct 19 '16 at 10:03
Running the following two commands will do it!
sudo apt-get install linux-tools-common
sudo apt-get install linux-tools

- 13,416

- 273
-
Doesn't work. I'm using 12.04. I get the error perf not found for kernel 3.2.0-60. You may need to install linux-tools-3.2.0-60-generic – Rishi Dua Mar 10 '14 at 18:54
-
Here's how it worked for me On Ubuntu 18.04:
After Command 'perf' not found
, it suggested to install with sudo apt install linux-tools-common
. Doing so and trying to run perf
afterward still resulted in:
WARNING: perf not found for kernel 4.15.0-39
You may need to install the following packages for this specific kernel:
linux-tools-4.15.0-39-generic
linux-cloud-tools-4.15.0-39-generic
You may also want to install one of the following packages to keep up to date:
linux-tools-generic
linux-cloud-tools-generic
I decided for sudo apt-get install linux-tools-generic
and this was enough.
In case you run into permission-error when trying to use perf
as non-root, look here:

- 121
-
I got the same warning. But then I ran the command you suggested and I still get the same warning. – Caleb Stanford Mar 20 '19 at 21:40
-
-
1@6005 Thx for the feedback, I don't have an idea why you experienced a different behaviour, though. – Darkonaut Mar 20 '19 at 21:47
-
This happens because the package your are downloading from the dpkg repo was never compiled for your newer kernel version. So the logic builds a binary that just runs this output. You must do what @bodha suggested. Even after compiling, you need to remove or move these binaries where ever they are based on your path, and replace with the compiled binary you made. You will need to do a lot of
which perf
to find out where they all are. – Dave Feb 08 '22 at 15:28
For debian 9.11 (Stretch)
sudo apt-get install linux-perf-4.9
https://packages.debian.org/stretch/linux-perf
You might need to do an
apt-get update
before.

- 111