How to install perf on Ubuntu 18.04?

5,409

Solution 1

The output of cat /etc/apt/sources.list was quite short, containing only two non-blank lines. It revealed that /etc/apt/sources.list has the bionic repository but is missing the bionic-updates and bionic-security repositories, which are typically present and enabled.

Adding them should fix the problem. The package you're trying to install, linux-tools-4.18.0-21-generic, is provided in bionic-updates.

Since all official updates to stable releases are released through the -security and -updates repositories, you may find a number of updates available for installation. It's a good idea to install those, unless you have a specific and important reason not to do so.

You can enable those repositories with the add-apt-repository command or with either of the methods summarized below. Or you may want to follow one of the procedures given at How do I restore the default repositories?

Graphically

If your system has a graphical desktop installed, you can run the Software & Updates tool and enable them from there. To do that:

  1. Open Software & Updates.

  2. Click the Updates tab.

  3. Under "Install updates from:" make sure these boxes are checked:

    • Important security updates (bionic-security)
    • Recommended updates (bionic-updates)


    For this purpose, it doesn't matter much whether or not the "Unsupported updates" box is checked. Most users will generally prefer not to enable that repository.

    You may need to enter a password to change those settings. That's normal.

  4. Click Close.

  5. You will be told, "The information about available software is out-of-date." Click Reload.

  6. You should now be able to install the linux-tools-4.18.0-21-generic package. Go ahead and attempt to do so.

Manually, by editing /etc/apt/sources.list

If you have no GUI or prefer to manually edit /etc/apt/sources.list, you can do so. Normally I would recommend backing up the file you have, but what you have doesn't contain very much. Still, if you want to you can do so by running sudo cp /etc/apt/sources.list{,.bak}. You can then edit the file. It's owned by root; I suggest editing it with sudoedit. You can run:

sudoedit /etc/apt/sources.list

If you have a specific editor you prefer sudoedit to use, you can specify that. For example, to use nano even if that's not the default, you could run this instead:

VISUAL=nano sudoedit /etc/apt/sources.list

After editing, the contents of your /etc/apt/sources.list file should look like:

deb http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates main universe restricted multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-updates main universe restricted multiverse
deb http://security.ubuntu.com/ubuntu/ bionic-security main universe restricted multiverse
deb-src http://security.ubuntu.com/ubuntu/ bionic-security main universe restricted multiverse

The lines that start with deb-src provide source code packages. Including them may make sudo apt update take slightly longer each time it is run, but does not incur any other significant overhead. Still, if you don't want to able to download source code automatically through the package manager, you can comment them out (by placing a # at the beginning of each line you wish to deactivate) or even omit them. You can (re)enable them later.

You may want to use a mirror instead of the master site, to get faster downloads. For example, the main US mirror would be used if you wrote us.archive.ubuntu.com instead of archive.ubuntu.com. Your current deb and deb-src lines don't use one, so I didn't either in what I wrote above. I mainly mention this to point out that if you do decide to use one, you should still keep the URLs in the http://security.ubuntu.com/ubuntu/ lines unchanged.

Solution 2

The correct command to install linux-tools for actually used kernel (from official repository) is:

sudo apt install linux-tools-`uname -r`
Share:
5,409

Related videos on Youtube

Anubhav Dinkar
Author by

Anubhav Dinkar

Updated on September 18, 2022

Comments

  • Anubhav Dinkar
    Anubhav Dinkar over 1 year

    I have tried to install perf using sudo apt-get install linux-tools-$(uname -r) linux-tools-generic

    It gives an error saying:

    Reading package lists... Done 
    Building dependency tree 
    Reading state information... 
    Done E: Unable to locate package linux-tools-4.18.0-21-generic 
    E: Couldn't find any package by glob 'linux-tools-4.18.0-21-generic' 
    E: Couldn't find any package by regex 'linux-tools-4.18.0-21-generic' –
    

    (EDIT)

    I did run sudo apt-get update and sudo apt-get upgrade before running the above command, but I still get the same error message as above.

    I ran cat /etc/apt/sources.list and got the following message:

    deb http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse
    
    deb-src http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse #Added by software-properties
    

    uname -a yields: Linux ubuntu 4.18.0-21-generic #22~18.04.1-Ubuntu SMP Thu May 16 15:07:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    output of apt list 'linux-tools-*'

    output of apt list --installed 'linux-*'

    • Anubhav Dinkar
      Anubhav Dinkar almost 5 years
      Apologies. I have made those edits
    • Eliah Kagan
      Eliah Kagan almost 5 years
      Thanks. The output of cat /etc/apt/sources.list shows you don't have either of the repositories that provide updated software enabled. I've posted an answer.
  • Anubhav Dinkar
    Anubhav Dinkar almost 5 years
    I get the same error message even when I run this command
  • mariaczi
    mariaczi almost 5 years
    Please put here the output with this error. "`" is from the tilda key.
  • Anubhav Dinkar
    Anubhav Dinkar almost 5 years
    Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package linux-tools-4.18.0-21-generic E: Couldn't find any package by glob 'linux-tools-4.18.0-21-generic' E: Couldn't find any package by regex 'linux-tools-4.18.0-21-generic'
  • Anubhav Dinkar
    Anubhav Dinkar almost 5 years
    I wasn't able to add a line-break for some reason, sorry for the formatting of the comment
  • mariaczi
    mariaczi almost 5 years
    Do you have enabled updates repository for your ubuntu release? Did you do apt get update before?
  • Anubhav Dinkar
    Anubhav Dinkar almost 5 years
    Yes, I did, and it still gives the same error message
  • mariaczi
    mariaczi almost 5 years
    Which one of mirror server you use? Maybe it is a problem with them. Please look here: ubuntu.task.gda.pl/ubuntu/pool/main/l/linux The package for which you are looking for is available. Btw. Your and my command are correct. Both works well for me.
  • Anubhav Dinkar
    Anubhav Dinkar almost 5 years
    Great Answer! Works like a charm. Thanks!