Home » Guides » Install Valgrind on Linux: Debian, Ubuntu, Arch, Fedora, RHEL, Raspberry, etc.

Install Valgrind on Linux: Debian, Ubuntu, Arch, Fedora, RHEL, Raspberry, etc.

Valgrind is a framework required to build dynamic analysis tools for Linux. It is instrumental for the OS as some Valgrind tools can automatically detect bugs affecting your memory management. The same framework is also responsible for analysis and removing threading bugs, hence profiling the different Linux programs in detail.

But most importantly, users can always rely on the framework to create new tools for their distro. As such, it becomes necessary to have Valgrind on a Linux system. Now, most Linux distros do come with Valgrind pre-installed.

But if your system is missing one, or the included version isn’t working, then it is worth knowing how to install Valgrind on Linux, which we have discussed in the following article.

What is Valgrind?

Valgrind is a GPL v2 licensed collection that utilizes binary instrumentation or dynamic recompilation to offer a set of analysis tools. There are six tools in total that can be used to detect memory management, threading errors, profile programming, and generating call graphs. The tools are Memcheck, Helgrind, DRD, Callgrind, Cachegrind and Massif.

Prerequisites

There are a few conditions to be met before a user can run Valgrind,

  • A PC with Linux OS
  • Valgrind supporting Distro
  • And a working internet.

Method 1. Using Command Terminal if Valgrind is already included in a distro

If your Linux distro already includes Valgrind, then simply open the command terminal and run the following commands for different distros.

Debian & Ubuntu

sudo apt-get install valgrind

Arch Linux

sudo pacman -S valgrind

Fedora

sudo yum -y install valgrind

Or

sudo dnf install valgrind

Method 2. Using Snap packages on different Linux distros

In this method, we are going to use the Snap App Store to install Valgrind on different Linux distros. Snaps are basically application packages that include all the required dependencies to run on any Linux distro from a single build. Furthermore, these packages auto update and even rollback for older versions.

We have included the steps for installing Snap and Valgrind for different distros in the following segment:

Ubuntu

Before proceeding with the installation, remember that those users running Ubuntu Xenial Xerus or later do not have to install Snap, as it is already included in the distro.

Step 1. First, we need to install Snapd. We can do so by either searching the Ubuntu Software Center or using the following code in the Command Terminal.

sudo apt update
sudo apt install snapd

Step 2. Now, install Valgrind by using the command:

sudo snap install valgrind --classic

Raspberry Pi

Step 1. Users running the latest version of the Raspberry can directly install snap using the APT command.

sudo apt update
sudo apt install snapd

Step 2. Then reboot the system.

sudo reboot

Step 3. It is also recommended to get the Core Snap to keep your snapd up-to-date. Hence, the required command is:

sudo snap install core

Step 4. Finally, install Valgrind.

sudo snap install valgrind --classic

RHEL

Step 1. First, add the EPEL repository to your RHEL OS. It is the repository where you will find snapd. 

For those running RHEL 8 should use the following command to add EPEL.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf upgrade

Those running the RHEL 7 should use:

sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Step 2. It is also recommended to add the optional and extras repositories.

sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"
sudo yum update

Step 3. Finally, you can install Snap.

sudo yum install snapd

However users are hereby required to enable the systemd unit that manages the Snap communication socket

sudo systemctl enable --now snapd.socket

Step 4. At last, install Valgrind.

sudo snap install valgrind --classic

openSUSE

Step 1. openSUSE users are required to add the Snappy repository before installing Snap.

sudo zypper addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/openSUSE_version snappy

Step 2. Then import its GPG key:

sudo zypper --gpg-auto-import-keys refresh

Step 3. Now, update the package to include the new Snappy repository.

sudo zypper dup --from snappy

Step 4. Install snapd.

sudo zypper install snapd

Step 5. Now, enable and start snapd and snapd.apparmor services.

sudo systemctl enable snapd
sudo systemctl start snapd

Step 6. Then, install Valgrind.

sudo snap install valgrind --classic

Arch Linux

Step 1. First, install snapd from the AUR repository.

git clone https://aur.archlinux.org/snapd.git
cd snapd
makepkg -si

Step 2. After installation, enable the systemd unit which manages the snap communication socket.

sudo systemctl enable --now snapd.socket

Step 3. Now, install Valgrind.

sudo snap install valgrind --classic

CentOS

Step 1. As with the RHEL OS, we need to add the EPEL repository before installing snapd.

sudo yum install epel-release

Step 2. Now install Snap.

sudo yum install snapd

Step 3. Similarly, we need to enable the systemd unit managing the main snap communication socket.

sudo systemctl enable --now snapd.socket

Step 4. And lastly, install Valgrind.

sudo snap install valgrind --classic

Debian

Step 1. Install snapd directly from command line, using the APT command:

sudo apt update
sudo apt install snapd

Step 2. Install Snap core.

sudo snap install core

Step 3. Finally, install valgrind.

sudo snap install valgrind --classic

Elementary OS

Step 1. Launch the command terminal and install Snap.

sudo apt update
sudo apt install snapd

Step 2. Then, install Valgrind.

sudo snap install valgrind --classic

Fedora

Step 1. Use the DNF command to install snapd on your Fedora OS.

sudo dnf install snapd

Step 2. Then, install valgrind.

sudo snap install valgrind --classic

Manjaro

Step 1. On Manjaro users can either use the Add/Remove Software application (PAMAC) to install snapd. It can be found in the launch menu. Just launch the app, search for snapd and install. Or use the Command terminal with the PACMAN code.

sudo pacman -S snapd

Step 2. Then enable the systemd unit that manages the main snap communication socket. 

sudo systemctl enable --now snapd.socket

Step 3. And at last, install Valgrind.

sudo snap install valgrind --classic

Method 3. Build and Install Valgrind

The final method is not for beginners. Here we can learn how to build and install Valgrind from source.

Using the LFS 11.3 platform

Step 1. Run the command terminal and enter the following command to make the package.

sed -i 's|/doc/valgrind||' docs/Makefile.in && 
./configure --prefix=/usr \
--datadir=/usr/share/doc/valgrind-3.20.0 &&
make

Step 2. Install the make package.

make install

FAQ

How to verify that Valgrind is installed correctly?

In most cases, you can just run the command valgrind –version to check if Valgrind is installed correctly. It should return the current version number.

Is it the only tool for debugging and profiling?

No. There are several programs for Linux available for these purposes. Some of them are gdb, strace, and ltrace.

Gilbert John Avatar