0

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

Sandeepan Nath
  • 647
  • 6
  • 13
  • 29

2 Answers2

7

.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.
MadHatter
  • 79,770
  • 20
  • 184
  • 232
2

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

# source ~/.bash_profile

should apply your changes.

petrus
  • 5,297
  • 26
  • 42