Monday, January 31, 2011

Ubuntu Linux PATH problem

I was trying to build Android from source code.
http://source.android.com/source/download.html

I had to install Repo and set it to PATH.
I've been used to MacOS now but Ubuntu is not my cup of tea yet....well MacOS neither...but anyhow...
The problem was, that in ~/ directory, I find .profile and .bashrc files.
In .profile, I find the following line.
     if [ -d ~/bin ] ; then
          PATH=~/bin:"${PATH}"
     fi



So it seems this should work, however when I type "repo", the terminal doesn't recognize this command.
I went through quite a number of posts online.
And finally I found a solution.
Here, I quote
The .bash_profile file is read and executed when bash is invoked as a login shell, otherwise the .bashrc file will be read and executed.
That's why this code:
if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
fi
which is located in .bash_profile, doesn't seem to work...it's not being read. But, if you enter this into your terminal:
bash --login
then all your scripts in ~/bin will execute properly for your current terminal session.
A good solution is to cut those 3 lines of code out of .bash_profile and put them in your .bashrc file. If you don't cut (or comment out) the code in .bash_profile it will be read twice since .bash_profile includes the .bashrc file.

So I followed this suggestion and it worked perfectly.
Here's the reference to the post.
It's frustrating to be a beginner....isn't it?



No comments:

Post a Comment