20

I would like to set an environment variable so that it is set when I launch a specific Flatpak application, and only set for this application. How do I go about doing this in a permanent manner?

4
  • And how can I do it non-persistently, actually? Do the usual shell commands of prepending the env variable before the command work? Commented Feb 16, 2021 at 20:13
  • 3
    Oh I saw -env=VARIABLE_NAME=VARIABLE_VALUE also works with flatpak run. :) Commented Feb 16, 2021 at 20:18
  • 2
    @rugk I think it's actually --env not -env Commented Oct 13, 2021 at 12:47
  • @robertspierre Oh yes, of course. Commented Oct 14, 2021 at 17:23

2 Answers 2

21

You can do this via the flatpak override command.

To set only one environment variable you can use this syntax:

flatpak override --env=VARIABLE_NAME=VARIABLE_VALUE full.application.Name 

To set multiple environment variables you can use this syntax:

flatpak override --env=VARIABLE_NAME_ONE=VARIABLE_VALUE_ONE --env=VARIABLE_NAME_TWO=VARIABLE_VALUE_TWO full.application.Name 

This will set it globally and therefore requires you to run the command as root. If you want to do this for your current user, you can add the --user parameter to the command, like so:

flatpak override --user --env=VARIABLE_NAME=VARIABLE_VALUE full.application.Name 

Source and further reading: http://docs.flatpak.org/en/latest/flatpak-command-reference.html#flatpak-override

3
  • 1
    (1) I don’t have Flatpak, so I can’t experiment, but are you sure the --env="NAME1=VALUE1 NAME2=VAL2" syntax really works?  I see nothing in the documentation that suggests that it does.  Rather, it suggests --env="NAME1=VALUE1"--env="NAME2=VAL2".  (2) If it works as you describe, I don’t see how you would set an environment variable value that contains space(s) and equal sign(s).  For example, I wonder what --env="RELATIVITY=Einstein says E=mc^2" does. Commented May 13, 2021 at 21:10
  • as @G-ManSays'ReinstateMonica' mentioned --env can be used multiple times and join them with space is not working. Commented Sep 27, 2021 at 13:11
  • I thought I tested it and saw it work, but maybe I'm wrong. I'll update my answer. Commented Sep 27, 2021 at 15:33
3

The Flatseal application lets you set environment variables and other things relating to your installed flatpaks in a convenient fashion if you are GUI sort of person.

1
  • 5
    This answer could be improved by describing (and showing) how this answers the question. Commented May 13, 2021 at 21:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.