Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Install GTK4 and Libadwaita

Now that Rust is installed, we need to install the graphical libraries required to build GTK applications.

Rust alone is not enough to build a graphical interface. GTK applications depend on system libraries that must be installed separately.

In this chapter, you will:

  • Install GTK4 development libraries
  • Install Libadwaita
  • Install required system tools
  • Verify that the setup works

What Are GTK4 and Libadwaita?

GTK4

GTK (GIMP Toolkit) is a cross-platform library for building graphical user interfaces.

GTK4 is the modern version used for:

  • Linux desktop applications
  • GNOME applications
  • Mobile-adaptive applications

It provides widgets such as:

  • Windows
  • Buttons
  • Labels
  • List views
  • Layout containers

Libadwaita

Libadwaita is a companion library built on top of GTK4.

It provides:

  • Modern GNOME design components
  • Responsive layout tools
  • Adaptive UI behavior
  • Navigation patterns for desktop and mobile

In this tutorial, we will use Libadwaita to create a modern, responsive interface.

Why System Libraries Are Required

When you add this dependency in Cargo.toml:

gtk4 = "0.9"

Rust does not download GTK itself.

Instead:

  • The Rust crate connects to system-installed GTK libraries.
  • The system must already provide GTK development headers.

If GTK is not installed, you will see build errors like:

pkg-config not found
gtk4 not found

That is why this step is required.

Step 1 - Install GTK4 Development Packages

Run:

sudo apt install libgtk-4-dev -y

This installs:

  • GTK4 runtime libraries
  • Development headers
  • Required system components

Step 2 - Install Libadwaita Development Packages

Run:

sudo apt install libadwaita-1-dev -y

This installs:

  • Libadwaita runtime
  • Development headers

Step 3 - Install Additional Required Tools

Install pkg-config:

sudo apt install pkg-config -y

Install GLib development files:

sudo apt install libglib2.0-dev -y

These tools allow Rust to detect installed system libraries during compilation.

Step 4 - Verify Installation

You can verify GTK4 installation using:

pkg-config --modversion gtk4

You should see a version number such as:

Now verify Libadwaita:

pkg-config --modversion libadwaita-1

If both commands return version numbers, the installation was successful.

What If pkg-config Fails?

If you see:

Package gtk4 was not found

Make sure:

  • libgtk-4-dev is installed
  • You ran sudo apt update
  • Your distribution version supports GTK4

If you are using an older Linux distribution, GTK4 may not be available in default repositories.

Why This Step Is Important

GTK and Libadwaita are native libraries written in C.

Rust bindings rely on these native system components.

Without them:

  • Your project will not compile
  • Cargo will fail during build
  • Flatpak builds may also fail

Installing these correctly ensures:

  • Cargo can detect GTK
  • Your application builds successfully
  • Your development environment is complete

For more details can be found in Gtk and Libadwaita Documentation