bashmacosterminalpathosx-yosemite

How do I edit $PATH (.bash_profile) on OS X?


I am trying to edit an entry to PATH, as I did something wrong.

I am using Mac OS X v10.10.3 (Yosemite)

I have tried:

touch ~/.bash_profile; open ~/.bash_profile

But the file editor opens with nothing inside.

My problem:

I am trying to install ANDROID_HOME to my PATH

I misspelled it, but when I closed the terminal and went back it was gone, so I tried again:

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

This time, I typed the command correctly but, when I closed the terminal, my settings disappeared again.

How do I execute my desired settings?

If I was to edit bash.profile, how would I enter the above code?


Solution

  • You have to open that file with a text editor and then save it.

    touch ~/.bash_profile; open ~/.bash_profile
    

    It will open the file with TextEdit, paste your things and then save it. If you open it again you'll find your edits.

    You can use other editors:

    nano ~/.bash_profile
    mate ~/.bash_profile
    vim ~/.bash_profile
    

    But if you don't know how to use them, it's easier to use the open approach.


    Alternatively, you can rely on pbpaste. Copy

    export ANDROID_HOME=/<installation location>/android-sdk-macosx
    export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
    

    in the system clipboard and then in a shell run

    pbpaste > ~/.bash_profile
    

    Or alternatively you can also use cat

    cat > ~/.bash_profile
    

    (now cat waits for input: paste the two export definitions and then hit Ctrl + D).