Jump to content
Compatible Support Forums
Sign in to follow this  
frequencydrive

Setting $PATH environment variable in Bash

Recommended Posts

I have just installed MySQL and I am getting tired of having to type the full path name to start the server manually (/usr/local/mysql/bin/mysqld_safe --user=mysql). I thought I would add this path to my $PATH environment variable. So I typed the following to add this path:

 

Code:
PATH=$PATH":/usr/local/mysql/bin"

 

This works great only for the current session. If I move to another x-windows terminal (on the same machine just another window running a terminal) then the $PATH I just created isn't visible to any other terminal. So I thought I will just add this new path to my .bash_profile. Here is what my bash_profile looks like right now after adding /usr/local/mysql/bin to my path.

 

Code:
# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then	. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binPATH=$PATH:/usr/local/mysql/binBASH_ENV=$HOME/.bashrcUSERNAME="root"export USERNAME BASH_ENV PATH

 

If I close the current window that I am running a terminal in and start a new terminal then you would think bash would read the .bash_profile before starting the shell. Apparently it isn't rereading the .bash_profile or I am not adding the path /usr/local/mysql/bin to my $PATH variable correctly. Does anyone see what I am doing wrong? I am aware of creating an aliase but I don't want to do it that way. I want to know what I am doing wrong here.

 

I want the path /usr/local/mysql/bin to be part of my path whenever I start a terminal. I am tired of typing the full path name everytime I start and stop the MySQL server.

 

Thanks

Share this post


Link to post

Ok well I guess I should have tried this before posting. After adding a new path to my .bash_profile I decided to just logout and log back in again to see if it would see my new/modified path then. So I shutdown X-Windows and logged out. Logged back in and typed echo $PATH and BANG! the new/modified path was shown. That is great!

 

So the lesson learned here is that bash only reads the .bash_profile one time and that is when you first log in to the machine. Any modifications to that file do not get passed on to new terminal sessions/windows that you subsequently open. You have to completely log out and log back in. I am sure there is a way to force BASH to reread it's .bash_profile file but I don't know how. I can't even find it in the O'reilley BASH book. But hey everything is working now so I'm happy.

Share this post


Link to post

The issue with the bash shell is that you either have to do what you did, log out/in which is rather cumbersome and brut force, or you can simply invoke the following command:

 

>source [some file containing what you want to become the profile]

 

in this case it would be

 

>source .bash_profile

 

I hope this helps with future reference.

 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×