Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Set Permanent Environmental Variables 12.04LTS

  1. #1
    Join Date
    Oct 2012
    Beans
    3

    Cool Set Permanent Environmental Variables 12.04LTS

    Hi,

    Having a little trouble finding good documentation on adding in environmental variables permanently in Ubuntu 12.04LTS.

    I've read the official documentation, search on these forums on others and viewed all relevant posts from other people on editing the: ~/.bashrs , ~/.profile , /etc/environment.

    I've also tried adding a ~/.pum_environment with the supposed correct formating, which caused a crash of my user, fixing it by going into the text login (CTRL+ATL+F1) and loading the default PATH variables again (. /etc/environment) and deleting the file.

    I'm trying to add these, as currently I am doing it manually in the Terminal at the beginning of each session.

    Code:
    export NETKIT_HOME=~/netkit
    export PATH=$PATH:$NETKIT_HOME/bin
    export MANPATH=:$NETKIT_HOME/man
    I'm currently using netkit and really would like to add these to my PATH to remove me doing to manually.

    I'm assuming I need to add it to ~/.profile , which i have tried logged-in, out, to reload it and nothing happened (creating a backup first of course, in case it failed).

    I would like really simple instructions to learn it first. Please if you respond, could include why things are placed there so I actually learn something instead of just doing it? Hehe

    The original documentation is here: http://wiki.netkit.org/netkit-labs/netkit_introduction/netkit-introduction.pdf (page 16, "Setting up Netkit").

    Thanks
    Last edited by mysteriouskiwi; October 27th, 2012 at 01:29 AM. Reason: editing code

  2. #2
    Join Date
    Jul 2012
    Beans
    Hidden!

    Re: Set Permanent Environmental Variables 12.04LTS

    What are environmental variables anyway ??

  3. #3
    Join Date
    Jul 2009
    Location
    Netherlands
    Beans
    136
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Set Permanent Environmental Variables 12.04LTS

    look for ~/ .bashrc file and add what you want at the end.

  4. #4
    Join Date
    Jul 2009
    Location
    Netherlands
    Beans
    136
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Set Permanent Environmental Variables 12.04LTS

    Quote Originally Posted by madinc View Post
    look for ~/ .bashrc file and add what you want at the end.
    for example to add my bin to the path "/home/madinc/bin" i add this code at the end of the bashrc file like this:

    Code:
    export PATH
    PATH="/home/madinc/bin:$PATH"

  5. #5
    Join Date
    Oct 2012
    Beans
    3

    Smile Re: Set Permanent Environmental Variables 12.04LTS

    So, for example, would the '.bashrc' file look like this?:

    Code:
    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    # sources /etc/bash.bashrc).
    if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
        . /etc/bash_completion
       #my lines
       export NETKIT_HOME
       NETKIT_HOME="~/netkit:$NETKIT_HOME"
       export PATH
       PATH="$NETKIT_HOME/bin:$PATH"
       export MANPATH
       MANPATH="$NETKIT_HOME/man:$MANPATH"
    fi
    Would that work? Off to bed as it's 4:30am, but I'll check back on this later!

    Thanks for the help, by the way!

  6. #6
    Join Date
    Oct 2012
    Beans
    3

    Wink Re: Set Permanent Environmental Variables 12.04LTS

    Quote Originally Posted by offgridguy View Post
    What are environmental variables anyway ??
    I believe something in which are defined system or session wide to provide processes with common links to areas of the operating system, by user or developer definition.

    For example, to set the PATH for new Java installations for the JDK so that it can access its root files. Like an operating shell for processess, an aid to defined directories for the bash/shell/command area to check if the user hasn't predefined their own input, in which it checks before throwing an error or returning the correct desired result.

    Say, you're programming in C and have a directory setup for that. You would assign a new PATH to that directory, to tell the OS to check that directory when you input say "test.c", instead of having to type "./test.c" do show the process what directory that file is in to run.

    Eg: say your directory for working with said 'test.c' was "~/c_stuff/", ' PATH="$PATH":~/c_stuff ' would add the directory to the predefined directories in which the execute command would search in for the desired file name when you type in Bash "test.c". If the path is added correctly the program will run as it has found the path with the file named 'test.c' and run it. Instead of the person typing ./test.c to define the location and execute the file.

    Although with Netkit, the PATH(s) have to be set as it needs to use the commands without defining the directory each time. It would be like having to type ' . /etc/environment ' every time you wanted to use Terminal, so you have access to; sudo, rm, cp, etc....

    Sorry if that is slightly over complicated it or is just poorly explained.

  7. #7
    Join Date
    Jul 2009
    Location
    Netherlands
    Beans
    136
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Set Permanent Environmental Variables 12.04LTS

    Quote Originally Posted by mysteriouskiwi View Post
    Would that work? Off to bed as it's 4:30am, but I'll check back on this later!

    Thanks for the help, by the way!
    Well it works for me but most people seem to put it in ~/.bash_profile i really don't know the difference i just put it in the ~/.bashrc at the end of it after "fi" and not like you have there i hope it works for you too if it does please let me know you can also check this link http://www.troubleshooters.com/linux/prepostpath.htm
    and this http://www.linuxheadquarters.com/howto/basic/path.shtml
    and my favourite https://www.ccs.uky.edu/docs/cluster/env.html
    sometimes it's a matter of trial & error please let me know what worked for you.


    Code:
    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    # sources /etc/bash.bashrc).
    if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
        . /etc/bash_completion
    fi
    export DEBFULLNAME="Madinc"
    export DEBEMAIL="madinc29@gmail.com"
    export PATH
    PATH="/home/madinc/bin:$PATH"

  8. #8
    Join Date
    Jul 2009
    Location
    Netherlands
    Beans
    136
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Set Permanent Environmental Variables 12.04LTS

    Code:
    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    # sources /etc/bash.bashrc).
    if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
        . /etc/bash_completion
    fi
    export DEBFULLNAME="Madinc"
    export DEBEMAIL="madinc29@gmail.com"
    export PATH
    PATH="/home/madinc/bin:$PATH"
    To take efect type this in the terminal

    Code:
    ~/.bash_profile
    doing that you don't need to logout.

  9. #9
    Join Date
    Apr 2005
    Location
    Finland/UK
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Set Permanent Environmental Variables 12.04LTS

    put it ~/.bashrc if you want it to only affect terminal sessions, or in ~/.profile if you want the variables to be set any time you are logged in, including the graphical environment.

    (~/.bashrc is sourced for each Bash session, while ~/.profile is sourced when you log in, for all shells and graphical environments)

  10. #10
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Set Permanent Environmental Variables 12.04LTS

    default config adds ~/bin (if it exists) to $PATH automatically either way (~/.profile)
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •