Get CPU temperature on Linux

The ability to get the temperature of a key component such as a CPU is important, whether you are gaming, overclocking, or hosting intensive processes on a critical server for your company. The Linux kernel comes with modules built in that allow it to access onboard sensors within the CPU. In this tutorial, you will learn how to access these sensors and get the CPU temperature on a Linux system.

There is a program that will work in conjunction with the kernel modules mentioned above to display the readings of the CPU temperature in the userspace. The program is called lm_sensors. This software allows users to get a readout of the CPU temperature in the command line and interfaces with several graphical front ends that make displaying temperatures in real time automatic and easy.

In this tutorial you will learn:

  • How to install lm_sensors on all major Linux distros
  • How to use the sensors command to get CPU temperature
  • How to install Conky on all major Linux distros
  • How to use Conky to monitor CPU temperature
Get CPU temperature on Linux
Get CPU temperature on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software lm-sensors, Conky
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

How to install lm_sensors on all major Linux distros



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


The lm_sensors software allows users to retrieve the temperature of their CPU on Linux. This package is available on all major Linux distros and can be installed from the default system repositories.

You can use the appropriate command below to install lm_sensors with your system’s package manager.

To install lm_sensors on Ubuntu, Debian, and Linux Mint:

$ sudo apt install lm-sensors

To install lm_sensors on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install lm_sensors

To install lm_sensors on Arch Linux and Manjaro:

$ sudo pacman -S lm_sensors

Get CPU temperature from command line

Once the lm_sensors package is installed on your system, you will have access to the sensors-detect command. Running this command in your terminal will show you the temperature of your CPU cores. As long as you have relatively modern hardware, you will probably have temperature monitoring capability. If you use a desktop distribution, you will have hardware monitoring support enabled.

$ sudo sensors-detect




The program will pose a number of questions about which sensors to use. It will suggest a best option for each one. If you don’t know which sensors to pick, go with the recommendations until the end where it asks if you want to save the configuration. Always save it. Of course, you can use your best judgment regarding which sensors to use.

Now you may use the sensors command to see a list of your system’s current temperatures.

$ sensors

Here is a snippet of output that was produced on our test system:

k8temp-pci-00c3
Adapter: PCI adapter
Core0 Temp:   +32.0°C  
Core0 Temp:   +33.0°C  
Core1 Temp:   +29.0°C  
Core1 Temp:   +25.0°C  

nouveau-pci-0200
Adapter: PCI adapter
temp1:        +58.0°C  (high = +100.0°C, crit = +120.0°C)
DID YOU KNOW?
Incorrectly installed heat sinks, clogged vents, or dust-ridden chassis fans can lead to high temperatures inside your PC, which are a detriment to the longevity of system components, including the CPU, video card, etc. Your BIOS should have (modern systems do) a temperature failsafe option: if the temperature reaches a certain threshold, the system will shutdown in order to prevent damage to the hardware.

To continuously monitor the CPU temperature, you can start lm-sensors as a service.

$ sudo systemctl start lm-sensors

And enable it to start automatically at system boot:

$ sudo systemctl enable lm-sensors

Get CPU temperature from GUI

Conky is a system monitoring program for Linux. It displays a widget on your desktop with relevant information for your system. In this case, we are interested in using Conky to display the CPU temperature. Since Conky is highly customizable, we can configure it to continuously display the output of the sensors command.

Let’s start by installing Conky. You can use the appropriate command below to install Conky with your system’s package manager.

To install Conky on Ubuntu, Debian, and Linux Mint:

$ sudo apt install conky-all

To install Conky on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install conky

To install Conky on Arch Linux and Manjaro:

$ sudo pacman -S conky

Copy the default Conky configuration to your home directory. It is better to edit this file with your custom settings, and to keep the original as a backup.

$ cp /etc/conky/conky.conf ~/.conkyrc




Open the configuration file to make your changes. Since Conky can take input in the form of variables from the execution of command line programs, that’s how you pass sensor information to it.

Running execi sensors in the Conky configuration will give the output of the sensors. However, that give the whole output, so you may want to use other command line tools like grep and cut to get the exact output that you want.

Example:

${color grey} System temps:
${execi sensors | grep Temp}

Closing Thoughts

In this tutorial, we saw how to get the CPU temperature on a Linux system. This can be achieved on most Linux distros with the lm-sensors software. Then, Conky and a number of other GUI utilities can take advantage of lm-sensors in order to display the CPU temperature information. This provides you with an easy way to get and monitor the temperatures in your system, to ensure that your PC is running as cool as possible.



Comments and Discussions
Linux Forum