Linux headers to build package

Как установить заголовочные файлы ядра в Linux

Когда вы компилируете драйвер устройства как модуль ядра, вам необходимы установленные заголовочные файлы ядра. Также они требуются, если вы собираете пользовательское приложение, которое взаимодействует напрямую с ядром. При установке заголовочных файлов ядра, необходимо убедиться, что их версия совпадает с версией ядра установленного в системе.

Если версия вашего ядра не менялась после установки дистрибутива, или вы обновляли его с использованием системного менеджера пакетов (то есть apt-get, aptitude или yum) из системных репозиториев, то заголовочные файлы вы также можете установить с помощью пакетного менеджера. Однако если вы скачивали исходный код ядра и компилировали его самостоятельно, то заголовочные файлы необходимо устанавливать с помощью команды make.

Здесь мы предполагаем, что ваше ядро установлено из основного системного репозитория вашего дистрибутива, и вы хотите установить соответствующие заголовочные файлы ядра.

Установка заголовочных файлов ядра в Debian, Ubuntu или Linux Mint

Если вы не компилировали ядро вручную, то можете установить соответствующие заголовочные файлы ядра с помощью команды apt-get.
Сначала проверьте, не установлены ли уже требуемые заголовочные файлы с помощью команды:

Теперь установите заголовочные файлы, как показано ниже.

Проверьте, что установка прошла успешно.

По умолчанию в Debian, Ubuntu или Linux Mint заголовочные файлы находятся в /usr/src.

Установка заголовочных файлов ядра в Fedora, CentOS или RHEL

Если вы не обновляли ядро вручную, то можете установить соответствующие заголовочные файлы ядра с помощью команды yum.
Сначала проверьте, не установлены ли уже требуемые заголовочные файлы. По умолчанию заголовочные файлы ядра расположены в /usr/src/kernels/.
Если подходящих заголовочных файлов не установлено, вы можете установить их с помощью команды yum. Она автоматически найдет подходящий пакет.

Если заголовочные файлы ядра, установленные с помощью вышеприведенной команды, не соответствуют установленному в системе ядре, значит оно устарело. В этом случае обновите ядро системы до последней версии с помощью приведенной ниже команды. После обновления необходимо перезагрузить систему.

Теперь проверьте, что установлены заголовочные файлы соответствующей версии с помощью команды:

Источник

Правильная инструкция по установке linux-headers в Debian Stretch. uname -r|sed ‘s/[^-]*-[^-]*-//’ — работает неправильно?

