<p>Fedora, Arch, Debian and OpenSUSE are also possible. See <ahref="https://www.gtk.org/docs/installations/linux#installing-gtk-from-packages">Installing GTK from packages</a>. The following table shows the distributions which support Gtk4.</p>
<p>If your operating system doesn’t have Gtk4 packages, you need to build it from the source. Or, if you want the latest version of Gtk4 (4.6.3), you also need to build it from the source.</p>
<p>I installed Gtk4 from the source in January 2021. So, the following information is old, especially for the version of each software. For the latest information, see <ahref="https://docs.gtk.org/gtk4/building.html">Gtk API Reference, Building GTK</a>.</p>
<p>I installed Gtk4 under the directory <code>$HOME/local</code>. This is a private user area.</p>
<p>If you want to install it in the system area, <code>/opt/gtk4</code> is one of good choices. <ahref="https://docs.gtk.org/gtk4/building.html">Gtk API Reference, Building GTK</a> gives an installation example to <code>/opt/gtk4</code>.</p>
<p>Don’t install it to <code>/usr/local</code> which is the default. It is used by Ubuntu applications which are not build on Gtk4. Therefore, the risk is high and probably bad things will happen. Actually I did it and I needed to reinstall Ubuntu.</p>
<h3id="installation-to-ubuntu-20.10">Installation to Ubuntu 20.10</h3>
<p>Most of the necessary libraries are included by Ubuntu 20.10. Therefore, they can be installed with <code>apt-get</code> command. You don’t need to install them from the source tarballs. You can skip the subsections below about prerequisite library installation (Glib, Pango, Gdk-pixbuf and Gtk-doc).</p>
<h3id="glib-installation">Glib installation</h3>
<p>If your Ubuntu is 20.04LTS, you need to install prerequisite libraries from the tarballs. Check the version of your library and if it is lower than the necessary version, install it from the source.</p>
<p>For example,</p>
<pre><code>$ pkg-config --modversion glib-2.0
2.64.6</code></pre>
<p>The necessary version is 2.66.0 or higher. Therefore, the example above shows that you need to install Glib.</p>
<p>I installed 2.67.1 which was the latest version at that time (January 2021). Download Glib source files from the repository, then decompress and extract files.</p>
<p>Set several environment variables so that the Glib libraries installed can be used by build tools. Make a text file below and save it as <code>env.sh</code></p>
<p>Try meson and check the required packages. Install all the prerequisites. Then, compile and install Pango.</p>
<pre><code>$ meson --prefix $HOME/local _build
$ ninja -C _build
$ ninja -C _build install</code></pre>
<p>It installs Pango-1.0.gir under <code>$HOME/local/share/gir-1.0</code>. If you installed Pango without <code>--prefix</code> option, then it would be located at <code>/usr/local/share/gir-1.0</code>. This directory (/usr/local/share) is used by applications. They find the directory by the environment variable <code>XDG_DATA_DIRS</code>. It is a text file which keep the list of ‘share’ directories like <code>/usr/share</code>, <code>usr/local/share</code> and so on. Now <code>$HOME/local/share</code> needs to be added to <code>XDG_DATA_DIRS</code>, or error will occur in the later compilation.</p>
<p>Same as before, install prerequisite packages, then compile and install them.</p>
<p>The installation of Gtk-doc put <code>gtk-doc.pc</code> under <code>$HOME/local/share/pkgconfig</code>. This file is used by pkg-config, which is one of the build tools. The directory needs to be added to the environment variable <code>PKG_CONFIG_PATH</code></p>
<p>If you want a stable version of Gtk4, then download it from <ahref="https://download.gnome.org/sources/gtk/">Gnome source website</a>. The latest version is 4.3.1 (13/June/2021).</p>
<p>Compile and install it.</p>
<pre><code>$ meson --prefix $HOME/local _build
$ ninja -C _build
$ ninja -C _build install</code></pre>
<p>If you want to know more information, refer to <ahref="https://docs.gtk.org/gtk4/building.html">Gtk4 API Reference, Building GTK</a>.</p>
<h3id="modify-env.sh">Modify env.sh</h3>
<p>Because environment variables disappear when you log out, you need to add them again. Modify <code>env.sh</code>.</p>
<p>Include this file by . (dot) command before using Gtk4 libraries.</p>
<p>You may think you can add them in your <code>.profile</code>. But it’s a wrong decision. Never write them to your <code>.profile</code>. The environment variables above are necessary only when you compile and run Gtk4 applications. Otherwise it’s not necessary. If you changed the environment variables above and run Gtk3 applications, it probably causes serious damage.</p>
<p>The last part of this section is about Gnome40 and gnome-boxes. Gnome 40 is a new version of Gnome desktop system. And Gtk4 is installed in the distribution. See <ahref="https://forty.gnome.org/">Gnome 40 website</a> first.</p>
<p>I’ve installed Fedora 34 with gnome-boxes. My OS was Ubuntu 21.04 at that time. Gnome-boxes creates a virtual machine in Ubuntu and Fedora will be installed to that virtual machine.</p>
<li>Click on <code>+</code> button on the top left corner and launch a box creation wizard by clicking <code>Create a Virtual Machine ...</code>. Then a dialog appears. Click on <code>Operationg System Image File</code> and select the iso file you have downloaded.</li>
<li>Then, the Fedora’s installer is executed. Follow the instructions by the installer. At the end of the installation, the installer instructs to reboot the system. Click on the right of the title bar and select reboot or shutdown.</li>
<li>Your display is back to the initial window of gnome-boxes, but there is a button <code>Fedora 34 Workstation</code> on the upper left of the window. Click on the button then Fedora will be executed.</li>
<li>A setup dialog appears. Setup Fedora according to the wizard.</li>
</ol>
<p>Now you can use Fedora. It includes Gtk4 libraries already. But you need to install the Gtk4 development package. Use <code>dnf</code> to install <code>gtk4.x86_64</code> package.</p>
<p>You can test the Gtk4 development packages by compiling files which are based on Gtk4. I’ve tried compiling <code>tfe</code> text editor, which is written in section 21.</p>