restore PATH under Mac OS X [duplicate] - macos

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 6 years ago.
Hi guys I tried to add new directory to the PATH, but instead appending I overwrote it. Is there any way to restore those default paths?

If you changed your PATH in a Terminal shell, simply close that Terminal window and open a new one. Changes to environment variables are local to the shell in which you change them (and any subshells created by that one).

Just restart your terminal that will assign variables based on your .profile or .bashrc ( if you are running bash )

Related

Environment variable is not set MacOS [duplicate]

This question already has answers here:
Mac OS X 10.9 - setting permanent environment variables
(8 answers)
Closed 6 months ago.
I need to set environment variables to build an Ionic application, open the terminal and run the command:
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
Without closing the terminal I type echo $ANDROID_SDK_ROOT, and the environment variable is returned perfectly, so I run "source ~/.bash_profile", to update the environment variables. I open and close the terminal and my environment variable is empty!
I tried to set it manually by opening the environment variables files, with a text editor but without success.
For macOS 10.15 Catalina and Newer, you need to use a .zshenv file instead of .bash_profile. This is because, by default since Catalina, the terminal uses zsh instead of bash.
Export paths permanently in the following manner:
Create .zshenv file:
touch ~/.zshenv
open -a TextEdit.app ~/.zshenv
Type out the export you want to do in this format:
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
and save it. (From this old answer)

trying to install .bash_profile on terminal [duplicate]

This question already has answers here:
How to set .bash_profile, if it does not exist yet. I want to launch sublime from a command line in Mac
(4 answers)
Closed 3 years ago.
I'm having a very hard time installing flutter when I opened my terminal and tried to open the bash profile and I entered open -e .bash_profile on the therminal, I get error stating that my .bash_profile does not exit please see below, can someone help me I been researching and trying to figured what's wrong and no one seems to have an answer.
Last login: Sun Apr 28 00:06:05 on console
Veasnas-MacBook-Pro:~ veasnamam$ open -e .bash_profile
The file /Users/veasnamam/.bash_profile does not exist.
Veasnas-MacBook-Pro:~ veasnamam$
You easily can create a new, empty .bash_profile by doing a touch ~/.bash_profile.
Afterwards run open -e .bash_profile again.
In my case (MacBook Pro too) the file .bash_profile exists, but is empty (I'm using ZSH anyhow) so don't worry if yours does not exist.

Accidentally cleared ~/.bash_profile contents (Mac) [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 3 years ago.
I accidentally used > to put an output inside ~/.bash_profile and ended up erasing a lot of configs I had saved there.
I need help to recover it. I still have iTerm opened with all the ~/.bash_profile old settings before erase active. Which means next time I close it or do source ~/.bash_profile all the settings will be lost forever.
Is there a way to recover the current ~/.bash_profile settings loaded? Or something?
Normally, .bashrc is a copy from /etc/skel, so you can restore it from there.
If you added some extra informations in this file, you still have them available in your current session. To recover those, say:
env to see those variables.
typeset -f to see the functions that are defined.

Mac Yosemite, tried to change my bash profile path, but I messed up and now terminal cant find any commands [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 7 years ago.
I tried fixing an unrelated problem by changing my path in my .bash_profile, but I think I messed up and now my terminal cant find any command, not even 'ls' or 'nano'. Is there any way to edit the bash profile file back to the original without using the command line? Is there a way I could find my bash profile in finder and edit it with the text app? Or do I have to factory wipe my MacBook?
okay yeah I fixed it by changing my setting PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin‌​:/sbin and that gave me the bash commands back and then I could use nano to edit the profile back to how it was before I messed with it. I feel really dumb.

Mac OSX prompt git branch aware [duplicate]

This question already has answers here:
How can I display the current branch and folder path in terminal?
(18 answers)
Closed 5 years ago.
Ive been playing with the .profile file in my home directory, in order to show the git branch on the prompt and also to show the rvm gemset and python virtual env Im currently in... mostly all works fine, the problem that I'm having is that in order to show the branch in a different color depending on the state of the branch I have to do source ~/.profile every time, also I have to do the same in order to show the python virtualenv in CYAN.
Theres gotta be a way or something that Im missing so that I dont have to run source ~/.profile every time I go into a different folder so that the branch color is based on the status.
Heres my .profile
https://gist.github.com/3628788
Thanks for your help figuring this out!
Use the PROMPT_COMMAND variable to define a function that sets your PS1 after every command. Put this at the bottom of your .profile file in place of the assignment to PS1:
prompt_cmd () {
PS1="${PYTHON_VIRTUALENV}$PURPLE\$(set_rvm_prompt)$NO_COLOUR\u#\h:[\W]${B_STATE}\$(parse_git_branch)$NO_COLOUR\$ "
}
PROMPT_COMMAND=prompt_cmd
Now, just before displaying your prompt, bash will execute the function prompt_cmd, updating PS1 for the most recent information according to PYTHON_VIRTUALENV, set_rvm_prompt(), and parse_git_branch().

Resources