(uname -r|sed ‘s/[^-]*-[^-]*-//’) — что вот это вот делает?

Но почему apt-get устанавливает linux-headers откуда-то отсюда:

Или нужно при установке обязательно указывать часть backports?

apt-get install -t stretch-backports linux-headers-`uname -r`

Я читал это, но не понял что вот это делает: (uname -r|sed ‘s/[^-]*-[^-]*-//’)? uname -r — понятно, но sed.. ‘s/[^-]*-[^-]*-//’)?!

Заменяет последовательность «[не минусы]минус[не минусы]минус» на пустую строку

Кстати, можно было написать uname -r | cut -d- -f3 , но люди почему-то любят использовать sed для всего.

Можно, но пока нет

А как желательно писать при установку пакетов для архитектуры процессора amd64?

apt-get install linux-image-amd64

apt-get install linux-image-$(uname -r|sed ‘s/[^-]*-[^-]*-//’)

Зачем это всё, когда есть мета-пакеты? Поставил мета-пакет и у тебя всегда будет актуальная версия ядра и хедеров после обновления.

для amd64 одинаково, но это-то заклинание именно такое, чтобы не задавать новичку лишний раз вопрос об архитектуре системы, чтобы работало везде.

замудрено больно, мне проще посмотреть что там есть вкусного

и потом полностью указать желаемое

Зачем это всё, когда есть мета-пакеты?

И какой мета-пакет нужен мне?

мне проще посмотреть что там есть вкусного

Ещё есть apt-cache policy

uname -r | cut -d- -f3-

linux-image-amd64 linux-headers-amd64 — если для обоих указать backports, то так и поставятся.

Вместо того, чтобы в гугле на первой странице найти ответ на вопрос, ты лезешь на форум спрашивать. Нет предела тупости.

А ну я уже поставил этот мета-пакет. Осталось только найти 5 пакетов для 390 драйвера. А эта установка мета-пакетов тоже нужна из backpor’ов насколько я понял.

Такой подход не всегда нужен. Иногда надо установить определённую версию, а не последнюю в случае указания мета-пакета.

Читайте также:  Отключение запроса пароля windows 10 при выходе

Так для меня актуально ядро 4.17, а не 4.18, на который указывает мета-пакет.

в таком случае проще поставить нужную версию, чем колупать sed.

Правильная инструкция по установке linux-headers

Источник

Debian / Ubuntu Linux Install Kernel Headers Package

I need kernel headers to compile module for vmware tools or Virtualbox guest. How do I install the Linux kernel headers on Debian or Ubuntu Linux operating systems using command line options?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 5m

You can easily install the Linux kernel headers for currently running kernel version using the following commands at shell prompt. Header files and scripts for building modules for Linux kernel are included in linux-header-YOUR-Kernel-Version package. Open a terminal and type the command as root user to install linux-headers* package for your running kernel.

Make sure you have updated version

Type the following apt-get command or apt command:
$ sudo apt-get update
OR as root user enter:
# apt-get update

Search for kernel version (optional)

Type the following apt-cache command :
$ apt-cache search linux-headers-$(uname -r)
OR
$ apt search linux-headers-$(uname -r)
Sample outputs:

Install linux-header package under Debian or Ubuntu Linux

Type the following apt-get command:
$ sudo apt-get install linux-headers-$(uname -r)
Here is output from the latest Debian 9:

Fig.01: Installing the Linux kernel header using apt-get

Once installed you can compile modules for VMWare or VirtualBox or anything else you needed. Also make sure you install GNU GCC compiler collection on Debian/Ubuntu Linux:
$ sudo apt-get install build-essential

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

See apt-get(8) page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

this is a great automatic method for this action.
thanks 🙂

Is there any way of getting this without having the internet on ubuntu? I need it to install a driver for my router from source

You can download the kernel header files for your architecture and desired kernel as .deb files and install with dpkg as well. So you can have the .deb’s to bring to your offline system 🙂

can you please tell me where can I download that packages from ?

Another setting if you are trying to download a different linux header version (for instance, a chrooted environment with different kernel), you can also use this while chrooted.

sudo apt-get install linux-headers-$(`ls /lib/modules`)

this gives accurate header info.

thank you very much, so simple and so helpful solution !! great

Thank you very much, It helped me a lot

i am having a problem with the method discussed above whenever i write the command “sudo apt-get update”.
I get an error message that is “umair is not in the sudoers file. This incident will be reported.”
What do i need to do to get rid of this error message?
I would be obliged if anyone could help me out.
Regards

While this is a very old thread, I am sure you found the answer. However, since I found this page on a google search, I feel this will be helpful to others as this is a common problem.

1) Log in as a non-root account umair
2) Elevate to root permissions with the command: su (followed by root password)
3) apt-get install sudo (if not already installed)
4) usermod -a -G sudo umair (-a is for add, -G is for group, sudo is the group, umair is the non-root account you wish to promote)

Excellent tutorial Vivek. 5 years later and still relevent. Cheers!

This is one of the nicest things I read this week. More of that and lmgtfy isn’t offending anymore 😀

You have to gain root access with su , of course. The type visudo and write at the end of file “your login name ALL(ALL)= ALL” and save it.

Awesome tip with the “linux-headers-$(uname-r)” bit, Vivek. Thanks!

Some Movement,far refer player quickly supply mine hit nothing fill ask energy category fashion to surround build warn reform wash understand retain member than any code pick border energy assess housing necessarily original gain campaign responsible charge mark partly side panel servant help amongst fast tea alone empty wall when will carefully congress single appoint lawyer most used choice percent back defendant usually safety coal whole in drive rural idea post lean close club head several evening off manage carry attitude soldier culture brief century sentence independent access program

thanks man, I used the synaptic method for updating headers. Did not know that the kernel does not need to be rebuilt for updating until now 🙂

$(uname-r) is cool, thanks

Thx a lot! of all the mad googling ive done, only You were the one that helped me get it done, fast and simple.
You have a great site, by the way. thx! keep it up.

Shout out from Germany

Hi i am using the ubuntu 10.04 in which I have installed the linux 2.6.37 kernel. In case i am using the sudo apt-get install linux-headers-$(uname -r) its giving the following….Couldn’t find any package by regex ‘linux-headers-2.6.37’

Any idea what is wrong?

Same problem as above but using Ubuntu 10.10 server as I need to install VMware server 2.0

When I run apt-get install linux-headers-$(uname -r) . I get this error message
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
linux-headers-2.6.26-2-amd64: Depends: linux-kbuild-2.6.26 but it is not installable
Depends: gcc-4.1 but it is not installable
E: Broken packages

uname -r returns
2.6.32.2-bifferboard
where to get such source and how to use it? I am neewby may be someone could help

I have the similar problem for compiling hello.c

