MacOS – Shell not finding commands after I changed the .bash_profile file

bashmacossshterminal

I was following a tutorial trying to install Laravel (5.0). The tutorial showed to add export PATH="~/.composer/vendor/bin/laravel" to the .bash_profile document. Since then, I am not able to execute any command (nano, ssh, etc).

Nothing happens when I executed this in terminal:

export PATH="~/.composer/vendor/bin/laravel"

My .bash_profile looks like this:

export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH

I tried logging out, restarting and entering the following commands:

source ~/.bash_profile
. .bash_profile

Can anyone help?

Best Answer

When you did:

export PATH="~/.composer/vendor/bin/laravel"

You changed the system default PATH to something nearly useless. You should never replace PATH, you should only append to PATH.

Remove the following two lines from your ~/.bash_profile:

export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
export PATH="~/.composer/vendor/bin/laravel"

And replace them with the following:

pathadd() {
    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
        PATH="${PATH:+"$PATH:"}$1"
    fi
}
pathadd /Applications/MAMP/bin/php/php5.5.10/bin
pathadd ~/.composer/vendor/bin/laravel
export PATH

This is a safe way to append to your PATH environment variable. It only does the append if the path isn't already in the list.