setting-up-a-vala-development-environment.md (2774B)
1 +++ 2 title = "Setting up a Vala development environment" 3 date = 2025-10-28 4 url = "setting-up-a-vala-development-environment" 5 +++ 6 7 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](https://vala.dev). 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)](https://pygobject.gnome.org) and [Qt for Python](https://doc.qt.io/qtforpython-6). 8 9 This setup uses [flatpak](https://flatpak.org), [VSCodium](https://flathub.org/en/apps/com.vscodium.codium), and my distro of choice, [Debian](https://www.debian.org). 10 11 The following commands will install: 12 13 - flatpak 14 - VSCodium 15 - the [Vala SDK](https://github.com/flathub/org.freedesktop.Sdk.Extension.vala) (which importantly contains the [Vala language server](https://github.com/vala-lang/vala-language-server)) 16 - and the [Vala VSCodium extension](https://open-vsx.org/extension/prince781/vala): 17 18 ```zsh 19 sudo apt install flatpak 20 flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo 21 # 22 flatpak install flathub com.vscodium.codium 23 # 24 flatpak install flathub org.freedesktop.Sdk.Extension.vala 25 # 26 flatpak run com.vscodium.codium --install-extension prince781.vala 27 ``` 28 29 ## Flatpak override 30 31 Now we need to instruct VSCodium to include the Vala SDK when it launches. We can do that using an override: 32 33 ```zsh 34 flatpak override --user --env FLATPAK_ENABLE_SDK_EXT=vala com.vscodium.codium 35 ``` 36 37 This command will add the following block to `$XDG_DATA_HOME/flatpak/overrides/com.vscodium.codium`: 38 39 ``` 40 [Environment] 41 FLATPAK_ENABLE_SDK_EXT=vala 42 ``` 43 44 ## Host system 45 46 Finally, let's install the Vala compiler and GTK4 dependencies on the host system (so not in the flatpak): 47 48 ```zsh 49 sudo apt install libgtk-4-dev valac 50 ``` 51 52 In addition, don't forget to include this shebang line at the top of the `.vala` file! (IntelliSense won't work otherwise): 53 54 ```vala 55 #!/usr/bin/env -S vala --pkg gtk4 56 ``` 57 58 ## Putting it all together 59 60 Let's use the first example from the Vala docs. Create the file `ExampleApp.vala` and add: 61 62 ```vala 63 #!/usr/bin/env -S vala --pkg gtk4 64 // ExampleApp.vala 65 66 public class ExampleApp : Gtk.Application { 67 public ExampleApp () { 68 Object (application_id: "com.example.App"); 69 } 70 71 public override void activate () { 72 var win = new Gtk.ApplicationWindow (this); 73 74 var btn = new Gtk.Button.with_label ("Hello World"); 75 btn.clicked.connect (win.close); 76 77 win.child = btn; 78 win.present (); 79 } 80 81 public static int main (string[] args) { 82 var app = new ExampleApp (); 83 return app.run (args); 84 } 85 } 86 87 ``` 88 89 Compile it: 90 91 ```zsh 92 valac --pkg gtk4 ExampleApp.vala 93 ``` 94 95 Run it: 96 97 ```zsh 98 ./ExampleApp 99 ```