A Linux kernel is the core of a Linux distribution and consists of three things: the kernel itself, the kernel's headers, and the kernel's extra modules. The kernel headers are used to define device interfaces. For example, they can be used to compile the module that controls your computer's video card and driver.

The main reason you may find yourself needing to install kernel headers is if you are compiling kernel modules and need Linux to access and communicate with hardware as intended. Sometimes device drivers may require you to update the kernel headers on your system to function properly. Other times, there may be compatibility issues with new versions and you'll need to roll back an update. The process for doing this can vary on each distribution, but in this guide we'll be going over the steps specifically for Manjaro Linux. Continue reading to find out how to install kernel headers, check the version of installed kernel headers, and switch between kernel header versions on Manjaro.

In this tutorial you will learn:
  • Linux API headers vs kernel headers
  • Install or update kernel headers
  • Switch between kernel header versions
Installing kernel headers on Manjaro
Installing kernel headers on Manjaro
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Manjaro Linux
Software Kernel headers
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Getting the right package

To clear up any upcoming confusion, let us preface by saying that Arch Linux, the ancestor of Manjaro, uses two separate but similarly named header packages. One is linux-api-headers which is sanitized for use in userspace. This package is utilized when the user tries to compile their own libraries, like glibc for example.

What you need to know is that this API package has nothing to do with the Linux kernel headers themselves. The two are independent of each other and may very well be at different versions. In this guide, we're working with kernel headers, and not the API headers.

Check kernel header version

You can see the version of your system's current kernel headers by opening a terminal and executing the following command. This instructs pacman to retrieve a list of all the packages installed on your system and grep specifically for headers.

$ pacman -Q | grep headers
Check for currently installed headers with pacman
Check for currently installed headers with pacman

We have a fresh install of Manjaro on our test system and pacman shows us that there aren't any kernel headers currently installed. Again, the linux-api-headers package is not the kernel headers.

If your system does have kernel headers installed, you'll see the version in that output.

Install or update kernel headers

Generally, the version of our system's kernel headers should correspond to the version of the kernel itself. This may not be the case if you're having compatibility issues and want to install an older version or if you need to test out the newest kernel header packages by installing a more upgraded version.

Open a terminal and type the following command to check the version of your Manjaro system's kernel:

$ uname -r
Check the kernel version with uname command on Manjaro
Check the kernel version with uname command on Manjaro

As you'll see in the screenshot, the version of the kernel on our test system is 5.6.16-1. The first two numbers are what's important here, so let's remember 5.6.

Now, let's update our kernel headers to be on par with the kernel itself. Or, if you don't have kernel headers installed at all, this command will install them for you. Type the following command in your terminal:

$ sudo pacman -S linux-headers
Choose the desired version of kernel headers to install
Choose the desired version of kernel headers to install

If you already have kernel headers installed, pacman will proceed to update them. Otherwise, pacman will present you with a few options. Unless you have a unique circumstance, we want to choose from among the repository core options. We have seven different choices here. As discussed, there are a few situations where you may want to install older kernel headers, but generally, you'll want them on the same version as the kernel itself.

Since our test machine is running kernel 5.6.x, we'll choose option 6, which installs the linux56-headers package.

Check again to see that the package was installed correctly.

$ pacman -Q | grep headers
Use pacman to verify that the new kernel headers were successfully installed
Use pacman to verify that the new kernel headers were successfully installed

You may need to reboot your system to start using the kernel headers.

$ reboot

Switch between kernel header versions

If you're looking to switch kernel header versions, you have the option to either upgrade or downgrade. We covered upgrading above, but here's the command again:

$ sudo pacman -S linux-headers

To downgrade, you need to remove the current version of your installed headers, and then you can use pacman to install an older version. For example, to remove our 5.6 headers:

$ sudo pacman -R linux56-headers

Next, issue the following command and choose which version you'd like to use:

$ sudo pacman -S linux-headers

You'll have the option to install various header versions from either the repository core or community repository.

Conclusion

In this guide, we saw how to install, upgrade, and switch between kernel header versions on Manjaro Linux. We also discussed the important Arch-unique caveat about the linux-api-headers package which causes a bit of confusion to the inexperienced.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions