Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Hi January, many of these solutions make sense, but I'm a hard head. Qt Creator sees many System Variables, surely they weren't set in any of the launcher and it's extracting them from an existing source. I thought that source is either /etc/environment or /etc/profile –  Constantin Oct 17 '12 at 19:17
    
You are right; see the update in solution 4. –  January Oct 17 '12 at 19:27
    
January, the doing export BLA=blalalbabl in my ~/.profile worked. However, being the hardhead, I want to source an environment file I've made from the ~/.profile... is it simply . $HOME/my_environment.bash –  Constantin Oct 17 '12 at 19:32
    
Yes, exactly, this is it (dot or source). –  January Oct 17 '12 at 19:37
    
You don't need to edit your answer to say you're wrong, just edit the answer to be correct! –  Jorge Castro Oct 17 '12 at 19:41

Just logout and login back into the system that the .pam-environment file is read and the environment variable is recognized.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.