How to change terminal $HOME variable? My terminal can't even be opened now I mean change $HOME not by defining in ~/.bash_profile, but loading the variable when shell opens.

By the way, after some misoperation I cannot even get into the Terminal now... It now says [Process completed] and does not respond, as it should when every time it exits. Is there a way to configure or re-install the Terminal?
By default the $HOME variable is set to your home directory, you have nothing to do yourself in .bash_profile. I think something goes wrong in the process of starting your Terminal session. It is likely that your ~/.bash_profile is corrupt.

You can fix this without your terminal:


Open TextEdit and press CommandO to open a file.
Press CommandShiftG and enter ~/ to go to your home directory.
Now press CommandShift., this will make sure you can see hidden files.
Open .bash_profile, create a backup if needed, delete the contents and save.


This should fix your problem. You can try this for ~/.profile (if it exists) as well.

You can check your HOME variable by opening Terminal and type:

echo $HOME


This will return your current home directory. It is most likely that you do not want to change this. But if so, it is best to change it just before you run the command, not in your .bash_profile.



This example will show you how to change your HOME temporarily (for Bash):

# store original HOME location ('/User/CousinCocaine')
ORIGHOME="$HOME"
# set new home location    
HOME="/User/CousinCocaine/my/new/home/is/here"
# check new home location
echo "~/ " ~/
echo "\$HOME "$HOME""
# set home location back to original
HOME="$ORIGHOME"
# test old home location
echo "~/ " ~/
echo "\$HOME "$HOME""