Score:1

How to set environment variables in desktop launcher (in UBUNTU)

af flag

How can I correctly set the following environment variables in a .desktop launcher file?

To fix a problem with Davinci Resolve Studio it is necessary for my setup to set these two environment variables:

__NV_PRIME_RENDER_OFFLOAD=1 
__GLX_VENDOR_LIBRARY_NAME=nvidia 

Via the terminal I can launch Davinci Resolve Studio now with the following line successfully:

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia /opt/resolve/bin/resolve

And I try to note these in the .desktop launcher like the following with no effect (see line 8, "Exec=..."). What do I have to alter in this .desktop file to get this working? I tried with and without the "env" command at the beginning so far.

[Desktop Entry]
Version=1.0
Type=Application
Name=DaVinci Resolve
GenericName=DaVinci Resolve
Comment=Revolutionary new tools for editing, visual effects, color correction, and professional audio post-production, all in a single application!
Path=/opt/resolve/
Exec=env __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia /opt/resolve/bin/resolve %u
Terminal=false
MimeType=application/x-resolveproj;
Icon=/opt/resolve/graphics/DV_Resolve.png
StartupNotify=true
Name[en_US]=DaVinci Resolve

The parameters are exemplary here. I wonder what is missing here to get this working via a launcher.

vanadium avatar
cn flag
The way you post it should work. Maybe you have another .desktop file that masks this one? Try placing it in ~/.local/share/applications
Fuchsi avatar
af flag
Thanks @vanadium. After moving the file from the desktop to this directory it works!
Fuchsi avatar
af flag
Thanks @karel, I have seen that before, but this more general guide did not help me solve this problem.
karel avatar
sa flag
Your comment "After moving the file from the desktop to this directory it works!" is the same as written in the accepted answer to [How can I create launchers on my desktop?](https://askubuntu.com/q/64222/) so how could it not be a duplicate of that question?
Fuchsi avatar
af flag
I see what you mean, if there is another post explaining how to add these enviromental parameters to the Exec line of the .desktop file, I would not mind to mark this question as a duplicate. Because this was my question initially. Somebody looking for these parameters would not find the answer in this previous question, would they?
Fuchsi avatar
af flag
I will update my question and hightlight the solution. The Davinci Resolve installer put this .desktop file on the Desktop itself. So the problem is not obvious.
cc flag
I found that selecting Performance Mode in the Nvidia settings/profiles allowed running my CUDA samples without the environment variables you use for Resolve. The mode seems to switch which GPU is considered "primary".
Fuchsi avatar
af flag
Thanks @ubfan1! This makes sense in this case, too. I prefer the adaptive mode to save battery on my laptop in general.
Artur Meinild avatar
vn flag
Does this answer your question? [How can I create launchers on my desktop?](https://askubuntu.com/questions/64222/how-can-i-create-launchers-on-my-desktop)
Fuchsi avatar
af flag
@ArturMeinild, we had this question before. [This is](https://askubuntu.com/questions/1435236/how-to-set-environment-variables-in-desktop-launcher-in-ubuntu?noredirect=1#comment2501838_1435236) how I answered.
Yerong Li avatar
cn flag
Actually when I add an evironmental variable, the icon does not work any more, does anyone knows how to fix this? https://askubuntu.com/questions/1461097/adding-an-enviromental-variable-in-desktop-icon-fails-the-desktop-icon
Score:1
af flag

As suggested by @vanadium I just had to move this .desktop file to ~/.local/share/applications.

See also this post for more information: How can I create launchers on my desktop?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.