Shell not finding commands after I changed my .bash_profile file

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?


Solution 1:

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.

Solution 2:

What you did is to overwrite the PATH variable. This removed every other path that was in your PATH before from the variable.

You need to do the following:

export PATH="$HOME/.composer/vendor/bin:$PATH"

This adds the Composer bin path to the system paths where SSH etc. are located.