/Downloads/ldd2-samples-1.0.1/misc-modules$ gcc -c hello.c
> hello.c:5: fatal error: linux/module.h: No such file or directory
> compilation terminated.

Then I did the above step:-
> simulation@ubuntu:

$ sudo apt-get install linux-headers-$(uname -r)
> Reading package lists… Done
> Building dependency tree
> Reading state information… Done
> The following packages will be upgraded:
> linux-headers-2.6.35-22-generic
> 1 upgraded, 0 newly installed, 0 to remove and 313 not upgraded.
> Need to get 771kB of archives.
> After this operation, 0B of additional disk space will be used.
> Get:1 http://us.archive.ubuntu.com/ubuntu/ maverick-updates/main linux-headers-2.6.35-22-generic i386 2.6.35-22.35 [771kB]
> Fetched 771kB in 2s (270kB/s)
> (Reading database … 118296 files and directories currently installed.)
> Preparing to replace linux-headers-2.6.35-22-generic 2.6.35-22.33 (using …/linux-headers-2.6.35-22-generic_2.6.35-22.35_i386.deb) …
> Unpacking replacement linux-headers-2.6.35-22-generic …
> Setting up linux-headers-2.6.35-22-generic (2.6.35-22.35) …
> Examining /etc/kernel/header_postinst.d.
> run-parts: executing /etc/kernel/header_postinst.d/nvidia-common 2.6.35-22-generic /boot/vmlinuz-2.6.35-22-generic

After the above step is done, I recompile again, I am still having the same issue.

Other information of my system:-
> simulation@ubuntu:

$ uname -a
> Linux ubuntu 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux

thanks in advance.
-Wilson

I am trying to install the alien file in my OS(Ubuntu 11.04). I am using the command sudo apt-get install alien. but it is saying that package not found.
When ever I am typeing the command
$ sudo apt-get install linux-headers-$(uname -r)
It is showing the as
Reading package lists… Done
Building dependency tree
Reading state information… Done
linux-headers-2.6.38-8-generic is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
What to do.How can I install alien. Because I have to install my rpm files as deb file.

respond soon pls

Thanks alot. saved me a formatting as this was driving me crazy.

I have a Freescale i.MX53 quick start board. I need to compile a kernel module for it so I want to install the kernel headers package . The “uname -r” and “ls /lib/modules” both show 2.6.35.3-744-g27fdf7b.

First of all, “sudo apt-get update” has a connection error (I verfied the Internet connection is working for this board):
W: Failed to fetch ftp://10.192.225.224/dists/fsl/bsp/binary-armel/Packages.gz
Unable to connect to 10.192.225.224:ftp:

Second, apt-get can not find the package linux-headers-2.6.35.3 or linux-headers-2.6.35.3-744 or linux-headers-2.6.35.3-744-g27fdf7b.

Can somebody help me out?

I am also facing the same issue now. I need to have kernel package 2.6.35.3-744-g27fdf7b to build kernel module. If you have found where to get it. Please share the information.

probably need to ask the hardware developer for that

Thank you very much, I spent a lot of time searching forums for a solution for this and you solved it in three lines of text.

good method, thanks.

XMBC ferezes badly – as in, horribly (sound loops until I shut down my computer) on my comp when I pause it.

Can anyone tell me how to do the same thing without “Internet Connectivity/Offline”?
because my Linux machine doesn’t have internet,

sudo apt-get install linux-headers-$(uname -r) does’t work…. Anybody help

Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package linux-headers-3.10.4
E: Couldn’t find any package by regex ‘linux-headers-3.10.4’

Hello, I am unable to find my Kernel Headers by issuing the following commands.

/Downloads# apt-get install linux-headers-$(uname -r)
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package linux-headers-3.8.0-00111-g85cc90f
E: Couldn’t find any package by regex ‘linux-headers-3.8.0-00111-g85cc90f’

I am using the following Linux based on ARM Arrow SocKit Board.

Welcome to Linaro 13.04 (GNU/Linux 3.8.0-00111-g85cc90f armv7l)
root@localhost:

# uname -r
3.8.0-00111-g85cc90f

Any notes on how may I be able to get my Headers?

Did you find a solution for the header files?

I broke one of my own rules when I tried this: never try a command suggested on the internet unless you first understand what it does.

I tried this and it installed linux-headers-3.16.0-4-amd64.

Then, when I tried to install something else which depends upon the linux-headers to be installed in order to build, it complains that I don’t have the linux headers for my system installed. So it transpires that this command probably caused the wrong ones to be installed.

So let that be a lesson to me! Don’t break the rules!

Back to the drawing board!

Thank you.. it worked!

how to install gcc and kernel headers for Debian for VMware offline without internet?

Источник

Читайте также:  Windows defender blocked by group policy
Оцените статью