I changed my "HOME" variable and now cannot find "~/.bash_profile" to change it back
I was messing around with environment variables on my Mac, trying to learn how to use them and I used the command nano ~/.bash_profile
where I then added the line HOME=/Users/MyCompName/Desktop
to update my home variable.
This change worked and can be seen when I use printenv
to view all environment variables but when I went to change HOME
back I couldn't seem to find ~/.bash_profile
anymore. Where did it go?
It's in the same place.
Before the change ~
expands to something like /Users/YourUserName
, the shell finds your .bash_profile
there. After the file gets sourced ~
expands to another path so ~/.bash_profile
no longer points to the relevant file. This is because in this context ~
means $HOME
.
If you know the full path to your actual home directory, you can use it instead of ~
. In Mac it would probably look like this:
nano /Users/YourUserName/.bash_profile
Or let your Bash look up your home directory in the user database rather than just looking at $HOME
. This doesn't require you to remember anything:
nano ~YourUserName/.bash_profile
Modifying your HOME
variable without changing your actual home directory is not the best idea. Changing any user's home directory is an administrative task, usually regular users cannot do this.