What is the difference between adding to PATH on the CLI vs in bashrc [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • How to correctly add a path to PATH?

    11 answers



In an online video lecture the teacher has explained how to add to PATH both on the command line and via .bashrc, and has indicated that the proper way of doing this is through .bashrc but has not adequately explained why.



My question is what is the difference between executing the following from the command line:



$ export PATH=/home/username/bin:$PATH


Or simply adding the line: export PATH=/home/username/bin:$PATH to my ~/.bashrc.







share|improve this question














marked as duplicate by Jesse_b, Archemar, Jeff Schaller, Vlastimil, meuh Feb 26 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • @Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
    – user7841468
    Feb 25 at 17:54














up vote
0
down vote

favorite













This question already has an answer here:



  • How to correctly add a path to PATH?

    11 answers



In an online video lecture the teacher has explained how to add to PATH both on the command line and via .bashrc, and has indicated that the proper way of doing this is through .bashrc but has not adequately explained why.



My question is what is the difference between executing the following from the command line:



$ export PATH=/home/username/bin:$PATH


Or simply adding the line: export PATH=/home/username/bin:$PATH to my ~/.bashrc.







share|improve this question














marked as duplicate by Jesse_b, Archemar, Jeff Schaller, Vlastimil, meuh Feb 26 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • @Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
    – user7841468
    Feb 25 at 17:54












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • How to correctly add a path to PATH?

    11 answers



In an online video lecture the teacher has explained how to add to PATH both on the command line and via .bashrc, and has indicated that the proper way of doing this is through .bashrc but has not adequately explained why.



My question is what is the difference between executing the following from the command line:



$ export PATH=/home/username/bin:$PATH


Or simply adding the line: export PATH=/home/username/bin:$PATH to my ~/.bashrc.







share|improve this question















This question already has an answer here:



  • How to correctly add a path to PATH?

    11 answers



In an online video lecture the teacher has explained how to add to PATH both on the command line and via .bashrc, and has indicated that the proper way of doing this is through .bashrc but has not adequately explained why.



My question is what is the difference between executing the following from the command line:



$ export PATH=/home/username/bin:$PATH


Or simply adding the line: export PATH=/home/username/bin:$PATH to my ~/.bashrc.





This question already has an answer here:



  • How to correctly add a path to PATH?

    11 answers









share|improve this question













share|improve this question




share|improve this question








edited Feb 25 at 17:51









Jesse_b

10.4k22658




10.4k22658










asked Feb 25 at 17:29









user7841468

335




335




marked as duplicate by Jesse_b, Archemar, Jeff Schaller, Vlastimil, meuh Feb 26 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Jesse_b, Archemar, Jeff Schaller, Vlastimil, meuh Feb 26 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • @Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
    – user7841468
    Feb 25 at 17:54
















  • @Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
    – user7841468
    Feb 25 at 17:54















@Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
– user7841468
Feb 25 at 17:54




@Jesse_b Thanks for the edit.It makes more sense of what I wanted to ask.
– user7841468
Feb 25 at 17:54










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










PATH is an environment variable (one of many) that stores the path that Bash searches when you type in a command on the command line. If you add a folder to the PATH, then any commands in that folder will be available for you to type at the command line (although, be careful, if the same commands exist elsewhere, earlier in the path).



However, if you change PATH on the command line, that won't persist outside of that session, after you log out. The .bashrc script is run every time Bash starts, so if you put a command in there to edit the PATH (or any other environment variable), that change will persist every time you log in to Bash.



Does that help?






share|improve this answer




















  • So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
    – user7841468
    Feb 25 at 17:42










  • @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
    – Time4Tea
    Feb 25 at 17:51










  • That seems correct thanks for the clarification.You were a great help sir.
    – user7841468
    Feb 25 at 17:53

















up vote
0
down vote













To modify the PATH in such a way that future shells see the modified value, the change should be made in the shell startup files (~/.bashrc in the case of bash for example).



However, that change will not be visible in the current shell, so executing the equivalent command on the command line introduces the new value for PATH for the currently running shell session as well.



If you only changed the shell startup file, you would have to close the current shell session and start a new one to see the effect of the change.






share|improve this answer



























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    PATH is an environment variable (one of many) that stores the path that Bash searches when you type in a command on the command line. If you add a folder to the PATH, then any commands in that folder will be available for you to type at the command line (although, be careful, if the same commands exist elsewhere, earlier in the path).



    However, if you change PATH on the command line, that won't persist outside of that session, after you log out. The .bashrc script is run every time Bash starts, so if you put a command in there to edit the PATH (or any other environment variable), that change will persist every time you log in to Bash.



    Does that help?






    share|improve this answer




















    • So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
      – user7841468
      Feb 25 at 17:42










    • @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
      – Time4Tea
      Feb 25 at 17:51










    • That seems correct thanks for the clarification.You were a great help sir.
      – user7841468
      Feb 25 at 17:53














    up vote
    2
    down vote



    accepted










    PATH is an environment variable (one of many) that stores the path that Bash searches when you type in a command on the command line. If you add a folder to the PATH, then any commands in that folder will be available for you to type at the command line (although, be careful, if the same commands exist elsewhere, earlier in the path).



    However, if you change PATH on the command line, that won't persist outside of that session, after you log out. The .bashrc script is run every time Bash starts, so if you put a command in there to edit the PATH (or any other environment variable), that change will persist every time you log in to Bash.



    Does that help?






    share|improve this answer




















    • So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
      – user7841468
      Feb 25 at 17:42










    • @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
      – Time4Tea
      Feb 25 at 17:51










    • That seems correct thanks for the clarification.You were a great help sir.
      – user7841468
      Feb 25 at 17:53












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    PATH is an environment variable (one of many) that stores the path that Bash searches when you type in a command on the command line. If you add a folder to the PATH, then any commands in that folder will be available for you to type at the command line (although, be careful, if the same commands exist elsewhere, earlier in the path).



    However, if you change PATH on the command line, that won't persist outside of that session, after you log out. The .bashrc script is run every time Bash starts, so if you put a command in there to edit the PATH (or any other environment variable), that change will persist every time you log in to Bash.



    Does that help?






    share|improve this answer












    PATH is an environment variable (one of many) that stores the path that Bash searches when you type in a command on the command line. If you add a folder to the PATH, then any commands in that folder will be available for you to type at the command line (although, be careful, if the same commands exist elsewhere, earlier in the path).



    However, if you change PATH on the command line, that won't persist outside of that session, after you log out. The .bashrc script is run every time Bash starts, so if you put a command in there to edit the PATH (or any other environment variable), that change will persist every time you log in to Bash.



    Does that help?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 25 at 17:36









    Time4Tea

    866119




    866119











    • So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
      – user7841468
      Feb 25 at 17:42










    • @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
      – Time4Tea
      Feb 25 at 17:51










    • That seems correct thanks for the clarification.You were a great help sir.
      – user7841468
      Feb 25 at 17:53
















    • So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
      – user7841468
      Feb 25 at 17:42










    • @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
      – Time4Tea
      Feb 25 at 17:51










    • That seems correct thanks for the clarification.You were a great help sir.
      – user7841468
      Feb 25 at 17:53















    So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
    – user7841468
    Feb 25 at 17:42




    So the path to a directory I set is for that session only. But if I put the same in .bashrc it is permanent.Did I get it right ?
    – user7841468
    Feb 25 at 17:42












    @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
    – Time4Tea
    Feb 25 at 17:51




    @user7841468 essentially, yes. In general, environment variables are internal to Bash and not persistent. If you change one from the command line, that will only last for that session. However, all of the commands in .bashrc are run every time you log in to Bash, which effectively makes them persistent.
    – Time4Tea
    Feb 25 at 17:51












    That seems correct thanks for the clarification.You were a great help sir.
    – user7841468
    Feb 25 at 17:53




    That seems correct thanks for the clarification.You were a great help sir.
    – user7841468
    Feb 25 at 17:53












    up vote
    0
    down vote













    To modify the PATH in such a way that future shells see the modified value, the change should be made in the shell startup files (~/.bashrc in the case of bash for example).



    However, that change will not be visible in the current shell, so executing the equivalent command on the command line introduces the new value for PATH for the currently running shell session as well.



    If you only changed the shell startup file, you would have to close the current shell session and start a new one to see the effect of the change.






    share|improve this answer
























      up vote
      0
      down vote













      To modify the PATH in such a way that future shells see the modified value, the change should be made in the shell startup files (~/.bashrc in the case of bash for example).



      However, that change will not be visible in the current shell, so executing the equivalent command on the command line introduces the new value for PATH for the currently running shell session as well.



      If you only changed the shell startup file, you would have to close the current shell session and start a new one to see the effect of the change.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        To modify the PATH in such a way that future shells see the modified value, the change should be made in the shell startup files (~/.bashrc in the case of bash for example).



        However, that change will not be visible in the current shell, so executing the equivalent command on the command line introduces the new value for PATH for the currently running shell session as well.



        If you only changed the shell startup file, you would have to close the current shell session and start a new one to see the effect of the change.






        share|improve this answer












        To modify the PATH in such a way that future shells see the modified value, the change should be made in the shell startup files (~/.bashrc in the case of bash for example).



        However, that change will not be visible in the current shell, so executing the equivalent command on the command line introduces the new value for PATH for the currently running shell session as well.



        If you only changed the shell startup file, you would have to close the current shell session and start a new one to see the effect of the change.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 25 at 21:37









        Kusalananda

        103k13202318




        103k13202318












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?