Here is what I believe is the easiest way to setup a Vala development environment. If you don’t know what Vala is, you can find out here. Vala is the easiest way I found to create programs with a GUI. Some other beginner-friendly ways are PyGObject (Python language binding for GTK) and Qt for Python.
This setup uses flatpak, VSCodium, and my distro of choice, Debian.
The following commands will install:
- flatpak
- VSCodium
- the Vala SDK (which importantly contains the Vala language server)
- and the Vala VSCodium extension:
sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
#
flatpak install flathub com.vscodium.codium
#
flatpak install flathub org.freedesktop.Sdk.Extension.vala
#
flatpak run com.vscodium.codium --install-extension prince781.vala
Flatpak override
Now we need to instruct VSCodium to include the Vala SDK when it launches. We can do that using an override:
flatpak override --user --env FLATPAK_ENABLE_SDK_EXT=vala com.vscodium.codium
This command will add the following block to $XDG_DATA_HOME/flatpak/overrides/com.vscodium.codium:
[Environment]
FLATPAK_ENABLE_SDK_EXT=vala
Host system
Finally, let’s install the Vala compiler and GTK4 dependencies on the host system (so not in the flatpak):
sudo apt install libgtk-4-dev valac
In addition, don’t forget to include this shebang line at the top of the .vala file! (IntelliSense won’t work otherwise):
#!/usr/bin/env -S vala --pkg gtk4
Putting it all together
Let’s use the first example from the Vala docs. Create the file ExampleApp.vala and add:
#!/usr/bin/env -S vala --pkg gtk4
// ExampleApp.vala
public class ExampleApp : Gtk.Application {
public ExampleApp () {
Object (application_id: "com.example.App");
}
public override void activate () {
var win = new Gtk.ApplicationWindow (this);
var btn = new Gtk.Button.with_label ("Hello World");
btn.clicked.connect (win.close);
win.child = btn;
win.present ();
}
public static int main (string[] args) {
var app = new ExampleApp ();
return app.run (args);
}
}
Compile it:
valac --pkg gtk4 ExampleApp.vala
Run it:
./ExampleApp