How to add a directory to the PATH?












653














How do I add a directory to the $PATH in Ubuntu and make the changes permanent?










share|improve this question















migrated from serverfault.com Sep 6 '11 at 7:35


This question came from our site for system and network administrators.











  • 1




    help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
    – Bus42
    Jun 12 '16 at 20:30
















653














How do I add a directory to the $PATH in Ubuntu and make the changes permanent?










share|improve this question















migrated from serverfault.com Sep 6 '11 at 7:35


This question came from our site for system and network administrators.











  • 1




    help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
    – Bus42
    Jun 12 '16 at 20:30














653












653








653


255





How do I add a directory to the $PATH in Ubuntu and make the changes permanent?










share|improve this question















How do I add a directory to the $PATH in Ubuntu and make the changes permanent?







environment-variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 '16 at 18:11









αғsнιη

24.3k2295156




24.3k2295156










asked Jul 22 '09 at 20:42









justingrifjustingrif

3,86051518




3,86051518




migrated from serverfault.com Sep 6 '11 at 7:35


This question came from our site for system and network administrators.






migrated from serverfault.com Sep 6 '11 at 7:35


This question came from our site for system and network administrators.










  • 1




    help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
    – Bus42
    Jun 12 '16 at 20:30














  • 1




    help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
    – Bus42
    Jun 12 '16 at 20:30








1




1




help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
– Bus42
Jun 12 '16 at 20:30




help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish!
– Bus42
Jun 12 '16 at 20:30










17 Answers
17






active

oldest

votes


















415














Using ~/.profile to set $PATH



A path set in .bash_profile will only be set in a bash login shell (bash -l).
If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.



For example ~/.profile:



if [ -d "$HOME/bin" ] ; then
PATH="$PATH:$HOME/bin"
fi


Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ



Note:



bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :




it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one that exists
and is readable.




See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.






share|improve this answer



















  • 4




    Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
    – justingrif
    Jul 22 '09 at 22:13






  • 3




    On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
    – tekumara
    Aug 25 '12 at 22:21






  • 11




    This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
    – Michele
    May 23 '13 at 13:38






  • 2




    Where in .profile do we add the path ??
    – Vineet Kaushik
    Oct 2 '15 at 2:40






  • 2




    I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
    – Jamie Hutber
    Apr 25 '16 at 14:37



















268














Edit .bashrc in your home directory and add the following line:



export PATH="/path/to/dir:$PATH"


You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type



$ source ~/.bashrc





share|improve this answer



















  • 2




    How do you "source your .bashrc"? How do you "restart the terminal"?
    – isomorphismes
    Sep 10 '11 at 1:16






  • 3




    In bash it is simply '. .bashrc'
    – Ophidian
    Sep 12 '11 at 2:54






  • 1




    I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
    – Ophidian
    Feb 16 '12 at 14:23






  • 17




    .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
    – geirha
    Mar 2 '12 at 12:21








  • 4




    @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
    – Znarkus
    Aug 21 '12 at 8:26



















107














The recommended place to define permanent, system-wide environment variables applying to all users is in:



/etc/environment


(which is where the default PATH is defined)



This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)





  • To edit, press Alt+F2 and type:



    gksudo gedit /etc/environment


    (or open the file using sudo in your favorite text editor)




To effect changes, run . /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.



Related:




  • https://help.ubuntu.com/community/EnvironmentVariables






share|improve this answer



















  • 5




    and then you need to reboot for changes to take effect...
    – Lee
    Nov 17 '13 at 9:27






  • 2




    This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
    – Austin Pray
    Jun 30 '14 at 3:07






  • 7




    To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
    – WindRider
    May 20 '15 at 13:27






  • 1




    I needed to run source /etc/environment to reload the changes
    – JohnnyAW
    May 16 '18 at 8:54



















56














I think the canonical way in Ubuntu is:





  • create a new file under /etc/profile.d/



    sudo vi /etc/profile.d/SCRIPT_NAME.sh



  • add there:



    export PATH="YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH"



  • and give it execute permission



    sudo chmod a+x /etc/profile.d/SCRIPT_NAME.sh







share|improve this answer



















  • 18




    It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
    – Joe
    Feb 7 '13 at 16:37



















45














For complete newbies (like I am) who are more comfortable with GUI:




  1. Open your $HOME folder.

  2. Go to ViewShow Hidden Files or press Ctrl + H.

  3. Right click on .profile and click on Open With Text Editor.

  4. Scroll to the bottom and add PATH="$PATH:/my/path/foo".

  5. Save.

  6. Log out and log back in to apply changes (let Ubuntu actually load .profile).






share|improve this answer



















  • 4




    Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
    – PulsarBlow
    May 19 '13 at 4:20










  • Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
    – dain
    May 20 '13 at 12:22






  • 1




    This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
    – Frisbetarian
    Mar 2 '17 at 11:27








  • 1




    @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
    – dain
    Mar 10 '17 at 5:07










  • @dain : your comment saved my life!
    – Py-ser
    Dec 27 '17 at 19:10



















43














For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation.



https://help.ubuntu.com/community/EnvironmentVariables



Referring to documentation above, I have setup my Android SDK path-tools by:




  1. creating ~/.pam_environment file in home directory.

  2. the content of which is PATH DEFAULT=${PATH}:~/android-sdk-linux/tools.

  3. additional custom user path can be added by separating paths with colon (:).

  4. this requires re-login, which means you need to log-out and log-in back to desktop environment.






share|improve this answer



















  • 1




    This is the best answer.
    – Paulo Coghi
    Aug 22 '15 at 13:02



















26














Put that line in your ~/.bashrc file.



It gets sourced whenever you open a terminal



EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.






share|improve this answer



















  • 1




    Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
    – Marty Fried
    Jul 31 '12 at 1:37






  • 1




    If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
    – geirha
    Jul 31 '12 at 4:58








  • 2




    I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
    – Marty Fried
    Jul 31 '12 at 5:02






  • 1




    @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
    – geirha
    Jul 31 '12 at 5:14








  • 1




    @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
    – Marty Fried
    Jul 31 '12 at 18:50



















15














To set it system wide, append the line export PATH=/path/you're/adding:$PATH to the end of /etc/profile.



To add the directory for only the logged-in user, append the same line to ~/.bash_profile.






share|improve this answer































    14














    Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.



    PATH=$PATH:/my/path/foo
    export PATH


    According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.






    share|improve this answer

















    • 1




      I don't have a .bash_profile, Should I create it?
      – justingrif
      Jul 22 '09 at 21:39






    • 7




      If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
      – koenigdmj
      Jul 22 '09 at 21:58






    • 1




      I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
      – justingrif
      Jul 22 '09 at 22:05






    • 2




      Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
      – 3dinfluence
      Jul 23 '09 at 2:30






    • 3




      @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
      – geirha
      Mar 2 '12 at 12:19





















    9














    In terminal, cd to the_directory_you_want_to_add_in_the_path



    echo "export PATH=$(pwd):${PATH}" >> ~/.bashrc


    This wasn't my idea. I found this way to export path at this blog here.






    share|improve this answer































      8














      sudo vi /etc/profile.d/SCRIPT_NAME.sh


      add there



      export PATH=YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH





      share|improve this answer



















      • 2




        sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
        – isomorphismes
        Sep 10 '11 at 1:22






      • 1




        For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
        – fouric
        Mar 26 '13 at 0:04



















      6














      Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like



      if [ -d "/usr/scripts" ]; then
      PATH="/usr/scripts:$PATH"
      fi


      It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S



      BZT






      share|improve this answer































        4














        Open your terminal, type gedit .profile and insert the following:



        # set PATH so it includes user's private bin if it exists
        if [ -d "$HOME/bin" ] ; then
        PATH="$PATH:$HOME/bin"
        fi

        #the following line add Bin where you dont have a Bin folder on your $HOME
        PATH="$PATH:/home/mongo/Documents/mongodb-linux-i686-2.2.2/bin"


        Close and open terminal, it should be working.






        share|improve this answer































          3














          The recommended way to edit your PATH is from /etc/environment file



          Example output of /etc/environment:



          PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


          For example, to add the new path of /home/username/mydir



          PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mydir"


          Then, reboot your PC.






          System-wide environment variables



          A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.



          /etc/environment



          This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.



          Note: Variable expansion does not work in /etc/environment.




          More info can be found here: EnvironmentVariables






          share|improve this answer



















          • 1




            The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
            – NotoriousPyro
            Oct 12 '17 at 13:33





















          2














          Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell).






          share|improve this answer































            1














            Even if system scripts do not use this,
            in any of the cases that one wants to add a path (e.g., $HOME/bin) to the PATH environment variable, one should use



            PATH="${PATH:+${PATH}:}$HOME/bin"


            for appending (instead of PATH="$PATH:$HOME/bin"),
            and



            PATH="$HOME/bin${PATH:+:${PATH}}"


            for prepending (instead of PATH="$HOME/bin:$PATH").



            This avoids the spurious leading/trailing colon when $PATH is initially empty, which can have undesired effects.



            See e.g. https://unix.stackexchange.com/questions/162891/append-to-path-like-variable-without-creating-leading-colon-if-unset






            share|improve this answer































              -1














              For Ubuntu edit the ~/.bashrc and add the following line.



              . ~/.bash_profile



              Then edit your .bash_profile as you need.....






              share|improve this answer



















              • 1




                Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                – isomorphismes
                Sep 10 '11 at 1:17






              • 4




                This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                – geirha
                Mar 2 '12 at 12:15










              protected by heemayl Aug 21 '15 at 22:00



              Thank you for your interest in this question.
              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



              Would you like to answer one of these unanswered questions instead?














              17 Answers
              17






              active

              oldest

              votes








              17 Answers
              17






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              415














              Using ~/.profile to set $PATH



              A path set in .bash_profile will only be set in a bash login shell (bash -l).
              If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.



              For example ~/.profile:



              if [ -d "$HOME/bin" ] ; then
              PATH="$PATH:$HOME/bin"
              fi


              Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ



              Note:



              bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :




              it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
              order, and reads and executes commands from the first one that exists
              and is readable.




              See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.






              share|improve this answer



















              • 4




                Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
                – justingrif
                Jul 22 '09 at 22:13






              • 3




                On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
                – tekumara
                Aug 25 '12 at 22:21






              • 11




                This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
                – Michele
                May 23 '13 at 13:38






              • 2




                Where in .profile do we add the path ??
                – Vineet Kaushik
                Oct 2 '15 at 2:40






              • 2




                I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
                – Jamie Hutber
                Apr 25 '16 at 14:37
















              415














              Using ~/.profile to set $PATH



              A path set in .bash_profile will only be set in a bash login shell (bash -l).
              If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.



              For example ~/.profile:



              if [ -d "$HOME/bin" ] ; then
              PATH="$PATH:$HOME/bin"
              fi


              Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ



              Note:



              bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :




              it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
              order, and reads and executes commands from the first one that exists
              and is readable.




              See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.






              share|improve this answer



















              • 4




                Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
                – justingrif
                Jul 22 '09 at 22:13






              • 3




                On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
                – tekumara
                Aug 25 '12 at 22:21






              • 11




                This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
                – Michele
                May 23 '13 at 13:38






              • 2




                Where in .profile do we add the path ??
                – Vineet Kaushik
                Oct 2 '15 at 2:40






              • 2




                I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
                – Jamie Hutber
                Apr 25 '16 at 14:37














              415












              415








              415






              Using ~/.profile to set $PATH



              A path set in .bash_profile will only be set in a bash login shell (bash -l).
              If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.



              For example ~/.profile:



              if [ -d "$HOME/bin" ] ; then
              PATH="$PATH:$HOME/bin"
              fi


              Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ



              Note:



              bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :




              it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
              order, and reads and executes commands from the first one that exists
              and is readable.




              See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.






              share|improve this answer














              Using ~/.profile to set $PATH



              A path set in .bash_profile will only be set in a bash login shell (bash -l).
              If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.



              For example ~/.profile:



              if [ -d "$HOME/bin" ] ; then
              PATH="$PATH:$HOME/bin"
              fi


              Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ



              Note:



              bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :




              it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
              order, and reads and executes commands from the first one that exists
              and is readable.




              See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 1 '18 at 1:11









              wjandrea

              8,47742259




              8,47742259










              answered Jul 22 '09 at 22:04









              ko-dosko-dos

              4,290183




              4,290183








              • 4




                Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
                – justingrif
                Jul 22 '09 at 22:13






              • 3




                On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
                – tekumara
                Aug 25 '12 at 22:21






              • 11




                This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
                – Michele
                May 23 '13 at 13:38






              • 2




                Where in .profile do we add the path ??
                – Vineet Kaushik
                Oct 2 '15 at 2:40






              • 2




                I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
                – Jamie Hutber
                Apr 25 '16 at 14:37














              • 4




                Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
                – justingrif
                Jul 22 '09 at 22:13






              • 3




                On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
                – tekumara
                Aug 25 '12 at 22:21






              • 11




                This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
                – Michele
                May 23 '13 at 13:38






              • 2




                Where in .profile do we add the path ??
                – Vineet Kaushik
                Oct 2 '15 at 2:40






              • 2




                I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
                – Jamie Hutber
                Apr 25 '16 at 14:37








              4




              4




              Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
              – justingrif
              Jul 22 '09 at 22:13




              Cool, that worked. I saw where it will auto add the bin dir if I make it so I just used that instead of scripts. TY.
              – justingrif
              Jul 22 '09 at 22:13




              3




              3




              On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
              – tekumara
              Aug 25 '12 at 22:21




              On Xbunutu .profile isn't be executed so I put it in .bashrc and it works.
              – tekumara
              Aug 25 '12 at 22:21




              11




              11




              This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
              – Michele
              May 23 '13 at 13:38




              This piece of documentation is very well done: Official documentation about environment variable. Consider reading it (not to say that is updated to the last version of the rules to add values to environment variable).
              – Michele
              May 23 '13 at 13:38




              2




              2




              Where in .profile do we add the path ??
              – Vineet Kaushik
              Oct 2 '15 at 2:40




              Where in .profile do we add the path ??
              – Vineet Kaushik
              Oct 2 '15 at 2:40




              2




              2




              I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
              – Jamie Hutber
              Apr 25 '16 at 14:37




              I've still got no idea where to add my extra path part to. I need to add the android SDK to my path... PATH="$HOME/bin:$PATH" So I add it to it?
              – Jamie Hutber
              Apr 25 '16 at 14:37













              268














              Edit .bashrc in your home directory and add the following line:



              export PATH="/path/to/dir:$PATH"


              You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type



              $ source ~/.bashrc





              share|improve this answer



















              • 2




                How do you "source your .bashrc"? How do you "restart the terminal"?
                – isomorphismes
                Sep 10 '11 at 1:16






              • 3




                In bash it is simply '. .bashrc'
                – Ophidian
                Sep 12 '11 at 2:54






              • 1




                I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
                – Ophidian
                Feb 16 '12 at 14:23






              • 17




                .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
                – geirha
                Mar 2 '12 at 12:21








              • 4




                @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
                – Znarkus
                Aug 21 '12 at 8:26
















              268














              Edit .bashrc in your home directory and add the following line:



              export PATH="/path/to/dir:$PATH"


              You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type



              $ source ~/.bashrc





              share|improve this answer



















              • 2




                How do you "source your .bashrc"? How do you "restart the terminal"?
                – isomorphismes
                Sep 10 '11 at 1:16






              • 3




                In bash it is simply '. .bashrc'
                – Ophidian
                Sep 12 '11 at 2:54






              • 1




                I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
                – Ophidian
                Feb 16 '12 at 14:23






              • 17




                .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
                – geirha
                Mar 2 '12 at 12:21








              • 4




                @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
                – Znarkus
                Aug 21 '12 at 8:26














              268












              268








              268






              Edit .bashrc in your home directory and add the following line:



              export PATH="/path/to/dir:$PATH"


              You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type



              $ source ~/.bashrc





              share|improve this answer














              Edit .bashrc in your home directory and add the following line:



              export PATH="/path/to/dir:$PATH"


              You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect. To source your .bashrc, simply type



              $ source ~/.bashrc






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jul 1 '17 at 19:45









              wjandrea

              8,47742259




              8,47742259










              answered Jul 22 '09 at 20:45









              OphidianOphidian

              2,805182




              2,805182








              • 2




                How do you "source your .bashrc"? How do you "restart the terminal"?
                – isomorphismes
                Sep 10 '11 at 1:16






              • 3




                In bash it is simply '. .bashrc'
                – Ophidian
                Sep 12 '11 at 2:54






              • 1




                I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
                – Ophidian
                Feb 16 '12 at 14:23






              • 17




                .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
                – geirha
                Mar 2 '12 at 12:21








              • 4




                @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
                – Znarkus
                Aug 21 '12 at 8:26














              • 2




                How do you "source your .bashrc"? How do you "restart the terminal"?
                – isomorphismes
                Sep 10 '11 at 1:16






              • 3




                In bash it is simply '. .bashrc'
                – Ophidian
                Sep 12 '11 at 2:54






              • 1




                I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
                – Ophidian
                Feb 16 '12 at 14:23






              • 17




                .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
                – geirha
                Mar 2 '12 at 12:21








              • 4




                @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
                – Znarkus
                Aug 21 '12 at 8:26








              2




              2




              How do you "source your .bashrc"? How do you "restart the terminal"?
              – isomorphismes
              Sep 10 '11 at 1:16




              How do you "source your .bashrc"? How do you "restart the terminal"?
              – isomorphismes
              Sep 10 '11 at 1:16




              3




              3




              In bash it is simply '. .bashrc'
              – Ophidian
              Sep 12 '11 at 2:54




              In bash it is simply '. .bashrc'
              – Ophidian
              Sep 12 '11 at 2:54




              1




              1




              I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
              – Ophidian
              Feb 16 '12 at 14:23




              I was making the assumption that you were in your home directory. since that's where the .bashrc you want to edit is.
              – Ophidian
              Feb 16 '12 at 14:23




              17




              17




              .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
              – geirha
              Mar 2 '12 at 12:21






              .bashrc is not the right place for setting environment variables. They should go in .profile or .pam_environment. See mywiki.wooledge.org/DotFiles
              – geirha
              Mar 2 '12 at 12:21






              4




              4




              @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
              – Znarkus
              Aug 21 '12 at 8:26




              @LaoTzu . .bashrc not .bashrc :) or source .bashrc for that matter
              – Znarkus
              Aug 21 '12 at 8:26











              107














              The recommended place to define permanent, system-wide environment variables applying to all users is in:



              /etc/environment


              (which is where the default PATH is defined)



              This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)





              • To edit, press Alt+F2 and type:



                gksudo gedit /etc/environment


                (or open the file using sudo in your favorite text editor)




              To effect changes, run . /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.



              Related:




              • https://help.ubuntu.com/community/EnvironmentVariables






              share|improve this answer



















              • 5




                and then you need to reboot for changes to take effect...
                – Lee
                Nov 17 '13 at 9:27






              • 2




                This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
                – Austin Pray
                Jun 30 '14 at 3:07






              • 7




                To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
                – WindRider
                May 20 '15 at 13:27






              • 1




                I needed to run source /etc/environment to reload the changes
                – JohnnyAW
                May 16 '18 at 8:54
















              107














              The recommended place to define permanent, system-wide environment variables applying to all users is in:



              /etc/environment


              (which is where the default PATH is defined)



              This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)





              • To edit, press Alt+F2 and type:



                gksudo gedit /etc/environment


                (or open the file using sudo in your favorite text editor)




              To effect changes, run . /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.



              Related:




              • https://help.ubuntu.com/community/EnvironmentVariables






              share|improve this answer



















              • 5




                and then you need to reboot for changes to take effect...
                – Lee
                Nov 17 '13 at 9:27






              • 2




                This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
                – Austin Pray
                Jun 30 '14 at 3:07






              • 7




                To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
                – WindRider
                May 20 '15 at 13:27






              • 1




                I needed to run source /etc/environment to reload the changes
                – JohnnyAW
                May 16 '18 at 8:54














              107












              107








              107






              The recommended place to define permanent, system-wide environment variables applying to all users is in:



              /etc/environment


              (which is where the default PATH is defined)



              This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)





              • To edit, press Alt+F2 and type:



                gksudo gedit /etc/environment


                (or open the file using sudo in your favorite text editor)




              To effect changes, run . /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.



              Related:




              • https://help.ubuntu.com/community/EnvironmentVariables






              share|improve this answer














              The recommended place to define permanent, system-wide environment variables applying to all users is in:



              /etc/environment


              (which is where the default PATH is defined)



              This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)





              • To edit, press Alt+F2 and type:



                gksudo gedit /etc/environment


                (or open the file using sudo in your favorite text editor)




              To effect changes, run . /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.



              Related:




              • https://help.ubuntu.com/community/EnvironmentVariables







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 2 '16 at 7:40









              muru

              1




              1










              answered Jul 31 '12 at 3:49









              ishish

              115k29265293




              115k29265293








              • 5




                and then you need to reboot for changes to take effect...
                – Lee
                Nov 17 '13 at 9:27






              • 2




                This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
                – Austin Pray
                Jun 30 '14 at 3:07






              • 7




                To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
                – WindRider
                May 20 '15 at 13:27






              • 1




                I needed to run source /etc/environment to reload the changes
                – JohnnyAW
                May 16 '18 at 8:54














              • 5




                and then you need to reboot for changes to take effect...
                – Lee
                Nov 17 '13 at 9:27






              • 2




                This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
                – Austin Pray
                Jun 30 '14 at 3:07






              • 7




                To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
                – WindRider
                May 20 '15 at 13:27






              • 1




                I needed to run source /etc/environment to reload the changes
                – JohnnyAW
                May 16 '18 at 8:54








              5




              5




              and then you need to reboot for changes to take effect...
              – Lee
              Nov 17 '13 at 9:27




              and then you need to reboot for changes to take effect...
              – Lee
              Nov 17 '13 at 9:27




              2




              2




              This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
              – Austin Pray
              Jun 30 '14 at 3:07




              This is exactly what I needed. Provisioning a throw-away vm image via vagrant and needed to add node and npm to the path.
              – Austin Pray
              Jun 30 '14 at 3:07




              7




              7




              To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
              – WindRider
              May 20 '15 at 13:27




              To take changes in effect run . /etc/environement (yes, dot, a space and /etc/environment). Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
              – WindRider
              May 20 '15 at 13:27




              1




              1




              I needed to run source /etc/environment to reload the changes
              – JohnnyAW
              May 16 '18 at 8:54




              I needed to run source /etc/environment to reload the changes
              – JohnnyAW
              May 16 '18 at 8:54











              56














              I think the canonical way in Ubuntu is:





              • create a new file under /etc/profile.d/



                sudo vi /etc/profile.d/SCRIPT_NAME.sh



              • add there:



                export PATH="YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH"



              • and give it execute permission



                sudo chmod a+x /etc/profile.d/SCRIPT_NAME.sh







              share|improve this answer



















              • 18




                It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
                – Joe
                Feb 7 '13 at 16:37
















              56














              I think the canonical way in Ubuntu is:





              • create a new file under /etc/profile.d/



                sudo vi /etc/profile.d/SCRIPT_NAME.sh



              • add there:



                export PATH="YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH"



              • and give it execute permission



                sudo chmod a+x /etc/profile.d/SCRIPT_NAME.sh







              share|improve this answer



















              • 18




                It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
                – Joe
                Feb 7 '13 at 16:37














              56












              56








              56






              I think the canonical way in Ubuntu is:





              • create a new file under /etc/profile.d/



                sudo vi /etc/profile.d/SCRIPT_NAME.sh



              • add there:



                export PATH="YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH"



              • and give it execute permission



                sudo chmod a+x /etc/profile.d/SCRIPT_NAME.sh







              share|improve this answer














              I think the canonical way in Ubuntu is:





              • create a new file under /etc/profile.d/



                sudo vi /etc/profile.d/SCRIPT_NAME.sh



              • add there:



                export PATH="YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH"



              • and give it execute permission



                sudo chmod a+x /etc/profile.d/SCRIPT_NAME.sh








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 28 '16 at 10:05









              Zanna

              50.3k13133241




              50.3k13133241










              answered Jan 9 '10 at 1:31









              wotowoto

              66954




              66954








              • 18




                It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
                – Joe
                Feb 7 '13 at 16:37














              • 18




                It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
                – Joe
                Feb 7 '13 at 16:37








              18




              18




              It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
              – Joe
              Feb 7 '13 at 16:37




              It is usually safer to add your custom path to the end of PATH instead of the beginning. This avoids accidentally replacing system commands with your programs (or someone else's malicious programs). This also avoids a lot of confusion when someone else works on your system (or gives you advice) and they get unexpected results from commands you have "replaced".
              – Joe
              Feb 7 '13 at 16:37











              45














              For complete newbies (like I am) who are more comfortable with GUI:




              1. Open your $HOME folder.

              2. Go to ViewShow Hidden Files or press Ctrl + H.

              3. Right click on .profile and click on Open With Text Editor.

              4. Scroll to the bottom and add PATH="$PATH:/my/path/foo".

              5. Save.

              6. Log out and log back in to apply changes (let Ubuntu actually load .profile).






              share|improve this answer



















              • 4




                Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
                – PulsarBlow
                May 19 '13 at 4:20










              • Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
                – dain
                May 20 '13 at 12:22






              • 1




                This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
                – Frisbetarian
                Mar 2 '17 at 11:27








              • 1




                @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
                – dain
                Mar 10 '17 at 5:07










              • @dain : your comment saved my life!
                – Py-ser
                Dec 27 '17 at 19:10
















              45














              For complete newbies (like I am) who are more comfortable with GUI:




              1. Open your $HOME folder.

              2. Go to ViewShow Hidden Files or press Ctrl + H.

              3. Right click on .profile and click on Open With Text Editor.

              4. Scroll to the bottom and add PATH="$PATH:/my/path/foo".

              5. Save.

              6. Log out and log back in to apply changes (let Ubuntu actually load .profile).






              share|improve this answer



















              • 4




                Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
                – PulsarBlow
                May 19 '13 at 4:20










              • Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
                – dain
                May 20 '13 at 12:22






              • 1




                This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
                – Frisbetarian
                Mar 2 '17 at 11:27








              • 1




                @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
                – dain
                Mar 10 '17 at 5:07










              • @dain : your comment saved my life!
                – Py-ser
                Dec 27 '17 at 19:10














              45












              45








              45






              For complete newbies (like I am) who are more comfortable with GUI:




              1. Open your $HOME folder.

              2. Go to ViewShow Hidden Files or press Ctrl + H.

              3. Right click on .profile and click on Open With Text Editor.

              4. Scroll to the bottom and add PATH="$PATH:/my/path/foo".

              5. Save.

              6. Log out and log back in to apply changes (let Ubuntu actually load .profile).






              share|improve this answer














              For complete newbies (like I am) who are more comfortable with GUI:




              1. Open your $HOME folder.

              2. Go to ViewShow Hidden Files or press Ctrl + H.

              3. Right click on .profile and click on Open With Text Editor.

              4. Scroll to the bottom and add PATH="$PATH:/my/path/foo".

              5. Save.

              6. Log out and log back in to apply changes (let Ubuntu actually load .profile).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 26 '13 at 12:57









              Aditya

              9,248125589




              9,248125589










              answered Oct 24 '11 at 22:05









              daindain

              56745




              56745








              • 4




                Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
                – PulsarBlow
                May 19 '13 at 4:20










              • Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
                – dain
                May 20 '13 at 12:22






              • 1




                This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
                – Frisbetarian
                Mar 2 '17 at 11:27








              • 1




                @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
                – dain
                Mar 10 '17 at 5:07










              • @dain : your comment saved my life!
                – Py-ser
                Dec 27 '17 at 19:10














              • 4




                Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
                – PulsarBlow
                May 19 '13 at 4:20










              • Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
                – dain
                May 20 '13 at 12:22






              • 1




                This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
                – Frisbetarian
                Mar 2 '17 at 11:27








              • 1




                @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
                – dain
                Mar 10 '17 at 5:07










              • @dain : your comment saved my life!
                – Py-ser
                Dec 27 '17 at 19:10








              4




              4




              Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
              – PulsarBlow
              May 19 '13 at 4:20




              Editing the .profile file is not recommended anymore.You can still use this method to edit the file .pam_environment see: help.ubuntu.com/community/EnvironmentVariables
              – PulsarBlow
              May 19 '13 at 4:20












              Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
              – dain
              May 20 '13 at 12:22




              Thank @PulsarBlow! I'm not really sure what's exactly the difference and the benefit though... This is the direct URL to the relevant section: help.ubuntu.com/community/…
              – dain
              May 20 '13 at 12:22




              1




              1




              This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
              – Frisbetarian
              Mar 2 '17 at 11:27






              This answer caused my system to stop logging in due to all paths being overridden. Using Ubuntu 16.04.
              – Frisbetarian
              Mar 2 '17 at 11:27






              1




              1




              @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
              – dain
              Mar 10 '17 at 5:07




              @Frisbetarian you have to make sure to add the $PATH: bit which includes the existing PATH definition
              – dain
              Mar 10 '17 at 5:07












              @dain : your comment saved my life!
              – Py-ser
              Dec 27 '17 at 19:10




              @dain : your comment saved my life!
              – Py-ser
              Dec 27 '17 at 19:10











              43














              For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation.



              https://help.ubuntu.com/community/EnvironmentVariables



              Referring to documentation above, I have setup my Android SDK path-tools by:




              1. creating ~/.pam_environment file in home directory.

              2. the content of which is PATH DEFAULT=${PATH}:~/android-sdk-linux/tools.

              3. additional custom user path can be added by separating paths with colon (:).

              4. this requires re-login, which means you need to log-out and log-in back to desktop environment.






              share|improve this answer



















              • 1




                This is the best answer.
                – Paulo Coghi
                Aug 22 '15 at 13:02
















              43














              For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation.



              https://help.ubuntu.com/community/EnvironmentVariables



              Referring to documentation above, I have setup my Android SDK path-tools by:




              1. creating ~/.pam_environment file in home directory.

              2. the content of which is PATH DEFAULT=${PATH}:~/android-sdk-linux/tools.

              3. additional custom user path can be added by separating paths with colon (:).

              4. this requires re-login, which means you need to log-out and log-in back to desktop environment.






              share|improve this answer



















              • 1




                This is the best answer.
                – Paulo Coghi
                Aug 22 '15 at 13:02














              43












              43








              43






              For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation.



              https://help.ubuntu.com/community/EnvironmentVariables



              Referring to documentation above, I have setup my Android SDK path-tools by:




              1. creating ~/.pam_environment file in home directory.

              2. the content of which is PATH DEFAULT=${PATH}:~/android-sdk-linux/tools.

              3. additional custom user path can be added by separating paths with colon (:).

              4. this requires re-login, which means you need to log-out and log-in back to desktop environment.






              share|improve this answer














              For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation.



              https://help.ubuntu.com/community/EnvironmentVariables



              Referring to documentation above, I have setup my Android SDK path-tools by:




              1. creating ~/.pam_environment file in home directory.

              2. the content of which is PATH DEFAULT=${PATH}:~/android-sdk-linux/tools.

              3. additional custom user path can be added by separating paths with colon (:).

              4. this requires re-login, which means you need to log-out and log-in back to desktop environment.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 9 '12 at 1:00

























              answered Dec 8 '12 at 23:07









              Eduardo B.Eduardo B.

              58145




              58145








              • 1




                This is the best answer.
                – Paulo Coghi
                Aug 22 '15 at 13:02














              • 1




                This is the best answer.
                – Paulo Coghi
                Aug 22 '15 at 13:02








              1




              1




              This is the best answer.
              – Paulo Coghi
              Aug 22 '15 at 13:02




              This is the best answer.
              – Paulo Coghi
              Aug 22 '15 at 13:02











              26














              Put that line in your ~/.bashrc file.



              It gets sourced whenever you open a terminal



              EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.






              share|improve this answer



















              • 1




                Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
                – Marty Fried
                Jul 31 '12 at 1:37






              • 1




                If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
                – geirha
                Jul 31 '12 at 4:58








              • 2




                I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
                – Marty Fried
                Jul 31 '12 at 5:02






              • 1




                @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
                – geirha
                Jul 31 '12 at 5:14








              • 1




                @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
                – Marty Fried
                Jul 31 '12 at 18:50
















              26














              Put that line in your ~/.bashrc file.



              It gets sourced whenever you open a terminal



              EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.






              share|improve this answer



















              • 1




                Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
                – Marty Fried
                Jul 31 '12 at 1:37






              • 1




                If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
                – geirha
                Jul 31 '12 at 4:58








              • 2




                I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
                – Marty Fried
                Jul 31 '12 at 5:02






              • 1




                @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
                – geirha
                Jul 31 '12 at 5:14








              • 1




                @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
                – Marty Fried
                Jul 31 '12 at 18:50














              26












              26








              26






              Put that line in your ~/.bashrc file.



              It gets sourced whenever you open a terminal



              EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.






              share|improve this answer














              Put that line in your ~/.bashrc file.



              It gets sourced whenever you open a terminal



              EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 5 '16 at 11:51









              Severus Tux

              5,69143782




              5,69143782










              answered Jul 31 '12 at 1:08









              Ian B.Ian B.

              3,1381425




              3,1381425








              • 1




                Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
                – Marty Fried
                Jul 31 '12 at 1:37






              • 1




                If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
                – geirha
                Jul 31 '12 at 4:58








              • 2




                I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
                – Marty Fried
                Jul 31 '12 at 5:02






              • 1




                @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
                – geirha
                Jul 31 '12 at 5:14








              • 1




                @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
                – Marty Fried
                Jul 31 '12 at 18:50














              • 1




                Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
                – Marty Fried
                Jul 31 '12 at 1:37






              • 1




                If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
                – geirha
                Jul 31 '12 at 4:58








              • 2




                I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
                – Marty Fried
                Jul 31 '12 at 5:02






              • 1




                @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
                – geirha
                Jul 31 '12 at 5:14








              • 1




                @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
                – Marty Fried
                Jul 31 '12 at 18:50








              1




              1




              Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
              – Marty Fried
              Jul 31 '12 at 1:37




              Actually, I thought you set the path in either $HOME/.profile for personal settings, or /etc/profile for all users. But if it's only needed for bash, I suppose either will work.
              – Marty Fried
              Jul 31 '12 at 1:37




              1




              1




              If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
              – geirha
              Jul 31 '12 at 4:58






              If you set it in ~/.bashrc, it'll only be available in the terminals you open. E.g. if you hit Alt+F2 and try to run a command from that dir, it won't find it. If you set it in ~/.profile or ~/.pam_environment, the gnome session (or whichever DE you use) will inherit it. Appending PATH in ~/.bashrc also has the drawback that if you open/exec bash interactively from another interactive bash shell, it'll be appended multiple times.
              – geirha
              Jul 31 '12 at 4:58






              2




              2




              I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
              – Marty Fried
              Jul 31 '12 at 5:02




              I haven't really looked into this for a while, so I did a search, and it seems that there are at least 95 different ways to set the path, most of which are discussed here. I never figured out which one is best. I think ~/.profile is correct for personal paths, though; that's where Ubuntu adds the ~/bin directory. And I confess that I exaggerated a slight bit on the number of ways - just a little.
              – Marty Fried
              Jul 31 '12 at 5:02




              1




              1




              @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
              – geirha
              Jul 31 '12 at 5:14






              @MartyFried, yes, to quote the bot in #bash on freenode: «The overwhelming majority of bash scripts, code, tutorials, and guides on the Internet are crap. Sturgeon was an optimist.» Using google for bash problem, you'll often find a lot of half-working solutions before you find a good one. Oh and I'd go with ~/.profile in this case too.
              – geirha
              Jul 31 '12 at 5:14






              1




              1




              @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
              – Marty Fried
              Jul 31 '12 at 18:50




              @geirha - I agree that most guides on the internet in general are probably crap, especially anything linux since different distros, or even different versions of the same one, do things differently. It usually boils down to what works, but most people don't realize that what works is simply what works, not necessarily what's right or even what will always work. I try to figure out which of the many ways is actually correct, because I hate doing things more than once - but it's not always easy. :)
              – Marty Fried
              Jul 31 '12 at 18:50











              15














              To set it system wide, append the line export PATH=/path/you're/adding:$PATH to the end of /etc/profile.



              To add the directory for only the logged-in user, append the same line to ~/.bash_profile.






              share|improve this answer




























                15














                To set it system wide, append the line export PATH=/path/you're/adding:$PATH to the end of /etc/profile.



                To add the directory for only the logged-in user, append the same line to ~/.bash_profile.






                share|improve this answer


























                  15












                  15








                  15






                  To set it system wide, append the line export PATH=/path/you're/adding:$PATH to the end of /etc/profile.



                  To add the directory for only the logged-in user, append the same line to ~/.bash_profile.






                  share|improve this answer














                  To set it system wide, append the line export PATH=/path/you're/adding:$PATH to the end of /etc/profile.



                  To add the directory for only the logged-in user, append the same line to ~/.bash_profile.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 10 '11 at 1:48









                  isomorphismes

                  85221228




                  85221228










                  answered Jul 22 '09 at 23:20









                  ennuikillerennuikiller

                  25113




                  25113























                      14














                      Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.



                      PATH=$PATH:/my/path/foo
                      export PATH


                      According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.






                      share|improve this answer

















                      • 1




                        I don't have a .bash_profile, Should I create it?
                        – justingrif
                        Jul 22 '09 at 21:39






                      • 7




                        If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                        – koenigdmj
                        Jul 22 '09 at 21:58






                      • 1




                        I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                        – justingrif
                        Jul 22 '09 at 22:05






                      • 2




                        Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                        – 3dinfluence
                        Jul 23 '09 at 2:30






                      • 3




                        @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                        – geirha
                        Mar 2 '12 at 12:19


















                      14














                      Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.



                      PATH=$PATH:/my/path/foo
                      export PATH


                      According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.






                      share|improve this answer

















                      • 1




                        I don't have a .bash_profile, Should I create it?
                        – justingrif
                        Jul 22 '09 at 21:39






                      • 7




                        If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                        – koenigdmj
                        Jul 22 '09 at 21:58






                      • 1




                        I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                        – justingrif
                        Jul 22 '09 at 22:05






                      • 2




                        Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                        – 3dinfluence
                        Jul 23 '09 at 2:30






                      • 3




                        @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                        – geirha
                        Mar 2 '12 at 12:19
















                      14












                      14








                      14






                      Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.



                      PATH=$PATH:/my/path/foo
                      export PATH


                      According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.






                      share|improve this answer












                      Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.



                      PATH=$PATH:/my/path/foo
                      export PATH


                      According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jul 22 '09 at 20:58









                      3dinfluence3dinfluence

                      4731513




                      4731513








                      • 1




                        I don't have a .bash_profile, Should I create it?
                        – justingrif
                        Jul 22 '09 at 21:39






                      • 7




                        If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                        – koenigdmj
                        Jul 22 '09 at 21:58






                      • 1




                        I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                        – justingrif
                        Jul 22 '09 at 22:05






                      • 2




                        Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                        – 3dinfluence
                        Jul 23 '09 at 2:30






                      • 3




                        @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                        – geirha
                        Mar 2 '12 at 12:19
















                      • 1




                        I don't have a .bash_profile, Should I create it?
                        – justingrif
                        Jul 22 '09 at 21:39






                      • 7




                        If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                        – koenigdmj
                        Jul 22 '09 at 21:58






                      • 1




                        I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                        – justingrif
                        Jul 22 '09 at 22:05






                      • 2




                        Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                        – 3dinfluence
                        Jul 23 '09 at 2:30






                      • 3




                        @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                        – geirha
                        Mar 2 '12 at 12:19










                      1




                      1




                      I don't have a .bash_profile, Should I create it?
                      – justingrif
                      Jul 22 '09 at 21:39




                      I don't have a .bash_profile, Should I create it?
                      – justingrif
                      Jul 22 '09 at 21:39




                      7




                      7




                      If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                      – koenigdmj
                      Jul 22 '09 at 21:58




                      If you have .bashrc, stick it in .bashrc instead. GUI terminals in Ubuntu are not login shells, so .bash_profile will not be run.
                      – koenigdmj
                      Jul 22 '09 at 21:58




                      1




                      1




                      I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                      – justingrif
                      Jul 22 '09 at 22:05




                      I am not running a gui shell. But from the thread above it looks like the .bashrc will work just fine.
                      – justingrif
                      Jul 22 '09 at 22:05




                      2




                      2




                      Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                      – 3dinfluence
                      Jul 23 '09 at 2:30




                      Both will work if your shell is a login shell. But I just tried the .bash_profile approach on one of my Ubuntu machines and even after restarting my gnome session it didn't source my .bash_profile. So I would say that putting this in .bashrc is probably the way to go with Ubuntu.
                      – 3dinfluence
                      Jul 23 '09 at 2:30




                      3




                      3




                      @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                      – geirha
                      Mar 2 '12 at 12:19






                      @justingrif No, you don't need .bash_profile. If bash doesn't find a .bash_profile (when you log in interactively), it will look for .profile and use that instead. By default, you'll have a .profile and .bashrc in Ubuntu. And .profile is the correct place to set environment variables if we disregard pam_env.
                      – geirha
                      Mar 2 '12 at 12:19













                      9














                      In terminal, cd to the_directory_you_want_to_add_in_the_path



                      echo "export PATH=$(pwd):${PATH}" >> ~/.bashrc


                      This wasn't my idea. I found this way to export path at this blog here.






                      share|improve this answer




























                        9














                        In terminal, cd to the_directory_you_want_to_add_in_the_path



                        echo "export PATH=$(pwd):${PATH}" >> ~/.bashrc


                        This wasn't my idea. I found this way to export path at this blog here.






                        share|improve this answer


























                          9












                          9








                          9






                          In terminal, cd to the_directory_you_want_to_add_in_the_path



                          echo "export PATH=$(pwd):${PATH}" >> ~/.bashrc


                          This wasn't my idea. I found this way to export path at this blog here.






                          share|improve this answer














                          In terminal, cd to the_directory_you_want_to_add_in_the_path



                          echo "export PATH=$(pwd):${PATH}" >> ~/.bashrc


                          This wasn't my idea. I found this way to export path at this blog here.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Sep 8 '12 at 22:50







                          user76204

















                          answered Sep 8 '12 at 22:44









                          Vittorio CecchettoVittorio Cecchetto

                          9111




                          9111























                              8














                              sudo vi /etc/profile.d/SCRIPT_NAME.sh


                              add there



                              export PATH=YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH





                              share|improve this answer



















                              • 2




                                sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                                – isomorphismes
                                Sep 10 '11 at 1:22






                              • 1




                                For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                                – fouric
                                Mar 26 '13 at 0:04
















                              8














                              sudo vi /etc/profile.d/SCRIPT_NAME.sh


                              add there



                              export PATH=YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH





                              share|improve this answer



















                              • 2




                                sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                                – isomorphismes
                                Sep 10 '11 at 1:22






                              • 1




                                For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                                – fouric
                                Mar 26 '13 at 0:04














                              8












                              8








                              8






                              sudo vi /etc/profile.d/SCRIPT_NAME.sh


                              add there



                              export PATH=YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH





                              share|improve this answer














                              sudo vi /etc/profile.d/SCRIPT_NAME.sh


                              add there



                              export PATH=YOUR_PATH_WITHOUT_TRAILING_SLASH:$PATH






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Sep 6 '11 at 12:49









                              Jorge Castro

                              36k105422617




                              36k105422617










                              answered Jan 13 '11 at 18:44







                              Clipping Path















                              • 2




                                sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                                – isomorphismes
                                Sep 10 '11 at 1:22






                              • 1




                                For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                                – fouric
                                Mar 26 '13 at 0:04














                              • 2




                                sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                                – isomorphismes
                                Sep 10 '11 at 1:22






                              • 1




                                For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                                – fouric
                                Mar 26 '13 at 0:04








                              2




                              2




                              sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                              – isomorphismes
                              Sep 10 '11 at 1:22




                              sudo nano /etc/profile.d/SCRIPT_NAME.sh is easier for beginners.
                              – isomorphismes
                              Sep 10 '11 at 1:22




                              1




                              1




                              For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                              – fouric
                              Mar 26 '13 at 0:04




                              For beginners, gksu gedit /etc/profile.d/SCRIPT_NAME.sh is even easier.
                              – fouric
                              Mar 26 '13 at 0:04











                              6














                              Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like



                              if [ -d "/usr/scripts" ]; then
                              PATH="/usr/scripts:$PATH"
                              fi


                              It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S



                              BZT






                              share|improve this answer




























                                6














                                Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like



                                if [ -d "/usr/scripts" ]; then
                                PATH="/usr/scripts:$PATH"
                                fi


                                It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S



                                BZT






                                share|improve this answer


























                                  6












                                  6








                                  6






                                  Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like



                                  if [ -d "/usr/scripts" ]; then
                                  PATH="/usr/scripts:$PATH"
                                  fi


                                  It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S



                                  BZT






                                  share|improve this answer














                                  Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like



                                  if [ -d "/usr/scripts" ]; then
                                  PATH="/usr/scripts:$PATH"
                                  fi


                                  It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S



                                  BZT







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Jun 5 '16 at 12:02









                                  Shashanth

                                  2611522




                                  2611522










                                  answered Dec 29 '11 at 2:25









                                  SilversleevesxSilversleevesx

                                  6111




                                  6111























                                      4














                                      Open your terminal, type gedit .profile and insert the following:



                                      # set PATH so it includes user's private bin if it exists
                                      if [ -d "$HOME/bin" ] ; then
                                      PATH="$PATH:$HOME/bin"
                                      fi

                                      #the following line add Bin where you dont have a Bin folder on your $HOME
                                      PATH="$PATH:/home/mongo/Documents/mongodb-linux-i686-2.2.2/bin"


                                      Close and open terminal, it should be working.






                                      share|improve this answer




























                                        4














                                        Open your terminal, type gedit .profile and insert the following:



                                        # set PATH so it includes user's private bin if it exists
                                        if [ -d "$HOME/bin" ] ; then
                                        PATH="$PATH:$HOME/bin"
                                        fi

                                        #the following line add Bin where you dont have a Bin folder on your $HOME
                                        PATH="$PATH:/home/mongo/Documents/mongodb-linux-i686-2.2.2/bin"


                                        Close and open terminal, it should be working.






                                        share|improve this answer


























                                          4












                                          4








                                          4






                                          Open your terminal, type gedit .profile and insert the following:



                                          # set PATH so it includes user's private bin if it exists
                                          if [ -d "$HOME/bin" ] ; then
                                          PATH="$PATH:$HOME/bin"
                                          fi

                                          #the following line add Bin where you dont have a Bin folder on your $HOME
                                          PATH="$PATH:/home/mongo/Documents/mongodb-linux-i686-2.2.2/bin"


                                          Close and open terminal, it should be working.






                                          share|improve this answer














                                          Open your terminal, type gedit .profile and insert the following:



                                          # set PATH so it includes user's private bin if it exists
                                          if [ -d "$HOME/bin" ] ; then
                                          PATH="$PATH:$HOME/bin"
                                          fi

                                          #the following line add Bin where you dont have a Bin folder on your $HOME
                                          PATH="$PATH:/home/mongo/Documents/mongodb-linux-i686-2.2.2/bin"


                                          Close and open terminal, it should be working.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Feb 4 '13 at 19:28









                                          Eric Carvalho

                                          41.4k17114145




                                          41.4k17114145










                                          answered Feb 4 '13 at 19:09









                                          djavierdjavier

                                          411




                                          411























                                              3














                                              The recommended way to edit your PATH is from /etc/environment file



                                              Example output of /etc/environment:



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


                                              For example, to add the new path of /home/username/mydir



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mydir"


                                              Then, reboot your PC.






                                              System-wide environment variables



                                              A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.



                                              /etc/environment



                                              This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.



                                              Note: Variable expansion does not work in /etc/environment.




                                              More info can be found here: EnvironmentVariables






                                              share|improve this answer



















                                              • 1




                                                The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                                – NotoriousPyro
                                                Oct 12 '17 at 13:33


















                                              3














                                              The recommended way to edit your PATH is from /etc/environment file



                                              Example output of /etc/environment:



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


                                              For example, to add the new path of /home/username/mydir



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mydir"


                                              Then, reboot your PC.






                                              System-wide environment variables



                                              A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.



                                              /etc/environment



                                              This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.



                                              Note: Variable expansion does not work in /etc/environment.




                                              More info can be found here: EnvironmentVariables






                                              share|improve this answer



















                                              • 1




                                                The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                                – NotoriousPyro
                                                Oct 12 '17 at 13:33
















                                              3












                                              3








                                              3






                                              The recommended way to edit your PATH is from /etc/environment file



                                              Example output of /etc/environment:



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


                                              For example, to add the new path of /home/username/mydir



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mydir"


                                              Then, reboot your PC.






                                              System-wide environment variables



                                              A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.



                                              /etc/environment



                                              This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.



                                              Note: Variable expansion does not work in /etc/environment.




                                              More info can be found here: EnvironmentVariables






                                              share|improve this answer














                                              The recommended way to edit your PATH is from /etc/environment file



                                              Example output of /etc/environment:



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


                                              For example, to add the new path of /home/username/mydir



                                              PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mydir"


                                              Then, reboot your PC.






                                              System-wide environment variables



                                              A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment. An alternative is to create a file for the purpose in the /etc/profile.d directory.



                                              /etc/environment



                                              This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.



                                              Note: Variable expansion does not work in /etc/environment.




                                              More info can be found here: EnvironmentVariables







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Sep 28 '18 at 19:58

























                                              answered Nov 8 '16 at 9:04









                                              BennyBenny

                                              3,13411026




                                              3,13411026








                                              • 1




                                                The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                                – NotoriousPyro
                                                Oct 12 '17 at 13:33
















                                              • 1




                                                The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                                – NotoriousPyro
                                                Oct 12 '17 at 13:33










                                              1




                                              1




                                              The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                              – NotoriousPyro
                                              Oct 12 '17 at 13:33






                                              The lowest answer yet the most correct. This file is usually auto-populated bin Ubuntu with the path.
                                              – NotoriousPyro
                                              Oct 12 '17 at 13:33













                                              2














                                              Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell).






                                              share|improve this answer




























                                                2














                                                Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell).






                                                share|improve this answer


























                                                  2












                                                  2








                                                  2






                                                  Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell).






                                                  share|improve this answer














                                                  Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell).







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Aug 21 '15 at 22:00









                                                  heemayl

                                                  66.1k8137211




                                                  66.1k8137211










                                                  answered Aug 1 '12 at 9:40









                                                  MikaelaMikaela

                                                  1475




                                                  1475























                                                      1














                                                      Even if system scripts do not use this,
                                                      in any of the cases that one wants to add a path (e.g., $HOME/bin) to the PATH environment variable, one should use



                                                      PATH="${PATH:+${PATH}:}$HOME/bin"


                                                      for appending (instead of PATH="$PATH:$HOME/bin"),
                                                      and



                                                      PATH="$HOME/bin${PATH:+:${PATH}}"


                                                      for prepending (instead of PATH="$HOME/bin:$PATH").



                                                      This avoids the spurious leading/trailing colon when $PATH is initially empty, which can have undesired effects.



                                                      See e.g. https://unix.stackexchange.com/questions/162891/append-to-path-like-variable-without-creating-leading-colon-if-unset






                                                      share|improve this answer




























                                                        1














                                                        Even if system scripts do not use this,
                                                        in any of the cases that one wants to add a path (e.g., $HOME/bin) to the PATH environment variable, one should use



                                                        PATH="${PATH:+${PATH}:}$HOME/bin"


                                                        for appending (instead of PATH="$PATH:$HOME/bin"),
                                                        and



                                                        PATH="$HOME/bin${PATH:+:${PATH}}"


                                                        for prepending (instead of PATH="$HOME/bin:$PATH").



                                                        This avoids the spurious leading/trailing colon when $PATH is initially empty, which can have undesired effects.



                                                        See e.g. https://unix.stackexchange.com/questions/162891/append-to-path-like-variable-without-creating-leading-colon-if-unset






                                                        share|improve this answer


























                                                          1












                                                          1








                                                          1






                                                          Even if system scripts do not use this,
                                                          in any of the cases that one wants to add a path (e.g., $HOME/bin) to the PATH environment variable, one should use



                                                          PATH="${PATH:+${PATH}:}$HOME/bin"


                                                          for appending (instead of PATH="$PATH:$HOME/bin"),
                                                          and



                                                          PATH="$HOME/bin${PATH:+:${PATH}}"


                                                          for prepending (instead of PATH="$HOME/bin:$PATH").



                                                          This avoids the spurious leading/trailing colon when $PATH is initially empty, which can have undesired effects.



                                                          See e.g. https://unix.stackexchange.com/questions/162891/append-to-path-like-variable-without-creating-leading-colon-if-unset






                                                          share|improve this answer














                                                          Even if system scripts do not use this,
                                                          in any of the cases that one wants to add a path (e.g., $HOME/bin) to the PATH environment variable, one should use



                                                          PATH="${PATH:+${PATH}:}$HOME/bin"


                                                          for appending (instead of PATH="$PATH:$HOME/bin"),
                                                          and



                                                          PATH="$HOME/bin${PATH:+:${PATH}}"


                                                          for prepending (instead of PATH="$HOME/bin:$PATH").



                                                          This avoids the spurious leading/trailing colon when $PATH is initially empty, which can have undesired effects.



                                                          See e.g. https://unix.stackexchange.com/questions/162891/append-to-path-like-variable-without-creating-leading-colon-if-unset







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Jun 27 '18 at 7:56

























                                                          answered Jan 5 '18 at 16:25









                                                          sancho.ssancho.s

                                                          460317




                                                          460317























                                                              -1














                                                              For Ubuntu edit the ~/.bashrc and add the following line.



                                                              . ~/.bash_profile



                                                              Then edit your .bash_profile as you need.....






                                                              share|improve this answer



















                                                              • 1




                                                                Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                                – isomorphismes
                                                                Sep 10 '11 at 1:17






                                                              • 4




                                                                This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                                – geirha
                                                                Mar 2 '12 at 12:15
















                                                              -1














                                                              For Ubuntu edit the ~/.bashrc and add the following line.



                                                              . ~/.bash_profile



                                                              Then edit your .bash_profile as you need.....






                                                              share|improve this answer



















                                                              • 1




                                                                Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                                – isomorphismes
                                                                Sep 10 '11 at 1:17






                                                              • 4




                                                                This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                                – geirha
                                                                Mar 2 '12 at 12:15














                                                              -1












                                                              -1








                                                              -1






                                                              For Ubuntu edit the ~/.bashrc and add the following line.



                                                              . ~/.bash_profile



                                                              Then edit your .bash_profile as you need.....






                                                              share|improve this answer














                                                              For Ubuntu edit the ~/.bashrc and add the following line.



                                                              . ~/.bash_profile



                                                              Then edit your .bash_profile as you need.....







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Sep 6 '11 at 12:50









                                                              Jorge Castro

                                                              36k105422617




                                                              36k105422617










                                                              answered Nov 19 '09 at 5:03







                                                              Vidula















                                                              • 1




                                                                Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                                – isomorphismes
                                                                Sep 10 '11 at 1:17






                                                              • 4




                                                                This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                                – geirha
                                                                Mar 2 '12 at 12:15














                                                              • 1




                                                                Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                                – isomorphismes
                                                                Sep 10 '11 at 1:17






                                                              • 4




                                                                This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                                – geirha
                                                                Mar 2 '12 at 12:15








                                                              1




                                                              1




                                                              Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                              – isomorphismes
                                                              Sep 10 '11 at 1:17




                                                              Downvoted because you didn't explain how to "edit your .bash_profile as you need". What exactly do I need to do to the .bash_profile?
                                                              – isomorphismes
                                                              Sep 10 '11 at 1:17




                                                              4




                                                              4




                                                              This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                              – geirha
                                                              Mar 2 '12 at 12:15




                                                              This is the wrong way. .profile or .bash_profile should source .bashrc. Not the other way around.
                                                              – geirha
                                                              Mar 2 '12 at 12:15





                                                              protected by heemayl Aug 21 '15 at 22:00



                                                              Thank you for your interest in this question.
                                                              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                              Would you like to answer one of these unanswered questions instead?



                                                              Popular posts from this blog

                                                              Ellipse (mathématiques)

                                                              Quarter-circle Tiles

                                                              Mont Emei