#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    107
    Rep Power
    3

    Set up linux environment variable or path?


    Hi. I'm a window user and trying linux - ubuntu now.

    I wonder how you set up your environment variable or path in linux?

    I know how to do that in window but not sure how you do it in linux. I don't think it has like an interface to add it easily like in window?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,396
    Rep Power
    1688
    Just how and where you do this will depend upon two things, the shell the user will be using and if you wish to alter the setting/value globally or individually.
    As you are using Linux I'd guess you shell may well be bash - so for individuals you could edit the .bash_profile file in the home directory of the relevant user, but you may prefer to use a .profile instead as that will also be used by bourne/korn shells (ig .bash_profile does not exist).
    For global changes (that affect all users) look at the /etc/profile which will be used by all bourne-type shells.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    107
    Rep Power
    3
    Originally Posted by SimonJM
    Just how and where you do this will depend upon two things, the shell the user will be using and if you wish to alter the setting/value globally or individually.
    As you are using Linux I'd guess you shell may well be bash - so for individuals you could edit the .bash_profile file in the home directory of the relevant user, but you may prefer to use a .profile instead as that will also be used by bourne/korn shells (ig .bash_profile does not exist).
    For global changes (that affect all users) look at the /etc/profile which will be used by all bourne-type shells.
    Hi. I can't get it to work and I don't know why.

    I add this line on /home/bee/.bash_profile

    export PATH=$PATH:/opt/lampp

    Then I logout and log in as bee again.

    Then I echo $PATH and I don't see my added path.

    bee@bee-EG134AA-ABA-a1230n:~$ echo $PATH
    /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    Any idea what I did wrong? Thanks.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,396
    Rep Power
    1688
    Are you running the bash shell?
    Try echo $SHELL
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    107
    Rep Power
    3
    Originally Posted by SimonJM
    Are you running the bash shell?
    Try echo $SHELL
    Hi. I just did this. I installed ubuntu 11.10 recently. I'm still confuse why it's not working. Any idea?

    bee@bee-EG134AA-ABA-a1230n:~$ echo $SHELL
    /bin/bash
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    107
    Rep Power
    3
    Originally Posted by SimonJM
    Are you running the bash shell?
    Try echo $SHELL
    There's also a .profile too but it seems it will ignore it base on it's comment where .bash_profile exists.

    Any idea? Thanks.

    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.
    # see /usr/share/doc/bash/examples/startup-files for examples.
    # the files are located in the bash-doc package.

    # the default umask is set in /etc/profile; for setting the umask
    # for ssh logins, install and configure the libpam-umask package.
    #umask 022

    # if running bash
    if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
    fi

    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    fi
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,396
    Rep Power
    1688
    I have to admit on my little netbook I just have a .profile with my bash shell user ... Migrate the PATH stuff across to .profile, get rid of the .bash_profile and see what happens?
    Also, don't logout and back in again, you can just source the file to get it to be re-read:
    Code:
    . .profile
    Note, that is dot space at the start
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    107
    Rep Power
    3
    Originally Posted by SimonJM
    I have to admit on my little netbook I just have a .profile with my bash shell user ... Migrate the PATH stuff across to .profile, get rid of the .bash_profile and see what happens?
    Also, don't logout and back in again, you can just source the file to get it to be re-read:
    Code:
    . .profile
    Note, that is dot space at the start
    Hey thanks. I can get it to work on .profile and when I do echo it has the new path now.

    I also tried to put it on /etc/profile and when I logout and login as bee then the new path is there too.

    But when I su as root and echo $PATH then it doesn't have the new path. Any idea why?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,396
    Rep Power
    1688
    Not off the top of my head - I'd check the shell root uses and also what 'start-up' files (such as .profile) the root user has as that could over-write any prior changes done in the generic /etc/profile.
    I would add a word of caution here as to what you put in the PATH for the root user: it is best not to place the current directory (the . character) in the PATH. Also add new paths at the ned, keeping the 'system' paths at the beginning.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo