Hi, I’ve been collecting lots of random Linux tips and tricks and just thought I might sharing of one in detail in case anyone finds it useful. It can be helpful to understand how Linux works; after all, it IS the “Year of the Linux Desktop”. I hope this is ok for this community; please mods delete if not. I have saved a copy and can post somewhere else more appropriate if so!
I’ve made it deliberately detailed as I personally learn by understanding the why as well as the how. This solution works for GTK 2 and 3 apps, but not GTK 4 which apparently deliberately ignores this.
The start section is a simple TLDR, likely enough for most people. The rest is a detailed explanation which may be helpful for different options and understanding/learning a bit more about using Linux environment variables generally.
TLDR - Get GTK apps to use your DEs save/load dialogue box
First ensure you have the following installed if you’re on KDE (Or use equivalents if you’re on Hyprland, cosmic etc.) These are pretty commonly already installed already on most distros. They may have slightly different names in your distros package manager.
- xdg-desktop-portal
- xdg-desktop-portal-kde6
- xdg-desktop-portal-gtk
Next, open a terminal and type:
echo 'export GTK_USE_PORTAL=1' >> ~/.profile
This will add the GTK_USE_PORTAL=1 to your personal desktop environment set up, and it’ll be set every time you log in. Just log out and back in. When you next launch a GTK app that supports it (like Firefox), you should find it now uses your desktop environments file manager dialogue boxes.
Detailed explanation!
The Problem
One thing that has always been a bugbear for me as a KDE user is when I use GTK 2 and 3 based apps, they usually default to use file/load/save dialogue boxes for GTK and not my KDE dolphin dialogue boxes. For example, Firefox uses GTK based dialogue boxes, so it has a different layout and different favourites on the left whenever I want to save an image or a page. It’s just different enough that it slows me down each time I use it.
Some distros are set up so this doesn’t happen (for example KDE Neon) but many don’t seem to set this up in my experience. Certainly OpenSuSE and Nobara didn’t have this set up.
It turns out, it’s pretty easy to fix that for most GTK apps. Sadly this does not apply to GTK 4.
The Solution
There is a simple widely available and installed framework called XDG Desktop Framework that standardises how apps from different desktop environments work together. It’s often used by Flatpaks, but also usually installed as a basic component of many major distros. But just in case it’s not installed on your system, you want to look for the following type of packages in your package manager and install them:
- xdg-desktop-portal
- xdg-desktop-portal-kde6
- xdg-desktop-portal-gtk
You may want different backends depending on your set up; on my distro (OpenSuSE) I can there are ones for Gnome, hyprland, lxqt, pantheon, cosmic and a few others, and there may be more on other distros. I’m on KDE and the KDE6 and GTK seems to be enough for me for this particular use.
Once these are installed, you can pass an environment variable to GTK 2 and 3 apps:
GTK_USE_PORTAL=1
An environment variable in Linux is something that can change the behaviour of software on your install. There are loads of ways to use these to get things done; they’ve very useful and a core part of how linux works.
For example, they can be set as a one-off when you launch a specific program, or set for a user for every program for that person or even set at the system level so every program has it set.
Detailed: How to set environment variables
Use it for ONE program only
The most basic way to use this would be open a terminal, and launch a program like firefox with the environment variable; for example:
env GTK_USE_PORTAL=1 firefox
This command runs the env program which sets the variable and then runs another program, like Firefox. The “child process” inherits the environment variable set by env. Here it’ll open Firefox from your terminal with an environment variable set to use the portal; it works but is probably not a very convenient solution day to day.
A slightly better way to use this would be to edit the menu entry for Firefox and add the environment variable. So as a KDE user, I could open my menu, find Firefox, right click and select “Edit Application…”. I’d then get the Firefox menu entry and I can add to the “Environment Variable:” box. Now each time I launch Firefox from my menu it will launch with variable set. Other DEs will have similar but unique methods to do the same.
This works but is still a bit limited. So a slightly better method again would be to edit the underlying .desktop file. To do that I could edit the existing .desktop file in the system folder and add the variable to the Exec=“” line:
EXEC=env GTK_USE_PORTAL=1 firefox
Bear in mind system .desktop files are often replaced when you do updates, so it may be better to copy the existing one to your home folder, edit it and then use that. I won’t go into massive detail about .desktop files.
This isn’t exhaustive; there are other ways of doing this for one program.
Use it for ALL programs for ONE user
However, I personally want ALL GTK programs to use KDE dialogue boxes if they support it, and I think this is probably the best solution for most users. This is also a useful method for any other variables you want to use. Instead of setting the environment variable each time on the fly or per program, we can set it for the whole user account.
To set Environment Variables for a user there are a few places we can put them to make use of them. For a single user with a bash based system (vast majority of people), the best place to set them is ONE of these 3 files in your home folder:
- .bashrc
- .bash_profile
- .profile
Lets try and understand these files:
.bashrc is used whenever a new interactive non-login shell is used - that generally means each time you open a terminal, this file is read and if you set an environment variable in it, anything run from that terminal will inherit and use that variable. That’s fine, but it’s not generally ideal for a GUI run program in a desktop environment and we’re basically constantly setting the variable each time we run something. It’ll work but it’s not ideal.
.bash_profile (if it exists) is run when a user starts a new login shell with bash. You may not have this file; don’t worry if not! This will run once per session; so when you first login to your desktop any environment variable in here will be run. This is better but it’s still not quite ideal. If you have a bash based system, this will work, but if you’ve switched entirely to another shell script system (like zsh or fish) it won’t. So this will probably work but again it’s not ideal. Many systems seem to skip this file and use .profile as a more generic option.
.profile is run when a user starts a new login shell, regardless of the shell (bash, zsh, fish etc). Lots of systems even using bash may use this file instead of .bash_profile as it’s more generic. If you add an environment variable to this file, whenever you login it will load and stay loaded for your session.
So the best place for most users to put GTK_USE_PORTAL=1 is .profile. When you log in that variable will set globally for your session and all new programs will use it. To use it, we need to add the following line to the file:
export GTK_USE_PORTAL=1
(For this, the export command will make an environment variable inheritable to all other programs run after it. If we just put GTK_USE_PORTAL=1 in, it’d actually be set for a moment but only for a moment - then the next command would be run during login and the variable would be forgotten again. If we used env instead of export, the env program gets launched as a new process, it modifies the environment and then it is designed to call another program straight after it. It’s meant to set the variable for it’s child process. It may still work but even if it does it’s overkill: export changes the variable globally and is done, env changes the variable and then is supposed to start a new child process so is redundant here.)
We can add the line to the file in numerous ways. Via the GUI/desktop, you could open your file manager, find the file, open it with a text editor and type the line in. You’ll probably find there isn’t much in your .profile file, you can put it anywhere in the file, as long as it’s on it’s own clear line.
Or an we can add it in via the terminal. All we do is open a terminal and type/paste the following:
echo 'export GTK_USE_PORTAL=1' >> ~/.profile
(This command uses echo to take the text written after it in the quotes, and pass it on. The >> is a linux operator, and it takes whatever it is being passed and appends/adds it to the end of whatever file follows. So we finish with the destination ~/.profile for >> to put the text. So echo takes the text ‘export GTK_USE_PORTAL=1’, passes is to >> which then adds it to the end of the file .profile in the ~/ directory.)
Once the text is in your .profile file, you need to log out and log back in to your Linux desktop session. This is because .profile is generally only launched when you first login to your session.
After that, any program that launches will have the environment variable of GTK_USE_PORTAL=1 set. If it supports it, it will use it. If it doesn’t support it, it will ignore it.
Use it for ALL programs for ALL users
If you want to set this globally for ALL users sharing a Linux install, then instead of using an individual home folder, we need to set the environment variable in a system file. This is overkill for this particular variable in my opinion, and generally I’d stick to user level settings (particularly as you will keep your changes if you back up your Home folder like a good Linux user!), but this may still be of interest as a concept for other variables.
To do this we need to add it to ONE of the following files:
- /etc/environment
- /etc/profile
You may not even have these files but don’t worry. Many modern systems have loads of variables and settings, and are set up to generate these files dynamically from a collection of other files located in folders like /etc/environment.d or /etc/profile.d A folder ending with .d just means it’s a directory containing partial configuration files, and the files in this folder are combined to make the final file by the Linux system. This is for convenience to make complex systems more modular, so things can be “plugged together”. That helps complex distros separate out and manage different things cleanly.
We can also “plug in” our own settings by creating our own configuration files, and the good thing is if we give them a unqiue name, we usually won’t lose our custom config if there is a system update and the distro changes it’s own config files.
Either /etc/environment.d or /etc/profile.d is fine for this; I use profile.d because that’s what my system is set up to use. If you don’t have an /etc/environment file or /etc/environment.d folder, you could create one, put the “export variable” line in and it’ll also work, but here I’ll use profile.d as it’s pretty widely used and it’s a useful concept to understand how combined config files work.
First we need to create a new shell script file (.sh) in the folder which will be combined by the system at boot with the other existing files. System folders like /etc/ are system level and protected so we need to use the sudo command to do this as a root user. In this example I’m going to put my custom variables in a file called myvariables.sh - but call it whatever you want (within reason!). To do this, in a terminal we can put the following:
sudo cat /etc/profile.d/myvariables.sh
#!/bin/sh
export GTK_USE_PORTAL=1
(This first runs sudo - temporarily logging us in as a super user (we’ll be asked for our admin password). Then it runs cat which will take the following text and put it in the target file (i.e. it’ll concatenate the text). To do this we first tell cat the file location - /etc/profile.d/myvariables.sh - if it doesn’t exist, cat will create it. Then it will put everything that follows into the new file. The first line is #!/bin/sh - this line tells the operating system when it reads the file it is a shell script, and to use /bin/sh to interpret it. In most systems, /bin/sh actually points to /bin/bash. The next line then runs the export command to set the environment variable to GTK_USE_PORTAL=1; because we use export this will be inherited by all programs running after it in the entire system, for all users.)
Alternative if we have already created a myvariables.sh we can instead just add the line to the existing file:
sudo echo 'export GTK_USE_PORTAL=1' >> /etc/profile.d/myvariables.sh
(This command uses **sudo ** to give us permission to use echo to take the text written after it in the quotes, and pass it on. The >> operator appends/adds it to the end of the file we provide it.)
Or we could also use a text editor to do this:
sudo nano /etc/profile.d/myvariables.sh
(This uses sudo to open a text editor in the terminal - nano - to open the file.)
Then we can just type in the following into the new file, and save the file.
#!/bin/sh
export GTK_USE_PORTAL=1
If you want to do this via the GUI, you can put the above in using a GUI text editor like Kate or Gedit; just bear in mind you need administrator level access to edit and save the changes as we’re working within the /etc/ folder
Whichever method you use, you will likely need to reboot so that the new environment variable is set for all programs on your system.
Setting this for Flatpaks
Just to be completely comprehensive, we can also set this variable (and others) for Flatpaks if we want to. I won’t go into massive detail though.
Personally I use a program called flatseal - you can install this from Flathub. This program lets you manage all your flatpaks.
In Flatseal, on the left is a list of all your flatpak programs. The first option is “All Applications”. If you select this and scroll down on the right you will find an “Environment” section. You can click the + button to add a new line and add GTK_USE_PORTAL=1. This will tell ALL flatpaks to use this setting if they can. If you prefer you can instead just add it to individual programs in the same way - select the program from your list of flatpaks on the left, and then find it’s “Environment” section on the right and add a new variable in the same way.
This can also be done using flatpak itself from the terminal if you prefer.
Hope this is helpful!
Nice information man! Everyday is a good day to learn some Linux tips :)
Awesome guide! I’ve saved it locally, and I’ll pay more attention to these menus moving forward.

