Editing .bash_profile file not taking effect

10,572

Solution 1

.bash_profile is only supposed to be run once, by the login shell. .bashrc is the file that's run for each child.

Try logging out and logging in again, then see if your .bash_profile changes are picked up.

Just for the sake of chapter and verse, this is from bash's man page:

   When bash is invoked as an interactive login shell, or as a  non-inter‐
   active  shell with the --login option, it first reads and executes com‐
   mands from the file /etc/profile, if that file exists.   After  reading
   that file, 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.  The --noprofile option may be used when the
   shell is started to inhibit this behavior.

   When a login shell exits, bash reads and  executes  commands  from  the
   file ~/.bash_logout, if it exists.

   When  an  interactive  shell that is not a login shell is started, bash
   reads and executes commands from ~/.bashrc, if that file exists.   This
   may  be inhibited by using the --norc option.  The --rcfile file option
   will force bash to read and  execute  commands  from  file  instead  of
   ~/.bashrc.

Solution 2

If you do not want to logout to apply the changes,

# source ~/.bash_profile

should apply your changes.

Share:
10,572

Related videos on Youtube

Sandeepan Nath
Author by

Sandeepan Nath

Please answer these questions of mine - Stackoverflow - mysql date time indexes not applying for some specific date ranges How to find the absolute path of a node (file or directory) in this file system model (Interesting question!) Need help? Have some questions that I may answer? Is nobody answering your question? If you feel I may be able to answer any of your questions, mail me the link of your question. My mail ID is sandeepan (dot) nits (at) google's mail. I like trying to answer those questions which are generally skipped by many highly reputated guys here lol. Sometimes they skip them because they don't have time to read long questions. I like attempting such questions and I think that could be my trick to earn reputation. I am also active in many SE sites like programmers.SE, gaming.SE, onstartups.SE, etc. Send me questions!! About me I am a Software Developer/Designer from India. Here is my Brief Résumé on Stackoverflow Careers. Contact me at sandeepan (dot) nits (at) google's mail. Other than programming I have deep interests in Human Psychology, Entrepreneurship, Social work and Scientific Research. While younger I had deep interests in Genetics, Astronomy etc. I love computer games, especially FPS games on multi-player, cricket, music, racing and adventure. I am a 24 years old guy and as time is passing by, I am gradually coming to realize that there are so many things to see and do in this beautiful world. I am afraid that a few years down the line I will repent over so many things I wished to do but could not do. However, I have started serious planning for all this.

Updated on September 17, 2022

Comments

  • Sandeepan Nath
    Sandeepan Nath almost 2 years

    I need to put export PATH=$PATH:/opt/lampp/bin to my ~/.bash_profile file so that mysql from command line works on my system. Please check mysql command line not working for further details on that.

    I am working on a fedora system and logged in as root user.

    If I run locate .bash_profile then I get these:-

    /etc/skel/.bash_profile
    /home/sam/.bash_profile
    /home/sohil/.bash_profile
    /home/windows/.bash_profile
    /root/.bash_profile
    

    So, I modified the /root/.bash_profile file like this:-

    from

    PATH=$PATH:$HOME/bin
    export PATH
    

    to

    PATH=$PATH:/opt/lampp/bin
    export PATH
    

    But, still the change is not taking effect - Opening a new console and running mysql again says bash: mysql: command not found.

    However running export PATH=$PATH:/opt/lampp/bin in console makes it work for that session. So, I am doing something wrong with the .bash_profile file. May be editing incorrect one or doing the edit incorrectly.

    Update

    Before doing the above edit, I also tried by just adding export PATH=$PATH:/opt/lampp/bin at the end like this:-

    From

    PATH=$PATH:$HOME/bin
    export PATH
    

    to

    PATH=$PATH:$HOME/bin
    export PATH=$PATH:/opt/lampp/bin
    

    But it didn't work. What am I missing?

    Thanks,
    Sandeepan

    • PP.
      PP. over 13 years
      Does your ~/.bashrc call ~/.bash_profile?
    • Sandeepan Nath
      Sandeepan Nath over 13 years
      how do I check that? I am basically new to server related things
    • MadHatter
      MadHatter over 13 years
      Iain: those commands make .bash_profile call .bashrc, not the other way around.
    • MadHatter
      MadHatter over 13 years
      Iain: BIG GRIN!