Saturday, May 4, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 7668  / 1 Year ago, thu, march 2, 2023, 8:47:16

All, I need to set environment variables in my ~/.profile since I am running a program (QtCreator) that doesn't start a bash shell.



I cannot for the life of me get it to work though. QtCreator will not show any of the environment variables I defined under "System Environment."



How can I do this?






Edit: Okay, actually it turns out my question is why can't I source my_environment where



my_environment:



 export SOME_PATH=blalalal


If I add export SOME_PATH=blalalal to my ~/.profile it works. But I can't use source ~/.profile


More From » environment-variables

 Answers
4

Here is the story:




~/.profile - In this file you can also place environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.




(source)




  1. solution: export the variables defined in .profile.



            export VAR1=foo


  2. solution: put the variables in .bashrc, open a terminal and start QtCreator from command line. It should have the variables. Don't forget to export them:



    export VAR1=foo

  3. solution: create a wrapper for starting your program, a small script that you run instead of running the program directly:



    #!/bin/bash

    export VAR1=foo
    program


    or



     #!/bin/bash

    VAR1=foo program

  4. solution: edit the .desktop file used to launch the application by modifying the execute line to



     VAR1=foo program


    instead of



     program


    (haven't tested that, but it should work)


  5. solution: change the environment. You are right in your comment that programs do get an environment, even if they do not read it from the .profile. The system-wide environment is in /etc/environment, but you can also set it per session, in a file in your home directory called .pam_environment. See here for more information. By the way, this page neatly explains what all the different files do and when to use which.



    However, I prefer solutions 1-3, because they change the environment of the program only, and not of the whole session.



[#34915] Thursday, March 2, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
umplegitimat

Total Points: 137
Total Questions: 126
Total Answers: 118

Location: Saint Pierre and Miquelon
Member since Sat, Aug 21, 2021
3 Years ago
umplegitimat questions
;